question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onChange event not firing

See original GitHub issue

Do 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
Francesco-Lancianacommented, Jan 14, 2020

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 nicely

1reaction
LiuJi-Jimcommented, Jan 17, 2020

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 nicely

ugly, but it works😰😂

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found