I made a custom checkbox control
made from a regular div
/span
.
Because the <input type='checkbox'.../>
cannot have children element, so I created the another one from a div
with role='checkbox'
and aria-checked={isChecked}
.
Then i handled the mouse & keyboard event for toggling the check state.
The question is:
How to trigger 'change'
event? The code below doesn't work in react 16
refTarget?.current?.dispatchEvent(new Event('change', { bubbles: true, cancelable: false }))
The another trick is calling the props.onChange
directly.
It works but the event doesn't bubble to parent <form onChange={(e) => console.log('changed!')}></form>