-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow control of Slate's event handler execution in custom event hand…
…ler API (#4299) Co-authored-by: Georg Berecz <gberecz@palantir.com> Co-authored-by: Claudéric Demers <clauderic.d@gmail.com>
- Loading branch information
1 parent
dfc0396
commit 2c17e2b
Showing
3 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
'slate-react': minor | ||
--- | ||
|
||
Allow custom event handlers on Editable component to return boolean flag to specify whether the event can be treated as being handled. | ||
|
||
By default, the `Editable` component comes with a set of event handlers that handle typical rich-text editing behaviors (for example, it implements its own `onCopy`, `onPaste`, `onDrop`, and `onKeyDown` handlers). | ||
|
||
In some cases you may want to extend or override Slate's default behavior, which can be done by passing your own event handler(s) to the `Editable` component. | ||
|
||
Your custom event handler can control whether or not Slate should execute its own event handling for a given event after your handler runs depending on the return value of your event handler as described below. | ||
|
||
```jsx | ||
import {Editable} from 'slate-react'; | ||
|
||
function MyEditor() { | ||
const onClick = event => { | ||
// Implement custom event logic... | ||
|
||
// When no value is returned, Slate will execute its own event handler when | ||
// neither isDefaultPrevented nor isPropagationStopped was set on the event | ||
}; | ||
|
||
const onDrop = event => { | ||
// Implement custom event logic... | ||
|
||
// No matter the state of the event, treat it as being handled by returning | ||
// true here, Slate will skip its own event handler | ||
return true; | ||
}; | ||
|
||
const onDragStart = event => { | ||
// Implement custom event logic... | ||
|
||
// No matter the status of the event, treat event as *not* being handled by | ||
// returning false, Slate will exectue its own event handler afterward | ||
return false; | ||
}; | ||
|
||
return ( | ||
<Editable | ||
onClick={onClick} | ||
onDrop={onDrop} | ||
onDragStart={onDragStart} | ||
{/*...*/} | ||
/> | ||
) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters