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

expose 'root' config of EditorView #204

Merged
merged 1 commit into from Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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