Skip to content

Commit b2600b4

Browse files
committed
Replace deprecated onTab function
1 parent cdf72f8 commit b2600b4

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/index.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { DraftHandleValue, EditorState, RichUtils } from "draft-js";
1+
import {
2+
DraftEditorCommand,
3+
DraftHandleValue,
4+
EditorState,
5+
getDefaultKeyBinding,
6+
RichUtils,
7+
} from "draft-js";
28
import { EditorPlugin, PluginFunctions } from "draft-js-plugins-editor";
39
import { KeyboardEvent } from "react";
410

@@ -89,13 +95,16 @@ const createListPlugin = (config?: Partial<ListPluginConfig>): EditorPlugin => {
8995

9096
// Handle tab and shift+tab presses if nested lists are allowed
9197
if (allowNestedLists) {
92-
plugin.onTab = (
98+
plugin.keyBindingFn = (
9399
e: KeyboardEvent,
94100
{ getEditorState, setEditorState }: PluginFunctions,
95-
): void => {
96-
const editorState = getEditorState();
97-
const updatedState = RichUtils.onTab(e, editorState, maxDepth);
98-
setEditorState(updatedState);
101+
): DraftEditorCommand | null => {
102+
if (e.key === "Tab") {
103+
const editorState = getEditorState();
104+
const updatedState = RichUtils.onTab(e, editorState, maxDepth);
105+
setEditorState(updatedState);
106+
}
107+
return getDefaultKeyBinding(e);
99108
};
100109
}
101110

0 commit comments

Comments
 (0)