Skip to content

Commit

Permalink
Merge pull request #308 from AppQuality/fix-chat-floating-menu-crash
Browse files Browse the repository at this point in the history
Fix-chat-floating-menu-crash
  • Loading branch information
cannarocks authored Jan 26, 2024
2 parents 5dda7b5 + 41691b6 commit a3a07a9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/stories/chat/_types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type SuggestedUser = { id: number; name: string; email:string };

export interface ChatEditorArgs extends Partial<EditorOptions> {
placeholderOptions?: Partial<PlaceholderOptions>;
hasInlineMenu?: boolean;
hasFloatingMenu?: boolean;
hasButtonsMenu?: boolean;
bubbleOptions?: any;
author: Author;
Expand Down
2 changes: 1 addition & 1 deletion src/stories/chat/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Placeholder.args = {
export const Menus = Template.bind({});
Menus.args = {
...defaultArgs,
hasInlineMenu: true,
hasFloatingMenu: true,
hasButtonsMenu: true,
i18n: {
menu: {
Expand Down
2 changes: 1 addition & 1 deletion src/stories/chat/parts/bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const CommentBar = ({
case "mention":
const { from } = editor.state.selection;
const char = from > 1 ? " @" : "@";
return editor.commands.insertContent(char);
return editor.chain().focus().insertContent(char).run();
default:
return;
}
Expand Down
9 changes: 5 additions & 4 deletions src/stories/chat/parts/commentBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const CommentBox = ({
placeholderOptions,
...props
}: PropsWithChildren<ChatEditorArgs>) => {
const { children, hasInlineMenu, hasButtonsMenu, bubbleOptions, i18n } =
const { children, hasFloatingMenu, hasButtonsMenu, bubbleOptions, i18n } =
props;
const { editor, setEditor, mentionableUsers, triggerSave } = useChatContext();

Expand Down Expand Up @@ -67,15 +67,16 @@ export const CommentBox = ({

if (!ed) return null;

ed.on("create", ({ editor }) => setEditor(editor as TipTapEditor));
ed.on("update", ({ editor }) => setEditor(editor as TipTapEditor));

return (
<>
{hasInlineMenu && (
<FloatingMenu editor={ed} tippyOptions={{ ...bubbleOptions }} />
)}
<ChatBoxContainer>
<EditorContainer editable style={{ marginLeft: 0 }}>
{hasFloatingMenu && (
<FloatingMenu editor={ed} tippyOptions={{ ...bubbleOptions }} />
)}
<EditorContent editor={ed} onKeyDown={onKeyDown} />
</EditorContainer>
</ChatBoxContainer>
Expand Down

0 comments on commit a3a07a9

Please sign in to comment.