From 501d9056cc57023b7744bae0faf4028d4f85176c Mon Sep 17 00:00:00 2001 From: kirillmohno Date: Tue, 10 Oct 2023 21:02:12 +0300 Subject: [PATCH] fix: add tags and fix Label component --- src/components/DropdownMenu/DropdownMenu.tsx | 2 +- src/components/Label/Label.scss | 15 ++++++++++++ src/components/Label/Label.tsx | 23 +++++++++++++++++-- src/components/Link/Link.tsx | 3 ++- .../TableColumnSetup/TableColumnSetup.tsx | 2 +- src/components/UserAvatar/UserAvatar.scss | 10 -------- src/components/UserAvatar/UserAvatar.tsx | 15 +++--------- src/hooks/useOutsideClick/__tests__/Demo.tsx | 5 ++-- 8 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/components/DropdownMenu/DropdownMenu.tsx b/src/components/DropdownMenu/DropdownMenu.tsx index c08825023b..5021241d00 100644 --- a/src/components/DropdownMenu/DropdownMenu.tsx +++ b/src/components/DropdownMenu/DropdownMenu.tsx @@ -137,7 +137,7 @@ const DropdownMenu = ({ return ( - {/* It is used to handle clicks on the switcher control */} + {/* FIXME change to renderProp or provide component's context */} {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
(function Label onClick, } = props; + const actionButtonRef = React.useRef(null); + const hasContent = Boolean(children !== '' && React.Children.count(children) > 0); const typeClose = type === 'close' && hasContent; @@ -122,12 +125,25 @@ export const Label = React.forwardRef(function Label } }; + const handleClick = (event: React.MouseEvent) => { + /** + * Triggered only if the handler was triggered on the element itself, and not on the actionButton + * It is necessary that keyboard navigation works correctly + */ + if (!actionButtonRef.current?.contains(event.target as Node)) { + onClick?.(event); + } + }; + + const {onKeyDown} = useActionHandlers(handleClick); + const renderLabel = (status?: CopyToClipboardStatus) => { let actionButton: React.ReactNode; if (typeCopy) { actionButton = (
+
{'Outside'}
);