Skip to content

Commit

Permalink
Merge pull request #2665 from udecode/fix/tabbable-read-only
Browse files Browse the repository at this point in the history
Disable tabbable when editor is read-only
  • Loading branch information
zbeyens authored Oct 2, 2023
2 parents 66a32cc + 64c496a commit 38d465e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/cuddly-toes-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-tabbable': patch
---

Disable tabbable when editor is read-only
13 changes: 12 additions & 1 deletion packages/tabbable/src/TabbableEffects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getPluginOptions,
toDOMNode,
toSlateNode,
useEditorReadOnly,
useEditorState,
} from '@udecode/plate-common';
import { Path } from 'slate';
Expand All @@ -16,10 +17,13 @@ import { TabbableEntry, TabbablePlugin } from './types';

export function TabbableEffects() {
const editor = useEditorState();
const readOnly = useEditorReadOnly();
const { query, globalEventListener, insertTabbableEntries, isTabbable } =
getPluginOptions<TabbablePlugin>(editor, KEY_TABBABLE);

useEffect(() => {
if (readOnly) return;

const editorDOMNode = toDOMNode(editor, editor);
if (!editorDOMNode) return;

Expand Down Expand Up @@ -123,7 +127,14 @@ export function TabbableEffects() {
eventListenerNode.addEventListener('keydown', handler, true);
return () =>
eventListenerNode.removeEventListener('keydown', handler, true);
}, [editor, globalEventListener, isTabbable, insertTabbableEntries, query]);
}, [
readOnly,
editor,
globalEventListener,
isTabbable,
insertTabbableEntries,
query,
]);

return null;
}

0 comments on commit 38d465e

Please sign in to comment.