@@ -13,10 +13,12 @@ const Editor = (EditorImport.default || EditorImport) as unknown as typeof Edito
13
13
const baseClass = 'code-editor'
14
14
15
15
const CodeEditor : React . FC < Props > = ( props ) => {
16
- const { className, options, readOnly, ...rest } = props
16
+ const { className, maxHeight , options, readOnly, ...rest } = props
17
17
const [ dynamicHeight , setDynamicHeight ] = useState ( 20 )
18
18
const { theme } = useTheme ( )
19
19
20
+ const MIN_HEIGHT = 56 // equivalent to 3 lines
21
+
20
22
const classes = [
21
23
baseClass ,
22
24
className ,
@@ -52,14 +54,14 @@ const CodeEditor: React.FC<Props> = (props) => {
52
54
// can already have scrolling, we want the height of the
53
55
// editor to fit its content.
54
56
// See: https://github.com/microsoft/monaco-editor/discussions/3677
55
- height = { dynamicHeight }
57
+ height = { maxHeight ? Math . min ( dynamicHeight , maxHeight ) : dynamicHeight }
56
58
onChange = { ( value , ev ) => {
57
59
rest . onChange ?.( value , ev )
58
- setDynamicHeight ( value . split ( '\n' ) . length * 18 + 2 )
60
+ setDynamicHeight ( Math . max ( MIN_HEIGHT , value . split ( '\n' ) . length * 18 + 2 ) )
59
61
} }
60
62
onMount = { ( editor , monaco ) => {
61
63
rest . onMount ?.( editor , monaco )
62
- setDynamicHeight ( editor . getValue ( ) . split ( '\n' ) . length * 18 + 2 )
64
+ setDynamicHeight ( Math . max ( MIN_HEIGHT , editor . getValue ( ) . split ( '\n' ) . length * 18 + 2 ) )
63
65
} }
64
66
/>
65
67
)
0 commit comments