Skip to content

Commit

Permalink
Improve popover accessibility. (#18173)
Browse files Browse the repository at this point in the history
  • Loading branch information
linuspahl authored Feb 6, 2024
1 parent 5ff0e5d commit a2cfd8a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions graylog2-web-interface/src/components/common/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,24 @@ const Title = styled.h4(({ theme }) => css`
font-size: ${theme.fonts.size.body};
`);

const titleId = (id: string) => `${id}-title`;

const dropdownAriaLabelledby = (ariaLabelBy: string | undefined, id: string | undefined, title: React.ReactNode | undefined) => {
if (ariaLabelBy) {
return ariaLabelBy;
}

if (id && title) {
return titleId(id);
}

return null;
};

const Dropdown = ({ title, children, ...rest }: DropdownProps) => (
<MantinePopover.Dropdown {...rest}>
<MantinePopover.Dropdown aria-labelledby={dropdownAriaLabelledby(rest['aria-labelledby'], rest.id, title)} {...rest}>
{title && (
<Title>
<Title id={rest.id ? titleId(rest.id) : null}>
{title}
</Title>
)}
Expand All @@ -69,6 +83,10 @@ const Dropdown = ({ title, children, ...rest }: DropdownProps) => (
</MantinePopover.Dropdown>
);

Dropdown.defaultProps = {
title: undefined,
};

Popover.Target = MantinePopover.Target;
Popover.Dropdown = Dropdown;

Expand Down

0 comments on commit a2cfd8a

Please sign in to comment.