import { type TAriaHasPopupValue, type TRoleRequiringAccessibleName } from './role-types'; /** * Roles accepted by `getAriaForTrigger`. * * Excludes tooltip-family roles (`tooltip`, `note`, `status`, `alert`, `log`) * because the correct trigger wiring for those is `aria-describedby`, not * `aria-haspopup` / `aria-expanded` / `aria-controls`. Use `aria-describedby` * manually for tooltip triggers. */ type TAriaForTriggerRole = TRoleRequiringAccessibleName | 'listbox' | 'tree' | 'grid'; type TGetAriaForTriggerOptions = { /** * The `role` that will be set on the `` element. Used to derive * the correct `aria-haspopup` value for the trigger. */ role: TAriaForTriggerRole; /** * Whether the popover is currently open. Drives `aria-expanded`. */ isOpen: boolean; /** * The popover identifier - the value returned by `usePopoverId()`, * passed as `id` to `` and referenced here via `aria-controls`. */ popoverId: string; }; /** * Non-undefined subset of `TAriaHasPopupValue`. Every role accepted by * `getAriaForTrigger` maps to a concrete `aria-haspopup` string, so the * trigger always receives a defined attribute value. */ type TAriaHasPopupForTrigger = Exclude; type TAriaForTrigger = { 'aria-haspopup': TAriaHasPopupForTrigger; 'aria-expanded': boolean; /** * `aria-controls` is `undefined` while the popover is closed, because * the popover host element is only rendered in the DOM while open. A * dangling `aria-controls` reference (pointing at a missing ID) is * tolerated by assistive tech but flagged by some a11y tooling, so * we leave it unset until the target exists. */ 'aria-controls': string | undefined; }; /** * Returns the ARIA attributes to spread onto a click-activated popover trigger. * * Centralises three attributes that are easy to forget or get wrong individually: * * - `aria-haspopup` - derived from the popover's role (e.g. `dialog → "dialog"`, * `menu → "menu"`, `tooltip → undefined`). React omits the attribute when * the value is `undefined`. * - `aria-expanded` - reflects the current open state. * - `aria-controls` - references the popover element by its id, even * while the popover is closed. The relationship is stable; `aria-expanded` * carries the current visibility state. * * **This function is for click/keyboard-activated popovers only.** For * hover-driven tooltips, the trigger should use `aria-describedby` instead. * * @example * ```tsx * import { getAriaForTrigger } from '@atlaskit/top-layer/get-aria-for-trigger'; * import { usePopoverId } from '@atlaskit/top-layer/use-popover-id'; * * const popoverId = usePopoverId(); * const [isOpen, setIsOpen] = useState(false); * * return ( * <> * * setIsOpen(false)} * > * … * * * ); * ``` */ export declare function getAriaForTrigger({ role, isOpen, popoverId, }: TGetAriaForTriggerOptions): TAriaForTrigger; export {};