IssueRaiser

Use the native `beforeinput` event if it's supported

**Do you want to request a *feature* or report a *bug*?** Improvement. **What is the current behavior?** Right now, the synthetic `onBeforeInput` event is being created based on two other events: - `textInput` when possible—which is in Webkit. - `keypress` as a fallback. But these days in Chrome, Safari and Opera the spec'd `beforeinput` event is available and actually fires. And when it does, it includes other [spec'd properties](https://developer.mozilla.org/en-US/docs/Web/API/InputEvent) which can be extremely helpful: - `inputType` tells you whether the event is inserting text, replacing text, inserting a line break, etc. - `getTargetRanges()` tells you where the input is taking place in the DOM. Right now this information isn't exposed, because even if the browser supports `beforeinput`, it's not being checked for. **What is the expected behavior?** Instead React should treat `textInput` as a slightly-preferred fallback for native `beforeinput` support, but add `beforeinput` as the true goal. So we'd end up with a fallback stack of: - `beforeinput` - `textInput` - `keypress` Which guarantees that the `nativeEvent` will always be the most spec'd and have the most relevant information associated with it. --- The `beforeinput` event's extra properties are critical in `contenteditable` situations, when you want to prevent the default browser behavior from firing but perform the logic on an internal model instead. (I'm looking to do this for [Slate](https://githu

Posted by ianstormtaylor on Oct 13, 2017, 1:45 AM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.4,500 issues0 comments

support (Other)

Use the native `beforeinput` event if it's supported

ianstormtaylorOct 13, 2017, 1:45 AM

**Do you want to request a *feature* or report a *bug*?** Improvement. **What is the current behavior?** Right now, the synthetic `onBeforeInput` event is being created based on two other events: - `textInput` when possible—which is in Webkit. - `keypress` as a fallback. But these days in Chrome, Safari and Opera the spec'd `beforeinput` event is available and actually fires. And when it does, it includes other [spec'd properties](https://developer.mozilla.org/en-US/docs/Web/API/InputEvent) which can be extremely helpful: - `inputType` tells you whether the event is inserting text, replacing text, inserting a line break, etc. - `getTargetRanges()` tells you where the input is taking place in the DOM. Right now this information isn't exposed, because even if the browser supports `beforeinput`, it's not being checked for. **What is the expected behavior?** Instead React should treat `textInput` as a slightly-preferred fallback for native `beforeinput` support, but add `beforeinput` as the true goal. So we'd end up with a fallback stack of: - `beforeinput` - `textInput` - `keypress` Which guarantees that the `nativeEvent` will always be the most spec'd and have the most relevant information associated with it. --- The `beforeinput` event's extra properties are critical in `contenteditable` situations, when you want to prevent the default browser behavior from firing but perform the logic on an internal model instead. (I'm looking to do this for [Slate](https://githu

Comments (0)

No comments yet. Start the discussion.

Comment on this issue