lovasoa / react-contenteditable

React component for a div with editable contents
http://npmjs.com/package/react-contenteditable
Apache License 2.0
1.63k stars 218 forks source link

Allow passing onBlur, onKeyUp, onKeyDown while still running emitChange #225

Open tony opened 3 years ago

tony commented 3 years ago

https://github.com/lovasoa/react-contenteditable/blob/a7f6c78a38af1d2da7e95e13733683e8c8f0e77e/src/react-contenteditable.tsx#L48-L52

emitChange triggers onChange, which sends up a typed event with event.target.value attached

In my case, onBlur, onKeyUp, onKeyDown aren't used to change state, but to toggle CSS classes.

tony commented 3 years ago

Proposal would be, if a function is passed to this.props.on{Blur,KeyUp,KeyDown}, pass (event: React.SyntheticEvent<any>, emitChange(originalEvt: React.SyntheticEvent<any>) => void) to the prop, this way, they could still run emitChange(event) if they want.

I don't think this would be possible due to the underlying typings of on{Blur,KeyUp,KeyDown}