Skip to content

Commit

Permalink
fix: make typeahead menu respect read-only mode
Browse files Browse the repository at this point in the history
- Add read-only mode check before showing typeahead menu
- Add editable state listener to close menu when editor becomes read-only
- Ensures emoji/mentions picker respects editor's read-only state

Fixes facebook#7160
  • Loading branch information
kirandash committed Feb 16, 2025
1 parent f505ffe commit 96f895f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/lexical-react/src/LexicalTypeaheadMenuPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ export function LexicalTypeaheadMenuPlugin<TOption extends MenuOption>({
useEffect(() => {
const updateListener = () => {
editor.getEditorState().read(() => {
// Check if editor is in read-only mode
if (!editor.isEditable()) {
closeTypeahead();
return;
}

const editorWindow = editor._window || window;
const range = editorWindow.document.createRange();
const selection = $getSelection();
Expand Down Expand Up @@ -297,6 +303,22 @@ export function LexicalTypeaheadMenuPlugin<TOption extends MenuOption>({
openTypeahead,
]);

// Add effect to listen for editable state changes
useEffect(() => {
const editableListener = (isEditable: boolean) => {
if (!isEditable) {
closeTypeahead();
}
};

const removeEditableListener =
editor.registerEditableListener(editableListener);

return () => {
removeEditableListener();
};
}, [editor, closeTypeahead]);

return resolution === null ||
editor === null ||
anchorElementRef.current === null ? null : (
Expand Down

0 comments on commit 96f895f

Please sign in to comment.