Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Popover): use visible title for popup a11y label #1941

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading