mirror of
https://github.com/facebook/lexical.git
synced 2025-05-17 23:26:16 +08:00
[lexical-react] Bug Fix: Make typeahead menu respect read-only mode (#7185)
This commit is contained in:
@ -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 : (
|
||||
|
Reference in New Issue
Block a user