From 2c9bdb9d31f295918172602920fce1bee20d75b0 Mon Sep 17 00:00:00 2001 From: Sarka Chwastkova Date: Fri, 15 Nov 2024 17:54:06 +0100 Subject: [PATCH 1/3] docs: add accessibility docs to Tooltip component --- .../04-overlay/tooltip/03-accessibility.mdx | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 docs/src/documentation/03-components/04-overlay/tooltip/03-accessibility.mdx diff --git a/docs/src/documentation/03-components/04-overlay/tooltip/03-accessibility.mdx b/docs/src/documentation/03-components/04-overlay/tooltip/03-accessibility.mdx new file mode 100644 index 0000000000..8636d1e3cb --- /dev/null +++ b/docs/src/documentation/03-components/04-overlay/tooltip/03-accessibility.mdx @@ -0,0 +1,49 @@ +--- +title: Accessibility +redirect_from: + - /components/tooltip/accessibility/ +--- + +## Accessibility + +### Tooltip + +The Tooltip component has been designed with accessibility in mind. It can be used with keyboard navigation and includes properties that enhance the experience for users of assistive technologies. + +While the `aria-label` and `aria-labelledby` attributes are not needed for the Tooltip component itself, it is important to ensure that the components passed as children can be perceived by assistive technologies. This ensures that the Tooltip component is accessible. + +#### Example 1 + +The content of children component is text, so it is read by screen reader. + +```jsx + +

Lorem ipsum dolor sit amet.

+ + } +> + Learn more. +
+``` + +The screen reader will announce: "Learn more. Lorem ipsum dolor sit amet.". + +#### Example 2 + +The children element is an icon component. To achieve the accessibility of the Tooltip, adding an `aria-label` to the icon component is necessary. + +```jsx + +

Lorem ipsum dolor sit amet.

+ + } +> + +
+``` + +Once the icon is focused by the screen reader, it will announce: "More information", followed by announcing the content of the tooltip: "Lorem ipsum dolor sit amet.". From b34cba8e8823574692f8fb6bac94f6cb43b19534 Mon Sep 17 00:00:00 2001 From: Sarka Chwastkova Date: Tue, 26 Nov 2024 17:53:04 +0100 Subject: [PATCH 2/3] fix(TooltipPrimitive): remove redundant role attribute --- .../components/TooltipContent.tsx | 83 ++++++++++--------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/packages/orbit-components/src/primitives/TooltipPrimitive/components/TooltipContent.tsx b/packages/orbit-components/src/primitives/TooltipPrimitive/components/TooltipContent.tsx index 93b0855950..76d0e84b2d 100644 --- a/packages/orbit-components/src/primitives/TooltipPrimitive/components/TooltipContent.tsx +++ b/packages/orbit-components/src/primitives/TooltipPrimitive/components/TooltipContent.tsx @@ -105,54 +105,55 @@ const TooltipContent = ({ [onClose, onCloseMobile, elements.floating], ); + const handleCombinedClick = (ev: React.MouseEvent) => { + handleInnerClick(ev); + onClick(ev); + }; + return ( - // Disabling because the onClick exists just to stop propagation of events + // Disabling because the onClick exists to close tooltip when clicking in interactive elements, which should not happen with keyboard. // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions -