Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with autoresize and min height #615

Open
medihack opened this issue Jan 11, 2024 · 2 comments
Open

Problem with autoresize and min height #615

medihack opened this issue Jan 11, 2024 · 2 comments

Comments

@medihack
Copy link

I want to use react-codemirror in an editor that auto-resizes, but I still want to use a minimum height. Unfortunately, react-codemirror does set height: '100% !important' on the .cm-scroller element. That way, I always end up with something like this when only adding a minHeight and maxHeight:

<CodeMirror minHeight="200px" maxHeight="75vh" theme="dark" value={optionsSource} />

Screenshot 2024-01-12 004855

I would like to have the horizontal scrollbar at the bottom of the editor, but still want it to grow until a given height.

Is there a good workaround for having an auto-resizing editor that also has a minimum height? Or can I turn off the height: '100% !important' somehow?

@medihack
Copy link
Author

medihack commented Jan 13, 2024

Here is some workaround I found to overwrite the height of cm-scroller set by react-codemirror:

  const theme = EditorView.theme({
    "& div.cm-scroller": {
      minHeight: `${minHeight} !important`,
    },
  })

  return (
    <CodeMirror
      minHeight={minHeight}
      maxHeight="75vh"
      theme={colorScheme === "dark" ? "dark" : "light"}
      extensions={[theme]}
      value={optionsSource}
    />
  )

It's a bit ugly, but now the horizontal scrollbar is on the bottom of the editor pane. But I still wonder why the height: '100% !important' was explicitly set by react-codemirror in the first place. The cm-scroller already has a 100% height (without important) set by CodeMirror itself.

@jaywcjlove
Copy link
Member

jaywcjlove commented Mar 6, 2024

Not sure if this is a solution.

<CodeMirror
  height="100%"
  style={{ height: "100%" }}
/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants