-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow control of Slate's event handler execution in custom event handler API #4299
Changes from 2 commits
afb7ddc
7dbbe7c
d7204c5
bf3c5f2
2c2b4c2
1c2a568
a825832
c9df05f
6cf1505
5ac9d88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'slate-react': patch | ||
--- | ||
|
||
Allow custom event handlers on Editable component to return boolean flag to specify whether the event can be treated as being handled |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1191,14 +1191,21 @@ export const isEventHandled = < | |
EventType extends React.SyntheticEvent<unknown, unknown> | ||
>( | ||
event: EventType, | ||
handler?: (event: EventType) => void | ||
handler?: (event: EventType) => void | boolean | ||
) => { | ||
if (!handler) { | ||
return false | ||
} | ||
// The custom event handler may return a boolean to specify whether the event | ||
// shall be treated as being handled or not. | ||
const shouldTreatEventAsHandled = handler(event) | ||
|
||
handler(event) | ||
return event.isDefaultPrevented() || event.isPropagationStopped() | ||
return ( | ||
(shouldTreatEventAsHandled === true || | ||
event.isDefaultPrevented() || | ||
event.isPropagationStopped()) && | ||
shouldTreatEventAsHandled !== false | ||
) | ||
georgberecz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha, very good point! I initially thought it shouldn't, but after having another look at the code I feel like it actually should behave the same way to stay consistent and not confuse people. I will adjust it. |
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a
minor
bump as it introduces new functionality rather than just a fix