Skip to content

Commit

Permalink
feat: expose 'root' config of EditorView (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
noru committed Oct 15, 2021
1 parent e73519d commit 21d77c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/index.tsx
Expand Up @@ -54,6 +54,11 @@ export interface ReactCodeMirrorProps
* or objects with an extension in its `extension` property. Extensions can be nested in arrays arbitrarily deep—they will be flattened when processed.
*/
extensions?: Extension[];
/**
* If the view is going to be mounted in a shadow root or document other than the one held by the global variable document (the default), you should pass it here.
* Originally from the [config of EditorView](https://codemirror.net/6/docs/ref/#view.EditorView.constructor%5Econfig.root)
*/
root?: ShadowRoot | Document;
}

export interface ReactCodeMirrorRef {
Expand Down Expand Up @@ -82,11 +87,13 @@ const ReactCodeMirror = React.forwardRef<ReactCodeMirrorRef, ReactCodeMirrorProp
placeholder,
indentWithTab,
editable,
root,
...other
} = props;
const editor = useRef<HTMLDivElement>(null);
const { state, view, container, setContainer } = useCodeMirror({
container: editor.current,
root,
value,
autoFocus,
theme,
Expand Down
2 changes: 2 additions & 0 deletions src/useCodeMirror.ts
Expand Up @@ -30,6 +30,7 @@ export function useCodeMirror(props: UseCodeMirror) {
editable = true,
indentWithTab = true,
basicSetup = true,
root,
} = props;
const [container, setContainer] = useState(props.container);
const [view, setView] = useState<EditorView>();
Expand Down Expand Up @@ -86,6 +87,7 @@ export function useCodeMirror(props: UseCodeMirror) {
const viewCurrent = new EditorView({
state: stateCurrent,
parent: container as any,
root,
});
setView(viewCurrent);
}
Expand Down

0 comments on commit 21d77c3

Please sign in to comment.