Skip to content

Commit

Permalink
Merge pull request #261 from element-hq/t3chguy/tooltip-role
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Oct 18, 2024
2 parents 9604916 + a339554 commit c6cdc7c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function TooltipContent({
<div
ref={rest.refs.setFloating}
style={rest.floatingStyles}
{...rest.tooltipProps}
{...rest.getFloatingProps()}
className={classNames(styles.tooltip, {
[styles.invisible]: purpose === "label" && !open,
Expand Down
15 changes: 14 additions & 1 deletion src/components/Tooltip/useTooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
useInteractions,
useRole,
} from "@floating-ui/react";
import { useMemo, useRef, useState, JSX } from "react";
import { useMemo, useRef, useState, JSX, AriaAttributes } from "react";
import { hoverDelay } from "./TooltipProvider";

export interface CommonUseTooltipProps {
Expand Down Expand Up @@ -80,6 +80,13 @@ export interface CommonUseTooltipProps {
* - trigger will be wrapped in a span with a tab index from prop nonInteractiveTriggerTabIndex
*/
isTriggerInteractive: boolean;

/**
* Additional aria-* attributes to pass through to the floating tooltip for
* edge cases which require more user awareness like errors & alerts.
*/
"aria-atomic"?: AriaAttributes["aria-atomic"];
"aria-live"?: AriaAttributes["aria-live"];
}

export interface TooltipLabel {
Expand All @@ -106,6 +113,8 @@ export function useTooltip({
placement = "bottom",
isTriggerInteractive,
caption,
"aria-atomic": ariaAtomic,
"aria-live": ariaLive,
...props
}: UseTooltipProps) {
const labelId = useId();
Expand Down Expand Up @@ -200,6 +209,10 @@ export function useTooltip({
purpose: purpose as "label" | "description",
open,
setOpen,
tooltipProps: {
"aria-atomic": ariaAtomic,
"aria-live": ariaLive,
},
...interactions,
...data,
arrowRef,
Expand Down

0 comments on commit c6cdc7c

Please sign in to comment.