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

[@mantine/tiptap]: add forward ref to mantine tip tap editor #3068

Merged
merged 1 commit into from Nov 28, 2022
Merged
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
15 changes: 10 additions & 5 deletions src/mantine-tiptap/src/RichTextEditor.tsx
@@ -1,5 +1,5 @@
/* eslint-disable react/no-unused-prop-types */
import React, { useMemo } from 'react';
import React, { useMemo, forwardRef } from 'react';
import {
Box,
useComponentDefaultProps,
Expand Down Expand Up @@ -50,7 +50,7 @@ const defaultProps: Partial<RichTextEditorProps> = {
withTypographyStyles: true,
};

export function RichTextEditor(props: RichTextEditorProps) {
export const RichTextEditor = forwardRef<HTMLDivElement, RichTextEditorProps>((props, ref) => {
const {
editor,
children,
Expand All @@ -63,21 +63,26 @@ export function RichTextEditor(props: RichTextEditorProps) {
unstyled,
...others
} = useComponentDefaultProps('RichTextEditor', defaultProps, props);
const { classes, cx } = useStyles(null, { name: 'RichTextEditor', classNames, styles, unstyled });
const { classes, cx } = useStyles(null, {
name: 'RichTextEditor',
classNames,
styles,
unstyled,
});
const mergedLabels = useMemo(() => ({ ...DEFAULT_LABELS, ...labels }), [labels]);

return (
<StylesApiProvider classNames={classNames} styles={styles} unstyled={unstyled}>
<RichTextEditorProvider
value={{ editor, labels: mergedLabels, withCodeHighlightStyles, withTypographyStyles }}
>
<Box className={cx(classes.root, className)} {...others}>
<Box className={cx(classes.root, className)} {...others} ref={ref}>
{children}
</Box>
</RichTextEditorProvider>
</StylesApiProvider>
);
}
}) as any;

// Generic components
RichTextEditor.Content = Content;
Expand Down