From 6d91000d41ce4a5af088629eeb9e91fa306dedb8 Mon Sep 17 00:00:00 2001 From: Peter Hellstrand Date: Thu, 3 Oct 2024 23:38:19 +0200 Subject: [PATCH] fix(ffe-cards-react): possible to copy text in card Do not follow link when text is selected in card. --- packages/ffe-cards-react/src/components/WithCardAction.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/ffe-cards-react/src/components/WithCardAction.tsx b/packages/ffe-cards-react/src/components/WithCardAction.tsx index c0b7c7048e..4b00c9a77d 100644 --- a/packages/ffe-cards-react/src/components/WithCardAction.tsx +++ b/packages/ffe-cards-react/src/components/WithCardAction.tsx @@ -81,7 +81,12 @@ function WithCardActionForwardRef( isUsingCardAction && `${baseClassName}--clickable`, )} onClick={(e: React.MouseEvent) => { - if (!cardActionInnerRef.current?.contains(e.target as Node)) { + const hasSelectedText = !!window.getSelection()?.toString() + .length; + if ( + !hasSelectedText && + !cardActionInnerRef.current?.contains(e.target as Node) + ) { cardActionInnerRef.current?.click(); } onClick?.(e);