From 49083ddc865dd9a6343bd6b70f6bd04e16b220f1 Mon Sep 17 00:00:00 2001 From: Fred Carlsen Date: Tue, 20 Aug 2024 15:02:32 +0200 Subject: [PATCH] fix(core): fix copy related issues (#7394) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(core): ignore all input/textarea elements when copying fixes sdx-1591 Signed-off-by: Fred Carlsen * 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 --------- Signed-off-by: Fred Carlsen --- .../form/inputs/ReferenceInput/ReferenceField.tsx | 13 ++++++++----- packages/sanity/src/core/studio/copyPaste/utils.ts | 8 +------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/sanity/src/core/form/inputs/ReferenceInput/ReferenceField.tsx b/packages/sanity/src/core/form/inputs/ReferenceInput/ReferenceField.tsx index 0fb43121c38..3aaf9ed11a8 100644 --- a/packages/sanity/src/core/form/inputs/ReferenceInput/ReferenceField.tsx +++ b/packages/sanity/src/core/form/inputs/ReferenceInput/ReferenceField.tsx @@ -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' @@ -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 ( @@ -279,7 +283,6 @@ export function ReferenceField(props: ReferenceFieldProps) { selected={selected} tone="inherit" onFocus={handleFocus} - onBlur={handleBlur} >