Skip to content

Commit

Permalink
fix(Popover): use visible title for popup a11y label (#1941)
Browse files Browse the repository at this point in the history
  • Loading branch information
ogonkov authored Nov 11, 2024
1 parent b5de671 commit f9d75e8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/Popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from 'react';

import {Xmark} from '@gravity-ui/icons';

import {useUniqId} from '../../hooks/useUniqId';
import {Button} from '../Button';
import {Icon} from '../Icon';
import type {PopupPlacement} from '../Popup';
Expand Down Expand Up @@ -115,6 +116,8 @@ export const Popover = React.forwardRef<PopoverInstanceProps, PopoverProps & QAP

const hasTitle = Boolean(title);

const popoverTitleId = `popover-${tooltipId ?? ''}-title-${useUniqId()}`;

const tooltip = (
<Popup
id={tooltipId}
Expand Down Expand Up @@ -144,9 +147,14 @@ export const Popover = React.forwardRef<PopoverInstanceProps, PopoverProps & QAP
restoreFocus={true}
restoreFocusRef={restoreFocusRef || controlRef}
modifiers={modifiers}
aria-labelledby={title ? popoverTitleId : undefined}
>
<React.Fragment>
{title && <h3 className={cnPopover('tooltip-title')}>{title}</h3>}
{title && (
<h3 id={popoverTitleId} className={cnPopover('tooltip-title')}>
{title}
</h3>
)}
<Content
secondary={hasTitle ? theme !== 'announcement' : false}
content={content}
Expand Down

0 comments on commit f9d75e8

Please sign in to comment.