Skip to content

Commit

Permalink
feat(PPDSC-2403): Extend role and aria-haspopup on Popover (#381)
Browse files Browse the repository at this point in the history
* feat(PPDSC-2403): added role in props

* feat(PPDSC-2403): removed unused code

* feat(PPDSC-2403): disable the default aria-haspopup

* feat(PPDSC-2403): linting fix

* feat(PPDSC-2403): unit test case error fix

* feat(PPDSC-2403): code patch fix

* feat(PPDSC-2403): test case

* feat(PPDSC-2403): simplified the condition

Co-authored-by: Ravindren <jravindren@NTS251819MC.local>
  • Loading branch information
jannuk59 and Ravindren authored Sep 28, 2022
1 parent 35bfd1c commit d14110d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
23 changes: 21 additions & 2 deletions src/popover/__tests__/popover.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,27 @@ describe('Popover', () => {
await applyAsyncStyling();
expect(el).toHaveAttribute('aria-describedby', `header-${MOCK_ID}`);
});
test('context element has aria-haspopup', () => {
const {queryByRole} = renderWithTheme(Popover, defaultProps);
test('context element has aria-haspopup as menu', () => {
const {queryByRole} = renderWithTheme(Popover, {
...defaultProps,
children: (
<button id="customId" aria-haspopup="menu" type="submit">
Add
</button>
),
});
const el = queryByRole('button');
expect(el).toHaveAttribute('aria-haspopup', 'menu');
});
test('aria-haspopup should have default value when aria-haspopup is not passed', () => {
const {queryByRole} = renderWithTheme(Popover, {
...defaultProps,
children: (
<button id="customId" type="submit">
Add
</button>
),
});
const el = queryByRole('button');
expect(el).toHaveAttribute('aria-haspopup', 'dialog');
});
Expand Down
13 changes: 6 additions & 7 deletions src/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ import {deepMerge} from '../utils';
import {mergeBreakpointObject} from '../utils/merge-breakpoint-object';
import {filterOutFalsyProperties} from '../utils/filter-object';

const buildContextAriaAttributes: BuildAriaAttributesFn = ({
floating: {id, open},
}) => ({
'aria-haspopup': 'dialog',
'aria-controls': open ? id : undefined,
});

const ThemelessPopover = React.forwardRef<HTMLDivElement, PopoverProps>(
(
{
Expand All @@ -47,6 +40,12 @@ const ThemelessPopover = React.forwardRef<HTMLDivElement, PopoverProps>(
},
ref,
) => {
const buildContextAriaAttributes: BuildAriaAttributesFn = ({
floating: {id, open},
}) => ({
'aria-haspopup': children.props['aria-haspopup'] || 'dialog',
'aria-controls': open ? id : undefined,
});
const theme = useTheme();
const closeButtonOverrides: typeof overrides['closeButton'] = {
...deepMerge(
Expand Down

0 comments on commit d14110d

Please sign in to comment.