onChange event not firing
See original GitHub issueDo you want to request a feature or report a bug?
bug
What’s the current behavior?
Inputs and other tags inside custom elements can only be changed if they are within a portal. onKeyDown fires correctly, but onChange never fires. Others on the slack channel have also come across this bug, and state the only solution is placing the custom element within a portal.
CodeSandbox: https://codesandbox.io/s/slate-reproductions-wcko1
<input
onChange={() => console.log('this never fires')}
onKeyDown={() => console.log('but this works')}
/>
Slate: 0.57.1 Browser: Chrome OS: Mac
What’s the expected behavior?
onChange should fire in custom elements without needing to be inside a portal / pop-up.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:9 (2 by maintainers)
Top Results From Across the Web
javascript - onchange event not fire when the change come ...
The change event occurs when a control loses the input focus and its value has been modified since gaining focus. This event is...
Read more >Onchange event will not fire - JavaScript
The onchange event occurs when a control loses the input focus and its value has been modified since gaining focus.
Read more >onChange event not firing · Issue #637 · testing-library ...
The value that I am getting is the updated one but the onChange event is not getting triggered. 6
Read more >Onchange event not fired on field service mobile
In the browser, this works fine, but when I open the Field Service Mobile app on my tablet, the onchange event does not...
Read more >HTMLElement: change event - Web APIs | MDN
The change event is fired for , , and elements when the user modifies the element's value. Unlike the input event, the change...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey this is quite the hack but if you wrap your input inside a div and give it the attribute
data-slate-editor
then the onChange handler should call. This fools Slate into thinking that the input is outside the editor so your input will work as normal. The issue I just created #3425 is more or less regarding the same thing, but my case was with CodeMirror which has a textarea whose onInput never fires. From what I can tell with some experimenting the culprit seems to be the Editable component that steals focus from inputs/textareas as you type. I would really like to get this resolved but in the meantime this hack seems to work nicelyugly, but it works😰😂