Skip to content

Commit

Permalink
Right and Left Arrow Event Handling
Browse files Browse the repository at this point in the history
Summary:
Exposes right and left keyboard events, as suggested in [this issue](facebookarchive/draft-js#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 facebookarchive/draft-js#1384

Differential Revision: D5954003

fbshipit-source-id: 90c3a7d6bb5070c455f56d60ccd64c5ad136fe59
  • Loading branch information
midas19910709 committed Oct 2, 2017
1 parent 3fd0fb5 commit 529c83d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/APIReference-Editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/component/base/DraftEditorProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions src/component/handlers/edit/editOnKeyDown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 529c83d

Please sign in to comment.