Skip to content

Commit

Permalink
fix(NcPopover): remove invalid aria-describedby
Browse files Browse the repository at this point in the history
Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
  • Loading branch information
ShGKme committed Feb 26, 2024
1 parent 2110ea1 commit 585a6a5
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions src/components/NcPopover/NcPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -280,23 +280,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][aria-haspopup]')
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')
}
},
/**
* @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 @@ -369,14 +389,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')
this.useFocusTrap()
this.addEscapeStopPropagation()
Expand Down

0 comments on commit 585a6a5

Please sign in to comment.