From d79fdfe29d4d129f4088be61af96a5c7eb15e26b Mon Sep 17 00:00:00 2001 From: Eve Essex <2034973+aforismesen@users.noreply.github.com> Date: Mon, 2 Oct 2017 11:15:17 -0700 Subject: [PATCH] Right and Left Arrow Event Handling Summary: Exposes right and left keyboard events, as suggested in [this issue](https://github.com/facebook/draft-js/issues/219) by hellendag. This will greatly simplify some of our arrow handling at [Artsy](https://github.com/artsy/positron/blob/master/client/apps/edit/components/content2/sections/text/index.coffee#L121). The test suite is passing locally. Closes https://github.com/facebook/draft-js/pull/1384 Differential Revision: D5954003 fbshipit-source-id: 90c3a7d6bb5070c455f56d60ccd64c5ad136fe59 --- docs/APIReference-Editor.md | 11 +++++++++++ src/component/base/DraftEditorProps.js | 2 ++ src/component/handlers/edit/editOnKeyDown.js | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/docs/APIReference-Editor.md b/docs/APIReference-Editor.md index 76dc54f..190430f 100644 --- a/docs/APIReference-Editor.md +++ b/docs/APIReference-Editor.md @@ -245,10 +245,21 @@ onTab?: (e: SyntheticKeyboardEvent) => void onUpArrow?: (e: SyntheticKeyboardEvent) => void ``` +#### onRightArrow +``` +onRightArrow?: (e: SyntheticKeyboardEvent) => void +``` + #### onDownArrow ``` onDownArrow?: (e: SyntheticKeyboardEvent) => void ``` + +#### onLeftArrow +``` +onLeftArrow?: (e: SyntheticKeyboardEvent) => void +``` + ### Mouse events ### onFocus diff --git a/src/component/base/DraftEditorProps.js b/src/component/base/DraftEditorProps.js index 9b5d1f6..0631fa5 100644 --- a/src/component/base/DraftEditorProps.js +++ b/src/component/base/DraftEditorProps.js @@ -156,7 +156,9 @@ export type DraftEditorProps = { onEscape?: (e: SyntheticKeyboardEvent<>) => void, onTab?: (e: SyntheticKeyboardEvent<>) => void, onUpArrow?: (e: SyntheticKeyboardEvent<>) => void, + onRightArrow?: (e: SyntheticKeyboardEvent<>) => void, onDownArrow?: (e: SyntheticKeyboardEvent<>) => void, + onLeftArrow?: (e: SyntheticKeyboardEvent<>) => void, onBlur?: (e: SyntheticEvent<>) => void, onFocus?: (e: SyntheticEvent<>) => void, diff --git a/src/component/handlers/edit/editOnKeyDown.js b/src/component/handlers/edit/editOnKeyDown.js index 1e95d60..4cb1698 100644 --- a/src/component/handlers/edit/editOnKeyDown.js +++ b/src/component/handlers/edit/editOnKeyDown.js @@ -109,9 +109,15 @@ function editOnKeyDown(editor: DraftEditor, e: SyntheticKeyboardEvent<>): void { case Keys.UP: editor.props.onUpArrow && editor.props.onUpArrow(e); return; + case Keys.RIGHT: + editor.props.onRightArrow && editor.props.onRightArrow(e); + return; case Keys.DOWN: editor.props.onDownArrow && editor.props.onDownArrow(e); return; + case Keys.LEFT: + editor.props.onLeftArrow && editor.props.onLeftArrow(e); + return; case Keys.SPACE: // Handling for OSX where option + space scrolls. if (isChrome && isOptionKeyCommand(e)) {