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.". diff --git a/packages/orbit-components/src/Tooltip/Tooltip.stories.tsx b/packages/orbit-components/src/Tooltip/Tooltip.stories.tsx index d0639e5fc2..4f1bf96b88 100644 --- a/packages/orbit-components/src/Tooltip/Tooltip.stories.tsx +++ b/packages/orbit-components/src/Tooltip/Tooltip.stories.tsx @@ -3,7 +3,7 @@ import { action } from "@storybook/addon-actions"; import type { Meta, StoryObj } from "@storybook/react"; import { PLACEMENTS, AUTO_PLACEMENTS } from "../common/placements"; -import * as Icons from "../icons"; +import Airplane from "../icons/Airplane"; import { SIZE_OPTIONS } from "./consts"; import Stack from "../Stack"; import Alert from "../Alert"; @@ -47,7 +47,7 @@ export const Default: Story = { render: args => ( - + ), @@ -149,7 +149,7 @@ export const WithImageInside: Story = { } > - + ), diff --git a/packages/orbit-components/src/primitives/TooltipPrimitive/TooltipPrimitive.stories.tsx b/packages/orbit-components/src/primitives/TooltipPrimitive/TooltipPrimitive.stories.tsx index 987bc04f2e..e076240073 100644 --- a/packages/orbit-components/src/primitives/TooltipPrimitive/TooltipPrimitive.stories.tsx +++ b/packages/orbit-components/src/primitives/TooltipPrimitive/TooltipPrimitive.stories.tsx @@ -2,7 +2,7 @@ import * as React from "react"; import { action } from "@storybook/addon-actions"; import type { Meta, StoryObj } from "@storybook/react"; -import * as Icons from "../../icons"; +import Airplane from "../../icons/Airplane"; import Stack from "../../Stack"; import Alert from "../../Alert"; import Text from "../../Text"; @@ -43,7 +43,7 @@ export const Default: Story = { render: args => ( - + ), @@ -147,7 +147,7 @@ export const WithImageInside: Story = { } > - + ), 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 -