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

feat(PPDSC-2403): Extend role and aria-haspopup on Popover #381

Merged

Conversation

jannuk59
Copy link
Contributor

@jannuk59 jannuk59 commented Sep 20, 2022

PPDSC-2403

  • Extended the role and aria-haspopup on the popover component.
    Example:
<Popover content="..." role="menu">
  <IconButton aria-haspopup="true" />
</Popover>
  • By default the role and aria-haspopup is to 'dialog'

I have done:

  • Written unit tests against changes
  • Written functional tests against the component and/or NewsKit site
  • Updated relevant documentation

I have tested manually:

  • The feature's functionality is working as expected on Chrome, Firefox, Safari and Edge
  • The screen reader reads and flows through the elements as expected.
  • There are no new errors in the browser console coming from this PR.
  • When visual test is not added, it renders correctly on different browsers and mobile viewports (Safari, Firefox, small mobile viewport, tablet)
  • The Playground feature is working as expected

Before:

After:

Who should review this PR:

How to test:

@github-actions github-actions bot added the feature This change contains a new feature label Sep 20, 2022
@@ -122,7 +123,7 @@ const ThemelessPopover = React.forwardRef<HTMLDivElement, PopoverProps>(
buildRefElAriaAttributes={buildContextAriaAttributes}
buildFloatingElAriaAttributes={buildFloatingElementAriaAttributes}
useInteractions={useInteractions}
role="dialog"
role={role}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the description of the ticket might be misleading.
you don't need to change this, people can pass a role on the popover and this will be overridden.

For example, I just did that with a passing banner:
Screenshot 2022-09-21 at 9 12 41

@@ -28,7 +28,7 @@ import {filterOutFalsyProperties} from '../utils/filter-object';
const buildContextAriaAttributes: BuildAriaAttributesFn = ({
floating: {id, open},
}) => ({
'aria-haspopup': 'dialog',
// 'aria-haspopup': 'dialog',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to remove that, this should stay as the default behaviour.

but we need to check if people provide they aria-haspopup and if so we don't apply it automatically.

For example:

<Popover content="..." role="menu">
  <IconButton aria-haspopup="true" />
</Popover>

That logic should happen in base-floating-element.tsx file, at the point you are cloning the children you can check if the children have already aria-popup

@jannuk59 jannuk59 changed the title Feat/ppdsc 2403 extend role and aria haspopup on popover feat(PPDSC-2403): Extend role and aria-haspopup on Popover Sep 21, 2022
@@ -27,8 +27,9 @@ import {filterOutFalsyProperties} from '../utils/filter-object';

const buildContextAriaAttributes: BuildAriaAttributesFn = ({
floating: {id, open},
ariaHasPopup,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to pass this down and then back up again. The purpose of BuildAriaAttributesFn is to expose data from the BaseFloatingElement that the Popover can't access. But the Popover has access to children.props.

Can we simply move buildContextAriaAttributes inside the component and change it to:

const buildContextAriaAttributes: BuildAriaAttributesFn = ({
  floating: {id, open}
}) => ({
  'aria-haspopup': children.props['aria-haspopup'] || 'dialog',
  'aria-controls': open ? id : undefined,
});

I think this would achieve the same result without any changes to the base component.

What do you think?

@jannuk59 jannuk59 merged commit d14110d into main Sep 28, 2022
@jannuk59 jannuk59 deleted the feat/PPDSC-2403-extend-role-and-aria-haspopup-on-popover branch September 28, 2022 06:47
Xin00163 pushed a commit that referenced this pull request Oct 17, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This change contains a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants