1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-14 11:14:04 +02:00

Fix inputs from not being able to be used within void nodes in Firefox and Added example of input and other editable void nodes (#3436)

This commit is contained in:
Ryan Mitts
2020-02-25 20:52:11 -08:00
committed by GitHub
parent d8cc9fc46b
commit 9504c4472c
3 changed files with 163 additions and 2 deletions

View File

@@ -443,11 +443,16 @@ export const Editable = (props: EditableProps) => {
...style,
}}
onBeforeInput={useCallback(
(event: React.SyntheticEvent) => {
(event: React.FormEvent<HTMLDivElement>) => {
// COMPAT: Firefox doesn't support the `beforeinput` event, so we
// fall back to React's leaky polyfill instead just for it. It
// only works for the `insertText` input type.
if (IS_FIREFOX && !readOnly) {
if (
IS_FIREFOX &&
!readOnly &&
!isEventHandled(event, attributes.onBeforeInput) &&
hasEditableTarget(editor, event.target)
) {
event.preventDefault()
const text = (event as any).data as string
Editor.insertText(editor, text)