From aa6aafa07237e69d5c219173e0939d17f4a4646c Mon Sep 17 00:00:00 2001 From: Sarka Chwastkova Date: Mon, 11 Nov 2024 18:52:45 +0100 Subject: [PATCH] feat(TooltipPrimitive): add aria-label, aria-labelledby props --- .../TooltipPrimitive.stories.tsx | 21 ++++++++++++++++--- .../src/primitives/TooltipPrimitive/index.tsx | 4 ++++ .../primitives/TooltipPrimitive/types.d.ts | 2 ++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/orbit-components/src/primitives/TooltipPrimitive/TooltipPrimitive.stories.tsx b/packages/orbit-components/src/primitives/TooltipPrimitive/TooltipPrimitive.stories.tsx index 987bc04f2e..32d69abf40 100644 --- a/packages/orbit-components/src/primitives/TooltipPrimitive/TooltipPrimitive.stories.tsx +++ b/packages/orbit-components/src/primitives/TooltipPrimitive/TooltipPrimitive.stories.tsx @@ -27,12 +27,23 @@ const meta: Meta = { parameters: { controls: { - exclude: ["onShow", "enabled", "tabIndex", "renderInPortal", "size", "stopPropagation"], + exclude: [ + "onShow", + "enabled", + "tabIndex", + "renderInPortal", + "size", + "stopPropagation", + "aria-label", + "aria-labelledby", + ], }, }, args: { onShow: action("onShow"), + "aria-label": "Tooltip label", + "aria-labelledby": "tooltip-labelledby", }, }; @@ -59,6 +70,7 @@ export const Default: Story = { "size", "stopPropagation", "block", + "aria-label", ], }, }, @@ -162,6 +174,8 @@ export const WithImageInside: Story = { "renderInPortal", "stopPropagation", "block", + "aria-label", + "aria-labelledby", ], }, }, @@ -188,7 +202,7 @@ export const WithImageInside: Story = { }; export const Playground: Story = { - render: ({ children, content, ...args }) => ( + render: ({ children, content, "aria-labelledby": ariaLabelledby, ...args }) => ( Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam lectus justo, vulputate @@ -202,9 +216,10 @@ export const Playground: Story = { Clickable element. } + aria-labelledby={ariaLabelledby} {...args} > - {children} + {children} diff --git a/packages/orbit-components/src/primitives/TooltipPrimitive/index.tsx b/packages/orbit-components/src/primitives/TooltipPrimitive/index.tsx index cdceffd3a7..b53cdc8a57 100644 --- a/packages/orbit-components/src/primitives/TooltipPrimitive/index.tsx +++ b/packages/orbit-components/src/primitives/TooltipPrimitive/index.tsx @@ -52,6 +52,8 @@ const TooltipPrimitive = ({ placement, noFlip, offset, + "aria-label": ariaLabel, + "aria-labelledby": ariaLabelledby, }: Props) => { const [shown, setShown] = React.useState(false); const [referenceElement, setReferenceElement] = React.useState(null); @@ -133,6 +135,8 @@ const TooltipPrimitive = ({ enabled={enabled} removeUnderlinedText={removeUnderlinedText} block={block} + aria-label={ariaLabel} + aria-labelledby={ariaLabelledby} > {children} diff --git a/packages/orbit-components/src/primitives/TooltipPrimitive/types.d.ts b/packages/orbit-components/src/primitives/TooltipPrimitive/types.d.ts index 0350becc7b..bc5bc2f9bc 100644 --- a/packages/orbit-components/src/primitives/TooltipPrimitive/types.d.ts +++ b/packages/orbit-components/src/primitives/TooltipPrimitive/types.d.ts @@ -25,4 +25,6 @@ export interface Props extends Common.Globals { readonly placement?: Placement; readonly noFlip?: boolean; readonly offset?: [number, number]; + readonly "aria-label"?: string; + readonly "aria-labelledby"?: string; }