Skip to content
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

fix: allow copying from editable void input #5369

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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