Skip to content

Commit

Permalink
fix(core): fix copy related issues (#7394)
Browse files Browse the repository at this point in the history
* fix(core): ignore all input/textarea elements when copying

fixes sdx-1591

Signed-off-by: Fred Carlsen <[email protected]>

* fix(core): fix blur issue for references inside groups

Removes blur handler on reference preview. This is a unnecessary footgun, and it is triggered because focus will change to the first element in the opened reference pane.

It isn’t clear why this only happens inside groups, though, so might dig more into that.

Fixes #7265

Signed-off-by: Fred Carlsen <[email protected]>

---------

Signed-off-by: Fred Carlsen <[email protected]>
  • Loading branch information
sjelfull authored and jordanl17 committed Aug 29, 2024
1 parent f0e95b3 commit 3e17c21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {MenuButton, MenuItem, TooltipDelayGroupProvider} from '../../../../ui-co
import {ContextMenuButton} from '../../../components/contextMenuButton'
import {type DocumentFieldActionNode} from '../../../config'
import {useTranslation} from '../../../i18n'
import {EMPTY_ARRAY} from '../../../util/empty'
import {FormField} from '../../components'
import {usePublishedId} from '../../contexts/DocumentIdProvider'
import {FieldActionsProvider, FieldActionsResolver} from '../../field'
Expand Down Expand Up @@ -223,10 +224,13 @@ export function ReferenceField(props: ReferenceFieldProps) {
[handleClear, handleReplace, inputId, OpenLink, readOnly, t, value?._ref],
)

const handleFocus = useCallback(() => inputProps.onPathFocus([]), [inputProps])
const handleBlur = useCallback(
(event: FocusEvent) => inputProps.elementProps.onBlur(event),
[inputProps.elementProps],
const handleFocus = useCallback(
(event: FocusEvent) => {
if (event.target === elementRef.current) {
inputProps.onPathFocus(EMPTY_ARRAY)
}
},
[inputProps],
)

return (
Expand Down Expand Up @@ -279,7 +283,6 @@ export function ReferenceField(props: ReferenceFieldProps) {
selected={selected}
tone="inherit"
onFocus={handleFocus}
onBlur={handleBlur}
>
<PreviewReferenceValue
value={value}
Expand Down
8 changes: 1 addition & 7 deletions packages/sanity/src/core/studio/copyPaste/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,7 @@ export function isEmptyValue(value: unknown): boolean {

export function isNativeEditableElement(el: EventTarget): boolean {
if (el instanceof HTMLElement && el.isContentEditable) return true
if (el instanceof HTMLInputElement) {
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types
if (/|text|email|number|password|search|tel|url/.test(el.type || '')) {
return !(el.disabled || el.readOnly)
}
}
if (el instanceof HTMLTextAreaElement) return !(el.disabled || el.readOnly)
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) return true
return false
}

Expand Down

0 comments on commit 3e17c21

Please sign in to comment.