[lexical-react] Bug Fix: Make typeahead menu respect read-only mode (#7185)

This commit is contained in:
Kiran Dash
2025-02-17 05:47:44 +08:00
committed by GitHub
parent 3cc852d6bb
commit e5f3c0cee5

View File

@ -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();
@ -297,6 +303,16 @@ export function LexicalTypeaheadMenuPlugin<TOption extends MenuOption>({
openTypeahead,
]);
useEffect(
() =>
editor.registerEditableListener((isEditable) => {
if (!isEditable) {
closeTypeahead();
}
}),
[editor, closeTypeahead],
);
return resolution === null ||
editor === null ||
anchorElementRef.current === null ? null : (