Skip to content

Commit 49083dd

Browse files
authored
fix(core): fix copy related issues (#7394)
* 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]>
1 parent 1a2ef91 commit 49083dd

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

packages/sanity/src/core/form/inputs/ReferenceInput/ReferenceField.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {MenuButton, MenuItem, TooltipDelayGroupProvider} from '../../../../ui-co
1717
import {ContextMenuButton} from '../../../components/contextMenuButton'
1818
import {type DocumentFieldActionNode} from '../../../config'
1919
import {useTranslation} from '../../../i18n'
20+
import {EMPTY_ARRAY} from '../../../util/empty'
2021
import {FormField} from '../../components'
2122
import {usePublishedId} from '../../contexts/DocumentIdProvider'
2223
import {FieldActionsProvider, FieldActionsResolver} from '../../field'
@@ -223,10 +224,13 @@ export function ReferenceField(props: ReferenceFieldProps) {
223224
[handleClear, handleReplace, inputId, OpenLink, readOnly, t, value?._ref],
224225
)
225226

226-
const handleFocus = useCallback(() => inputProps.onPathFocus([]), [inputProps])
227-
const handleBlur = useCallback(
228-
(event: FocusEvent) => inputProps.elementProps.onBlur(event),
229-
[inputProps.elementProps],
227+
const handleFocus = useCallback(
228+
(event: FocusEvent) => {
229+
if (event.target === elementRef.current) {
230+
inputProps.onPathFocus(EMPTY_ARRAY)
231+
}
232+
},
233+
[inputProps],
230234
)
231235

232236
return (
@@ -279,7 +283,6 @@ export function ReferenceField(props: ReferenceFieldProps) {
279283
selected={selected}
280284
tone="inherit"
281285
onFocus={handleFocus}
282-
onBlur={handleBlur}
283286
>
284287
<PreviewReferenceValue
285288
value={value}

packages/sanity/src/core/studio/copyPaste/utils.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,7 @@ export function isEmptyValue(value: unknown): boolean {
168168

169169
export function isNativeEditableElement(el: EventTarget): boolean {
170170
if (el instanceof HTMLElement && el.isContentEditable) return true
171-
if (el instanceof HTMLInputElement) {
172-
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types
173-
if (/|text|email|number|password|search|tel|url/.test(el.type || '')) {
174-
return !(el.disabled || el.readOnly)
175-
}
176-
}
177-
if (el instanceof HTMLTextAreaElement) return !(el.disabled || el.readOnly)
171+
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) return true
178172
return false
179173
}
180174

0 commit comments

Comments
 (0)