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(NcPopover): remove invalid aria-describedby #5304

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 32 additions & 10 deletions src/components/NcPopover/NcPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -279,23 +279,43 @@ export default {
*/
checkTriggerA11y() {
if (window.OC?.debug) {
// TODO: Vue 3: should be
// this.$refs.popover.$refs.popper.$refs.reference
const triggerContainer = this.$refs.popover.$refs.reference
const triggerContainer = this.getPopoverTriggerContainerElement()
const requiredTriggerButton = triggerContainer.querySelector('[aria-expanded]')
if (!requiredTriggerButton) {
Vue.util.warn('It looks like you are using a custom button as a <NcPopover> or other popover #trigger. If you are not using <NcButton> as a trigger, you need to bind attrs from the #trigger slot props to your custom button. See <NcPopover> docs for an example.')
}
}
},

/**
* Remove incorrect aria-describedby attribute from the trigger.
* @see https://github.com/Akryum/floating-vue/blob/8d4f7125aae0e3ea00ba4093d6d2001ab15058f1/packages/floating-vue/src/components/Popper.ts#L734
*/
removeFloatingVueAriaDescribedBy() {
// When the popover is shown, floating-vue mutates the root elements of the trigger adding data-popper-shown and incorrect aria-describedby attributes.
const triggerContainer = this.getPopoverTriggerContainerElement()
const triggerElements = triggerContainer.querySelectorAll('[data-popper-shown]')
for (const el of triggerElements) {
el.removeAttribute('aria-describedby')
}
Comment on lines +297 to +300
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In Vue 2 triggerElements is always only one root element, but in Vue 3 there could be multiple nodes. Using querySelectorAll for Vue 3 compatibility.

},

/**
* @return {HTMLElement|undefined}
*/
getPopoverContentElement() {
return this.$refs.popover?.$refs.popperContent?.$el
},

/**
* @return {HTMLElement|undefined}
*/
getPopoverTriggerContainerElement() {
// TODO: Vue 3: should be
// this.$refs.popover.$refs.popper.$refs.reference
return this.$refs.popover.$refs.reference
},

/**
* Add focus trap for accessibility.
*/
Expand Down Expand Up @@ -368,14 +388,16 @@ export default {
},

afterShow() {
/**
* Triggered after the tooltip was visually displayed.
*
* This is different from the 'show' and 'apply-show' which
* run earlier than this where there is no guarantee that the
* tooltip is already visible and in the DOM.
*/
this.removeFloatingVueAriaDescribedBy()

this.$nextTick(() => {
/**
* Triggered after the tooltip was visually displayed.
*
* This is different from the 'show' and 'apply-show' which
* run earlier than this where there is no guarantee that the
* tooltip is already visible and in the DOM.
*/
this.$emit('after-show')
Comment on lines +394 to 401
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the comment so it works as event documentation for styleguidist.

this.useFocusTrap()
this.addEscapeStopPropagation()
Expand Down