Skip to content

Commit

Permalink
fix: aria-describedby
Browse files Browse the repository at this point in the history
  • Loading branch information
bvandercar-vt committed Jun 26, 2024
1 parent 8c44382 commit 730d177
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/core/src/components/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,14 @@ export class Tooltip<

const tooltipId = Utils.uniqueId("tooltip");

const childTarget = Utils.ensureElement(React.Children.toArray(children)[0], undefined, {
"aria-describedby": tooltipId,
const childTarget = Utils.ensureElement(React.Children.toArray(children)[0]);

if (childTarget === undefined) {
return null;
}

const clonedTarget: React.JSX.Element = React.cloneElement(childTarget, {
"aria-describedby": [tooltipId, childTarget.props["aria-describedby"]].filter(Boolean).join(" "),

This comment has been minimized.

Copy link
@bvandercar-vt

bvandercar-vt Jun 26, 2024

Author Contributor

Or style wise would we prefer to do it this way

"aria-describedby": tooltipId + (childTarget.props["aria-describedby"] ? ` ${childTarget.props["aria-describedby"]}` : ""),
});

return (
Expand Down Expand Up @@ -149,7 +155,7 @@ export class Tooltip<
portalContainer={this.props.portalContainer}
ref={this.popoverRef}
>
{childTarget}
{clonedTarget}
</Popover>
);
};
Expand Down

0 comments on commit 730d177

Please sign in to comment.