How do I `preventDefault` inside `onKeyUp`?
unclechu opened this issue · 6 comments
I don't have Event in this handler to do so.
This is perhaps not a great solution, but would it work to coerce KeyboardEvent to Event? Maybe having a function to do this in the library would be handy, or maybe the events defined in the library can be updated in a way to accommodate this.
@ethul Coercing KeyboardEvent to Event is unsafe, because, we can just create an record that satisfies type of KeyboardEvent (that is simple unwrapped record), and by this coercing we can get runtime fails.
Agreed this would be unsafe. Does it temporarily solve your issue? Maybe reworking the way the events are represented would be worth looking further into. I am open to ideas on this.
I think type of KeyboardEvent must change, at least, with minimal breaking changes, an event key could be added to the KeyboardEvent type that would have a reference to Event (but in this case, we have to construct new object).
Does it temporarily solve your issue?
I haven't tried but it probably will solve it.
I think the best way would be to make some newtypes for events and to add some type class like ReactEvent that would have preventDefault and stopPropagation to implement. And KeyboardEvent shouldn't be just a record with simple data, at least it must have some field with FFI type like Event.