简体   繁体   中英

Monaco editor react resize by user (windows style resize)

I'm using monaco-editor, react version, have this code

  <Editor
                height={"100%"}
                width={1200}
                onChange={handleUserQueryChange}
                beforeMount={handleEditorBeforeMount}
                onMount={handleEditorDidMount}
                options={{
                  minimap: {
                    enabled: false,
                  },
                  scrollBeyondLastLine: false,
                  lineNumbers: 'off',
                  glyphMargin: false,
                  folding: false,
                  lineDecorationsWidth: 0,
                  lineNumbersMinChars: 0,
                  wordWrap: 'off',
                  automaticLayout: true
                }}
              />

I would like to change the size editor like a window that you open in a normal OS (windows/linux), and moving the content below down.

The automaticaLayout that I added doesn't seem to work (I think it something about being responsive).

Any ideas?

I ended up using the library re-resizable , with this code and it's working:


  const [height, setHeight] = useState(10)

  <Resizable size={{
              width: 1200,
              height: height,
            }}
            onResizeStop={(e, direction, ref, d) => {
              setHeight(height + d.height)
            }}
            >
             
               <Editor
                height={height}
                width={1200}
                options={{
                  minimap: {
                    enabled: false,
                  },
                  scrollBeyondLastLine: false,
                  lineNumbers: 'off',
                  glyphMargin: false,
                  folding: false,
                  lineDecorationsWidth: 0,
                  lineNumbersMinChars: 0,
                  wordWrap: 'off',
                  automaticLayout: true
                }}
              />
            </Resizable>

Note: only changes height in this example but you can add the width as well if needed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM