Skip to content

Commit

Permalink
feat(TooltipPrimitive): add aria-label, aria-labelledby props
Browse files Browse the repository at this point in the history
  • Loading branch information
sarkaaa committed Nov 15, 2024
1 parent a235c70 commit aa6aafa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,23 @@ const meta: Meta<typeof TooltipPrimitive> = {

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",
},
};

Expand All @@ -59,6 +70,7 @@ export const Default: Story = {
"size",
"stopPropagation",
"block",
"aria-label",
],
},
},
Expand Down Expand Up @@ -162,6 +174,8 @@ export const WithImageInside: Story = {
"renderInPortal",
"stopPropagation",
"block",
"aria-label",
"aria-labelledby",
],
},
},
Expand All @@ -188,7 +202,7 @@ export const WithImageInside: Story = {
};

export const Playground: Story = {
render: ({ children, content, ...args }) => (
render: ({ children, content, "aria-labelledby": ariaLabelledby, ...args }) => (
<Alert icon title="Lorem ipsum dolor sit amet" type="warning">
<Stack spacing="none">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam lectus justo, vulputate
Expand All @@ -202,9 +216,10 @@ export const Playground: Story = {
<TextLink>Clickable element.</TextLink>
</div>
}
aria-labelledby={ariaLabelledby}
{...args}
>
<Text>{children}</Text>
<Text id={ariaLabelledby}>{children}</Text>
</TooltipPrimitive>
</Stack>
</Alert>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLSpanElement | null>(null);
Expand Down Expand Up @@ -133,6 +135,8 @@ const TooltipPrimitive = ({
enabled={enabled}
removeUnderlinedText={removeUnderlinedText}
block={block}
aria-label={ariaLabel}
aria-labelledby={ariaLabelledby}
>
{children}
</TooltipWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit aa6aafa

Please sign in to comment.