Skip to content

Commit

Permalink
fix: allow copying from editable void input (#5369)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-vladut authored Mar 17, 2023
1 parent a9c0e37 commit 556a456
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-students-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': patch
---

Allow copying from editable void input
21 changes: 19 additions & 2 deletions packages/slate-react/src/components/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,8 @@ export const Editable = (props: EditableProps) => {
(event: React.ClipboardEvent<HTMLDivElement>) => {
if (
ReactEditor.hasSelectableTarget(editor, event.target) &&
!isEventHandled(event, attributes.onCopy)
!isEventHandled(event, attributes.onCopy) &&
!isDOMEventTargetInput(event)
) {
event.preventDefault()
ReactEditor.setFragmentData(
Expand All @@ -1174,7 +1175,8 @@ export const Editable = (props: EditableProps) => {
if (
!readOnly &&
ReactEditor.hasSelectableTarget(editor, event.target) &&
!isEventHandled(event, attributes.onCut)
!isEventHandled(event, attributes.onCut) &&
!isDOMEventTargetInput(event)
) {
event.preventDefault()
ReactEditor.setFragmentData(
Expand Down Expand Up @@ -1736,6 +1738,21 @@ export const isEventHandled = <
return event.isDefaultPrevented() || event.isPropagationStopped()
}

/**
* Check if the event's target is an input element
*/
export const isDOMEventTargetInput = <
EventType extends React.SyntheticEvent<unknown, unknown>
>(
event: EventType
) => {
return (
isDOMNode(event.target) &&
(event.target instanceof HTMLInputElement ||
event.target instanceof HTMLTextAreaElement)
)
}

/**
* Check if a DOM event is overrided by a handler.
*/
Expand Down

0 comments on commit 556a456

Please sign in to comment.