From edda9db3ac3cbb62f69dea124c1b4744372e61f6 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 28 Nov 2024 15:18:49 +0100 Subject: [PATCH 1/2] DataViews: Avoid double click handler on primary fields --- .../dataviews-layouts/utils/get-clickable-item-props.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/dataviews/src/dataviews-layouts/utils/get-clickable-item-props.ts b/packages/dataviews/src/dataviews-layouts/utils/get-clickable-item-props.ts index e2a6081a68fa3..36969b65edf1b 100644 --- a/packages/dataviews/src/dataviews-layouts/utils/get-clickable-item-props.ts +++ b/packages/dataviews/src/dataviews-layouts/utils/get-clickable-item-props.ts @@ -12,9 +12,15 @@ export default function getClickableItemProps< Item >( className: `${ className } ${ className }--clickable`, role: 'button', tabIndex: 0, - onClick: () => onClickItem( item ), + onClick: ( event: React.MouseEvent ) => { + event.preventDefault(); + event.stopPropagation(); + onClickItem( item ); + }, onKeyDown: ( event: React.KeyboardEvent ) => { if ( event.key === 'Enter' || event.key === '' ) { + event.preventDefault(); + event.stopPropagation(); onClickItem( item ); } }, From 59708baed3b7169ba5cbfaeac02110b332a0d15e Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 28 Nov 2024 17:33:10 +0100 Subject: [PATCH 2/2] Stop propagation --- .../src/dataviews-layouts/utils/get-clickable-item-props.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/dataviews/src/dataviews-layouts/utils/get-clickable-item-props.ts b/packages/dataviews/src/dataviews-layouts/utils/get-clickable-item-props.ts index 36969b65edf1b..efb4a8f598c7b 100644 --- a/packages/dataviews/src/dataviews-layouts/utils/get-clickable-item-props.ts +++ b/packages/dataviews/src/dataviews-layouts/utils/get-clickable-item-props.ts @@ -13,13 +13,13 @@ export default function getClickableItemProps< Item >( role: 'button', tabIndex: 0, onClick: ( event: React.MouseEvent ) => { - event.preventDefault(); + // Prevents onChangeSelection from triggering. event.stopPropagation(); onClickItem( item ); }, onKeyDown: ( event: React.KeyboardEvent ) => { if ( event.key === 'Enter' || event.key === '' ) { - event.preventDefault(); + // Prevents onChangeSelection from triggering. event.stopPropagation(); onClickItem( item ); }