Skip to content

Commit 3900875

Browse files
committed
fix: allow copy events on inline objects
The `draggable` attribute on the top-level span in inline objects interfered with copy events when the attribute was set to `true`. This meant that you couldn't copy inline objects when the editor was editable, only when it was in read-only. The `draggable="true"` attribute changes browser event handling to prioritize drag operations over selection. This prevents proper DOM selection from being established, causing the copy event to never fire. Per the HTML5 Drag and Drop spec, draggable elements cannot be selected normally - "text or other elements within it can no longer be selected in the normal way" (MDN). This is a design choice, not a bug.
1 parent 5e98297 commit 3900875

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

.changeset/three-kiwis-cheer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@portabletext/editor': patch
3+
---
4+
5+
fix: allow copying inline object

packages/editor/src/editor/render.inline-object.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,17 @@ export function RenderInlineObject(props: {
7474
return (
7575
<span
7676
{...props.attributes}
77-
draggable={!props.readOnly}
7877
className="pt-inline-object"
7978
data-child-key={inlineObject._key}
8079
data-child-name={inlineObject._type}
8180
data-child-type="object"
8281
>
8382
{props.children}
84-
<span ref={inlineObjectRef} style={{display: 'inline-block'}}>
83+
<span
84+
ref={inlineObjectRef}
85+
style={{display: 'inline-block'}}
86+
draggable={!props.readOnly}
87+
>
8588
{props.renderChild && path && legacySchemaType ? (
8689
<RenderChild
8790
renderChild={props.renderChild}

0 commit comments

Comments
 (0)