Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Deprecated the coarse onArrowUp et al key handler props on DraftEditor.react to make it possible to produce editor commands from these keys #1637

Closed
wants to merge 2 commits into from

Conversation

steveluscher
Copy link
Contributor

@steveluscher steveluscher commented Jan 31, 2018

Previously, it was impossible to do this:

function mapKeysToEditorCommands(e) {
  if (mentionsAutocompleteIsOpen) {
    switch (e.keyCode) {
      case Keys.UP:
        return 'MentionsAutocomplete/select-previous';
      case Keys.DOWN:
        return 'MentionsAutocomplete/select-next';
    }
  }
  return getDefaultKeyBinding(e);
}

<DraftEditor
  keyBindingFn={mapKeysToEditorCommands}
  ...
/>

…because we didn't give TAB, ESCAPE, LEFT, UP, RIGHT, or DOWN a chance to produce a command name.

This pull request:

  1. deprecates the prop-based key handlers (onUpArrow et al.) and encourages people to move their custom key logic into a keyBindingFn, and
  2. lets the named keypresses fall through to the keyBindingFn whenever a prop-based key handler isn't supplied.
  3. Updates the homepage and the rich text example.

tabs

…itor.react` to make it possible to produce editor commands from these keys
Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steveluscher has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@sophiebits sophiebits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update RichTextEditorUtil.onTab and the rich examples in examples/? Sounds great otherwise.

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steveluscher has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@steveluscher
Copy link
Contributor Author

I updated the examples and the homepage, but I wasn't really sure how to update RichUtils.onTab(). I tried to split it into onTabLevelIncrement and onTabLevelDecrement functions that don't rely on the keyboard event, but that makes it really easy to miss a case (eg. you want to preventDefault iff you're at a place in the text that even supports tab indenting). I ended up just leaving it the way it was.

mitermayer pushed a commit to mitermayer/draft-js that referenced this pull request Feb 2, 2018
…itor.react` to make it possible to produce editor commands from these keys

Summary:
Previously, it was impossible to do this:

```
function mapKeysToEditorCommands(e) {
  if (mentionsAutocompleteIsOpen) {
    switch (e.keyCode) {
      case Keys.UP:
        return 'MentionsAutocomplete/select-previous';
      case Keys.DOWN:
        return 'MentionsAutocomplete/select-next';
    }
  }
  return getDefaultKeyBinding(e);
}

<DraftEditor
  keyBindingFn={mapKeysToEditorCommands}
  ...
/>
```

…because we didn't give TAB, ESCAPE, LEFT, UP, RIGHT, or DOWN a chance to produce a command name.

This pull request:

1. deprecates the prop-based key handlers (`onUpArrow` et al.) and encourages people to move their custom key logic into a `keyBindingFn`, and
2. lets the named keypresses fall through to the `keyBindingFn` whenever a prop-based key handler isn't supplied.
3. Updates the homepage and the rich text example.

![tabs](https://user-images.githubusercontent.com/13243/35651838-f129bf4a-0695-11e8-971b-38dbae48fd23.gif)
Closes facebookarchive#1637

Differential Revision: D6864155

fbshipit-source-id: 23efb4caac25b1bc867350a1212f142b5b3ce7ab
@flarnie
Copy link
Contributor

flarnie commented Feb 9, 2018

It's weird that @steveluscher it looks like you did land this, but the PR was not closed by facebook-github-bot.

I'm closing this, if I'm missing something then please open a new PR and we can land it separately.

I also opened an internal task to look into why the PR wasn't closed when the imported change landed on master. T25937659

@flarnie flarnie closed this Feb 9, 2018
alicayan008 pushed a commit to alicayan008/draft-js that referenced this pull request Jul 4, 2023
…itor.react` to make it possible to produce editor commands from these keys

Summary:
Previously, it was impossible to do this:

```
function mapKeysToEditorCommands(e) {
  if (mentionsAutocompleteIsOpen) {
    switch (e.keyCode) {
      case Keys.UP:
        return 'MentionsAutocomplete/select-previous';
      case Keys.DOWN:
        return 'MentionsAutocomplete/select-next';
    }
  }
  return getDefaultKeyBinding(e);
}

<DraftEditor
  keyBindingFn={mapKeysToEditorCommands}
  ...
/>
```

…because we didn't give TAB, ESCAPE, LEFT, UP, RIGHT, or DOWN a chance to produce a command name.

This pull request:

1. deprecates the prop-based key handlers (`onUpArrow` et al.) and encourages people to move their custom key logic into a `keyBindingFn`, and
2. lets the named keypresses fall through to the `keyBindingFn` whenever a prop-based key handler isn't supplied.
3. Updates the homepage and the rich text example.

![tabs](https://user-images.githubusercontent.com/13243/35651838-f129bf4a-0695-11e8-971b-38dbae48fd23.gif)
Closes facebookarchive/draft-js#1637

Differential Revision: D6864155

fbshipit-source-id: 23efb4caac25b1bc867350a1212f142b5b3ce7ab
aforismesen added a commit to aforismesen/draft-js that referenced this pull request Jul 12, 2024
…itor.react` to make it possible to produce editor commands from these keys

Summary:
Previously, it was impossible to do this:

```
function mapKeysToEditorCommands(e) {
  if (mentionsAutocompleteIsOpen) {
    switch (e.keyCode) {
      case Keys.UP:
        return 'MentionsAutocomplete/select-previous';
      case Keys.DOWN:
        return 'MentionsAutocomplete/select-next';
    }
  }
  return getDefaultKeyBinding(e);
}

<DraftEditor
  keyBindingFn={mapKeysToEditorCommands}
  ...
/>
```

…because we didn't give TAB, ESCAPE, LEFT, UP, RIGHT, or DOWN a chance to produce a command name.

This pull request:

1. deprecates the prop-based key handlers (`onUpArrow` et al.) and encourages people to move their custom key logic into a `keyBindingFn`, and
2. lets the named keypresses fall through to the `keyBindingFn` whenever a prop-based key handler isn't supplied.
3. Updates the homepage and the rich text example.

![tabs](https://user-images.githubusercontent.com/13243/35651838-f129bf4a-0695-11e8-971b-38dbae48fd23.gif)
Closes facebookarchive/draft-js#1637

Differential Revision: D6864155

fbshipit-source-id: 23efb4caac25b1bc867350a1212f142b5b3ce7ab
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants