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
- some bike vendor told me that the biggest problem with regular to ebike conversion was that regular bike frames were not strong enough to...
- I think of this as the kiosk economy.
- What a goofy comment.
- There's lots of evidence for positive influences of Caffeine on the body (some negative as well), especially the brain.
- Compose support in WSLc
- [RFC] Roadmap to v2.0
Raise real-world problems, find people facing the same issue, and discuss solutions.4,500 issues0 comments
support (Other)
some bike vendor told me that the biggest problem with regular to ebike conversion was that regular bike frames were not strong enough to...
I think of this as the kiosk economy.
What a goofy comment.
There's lots of evidence for positive influences of Caffeine on the body (some negative as well), especially the brain.
Compose support in WSLc
[RFC] Roadmap to v2.0
[Feature]: Add TurboQuant Support for KV Cache Quantization
Support for AGENTS.md and .agents/skills/, the community has been asking since August 2025
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
Comments (0)
No comments yet. Start the discussion.