Skip to content

Commit 55644fc

Browse files
authored
Merge pull request #5304 from nextcloud-libraries/fix/nc-popover--remove-aria-describedby
fix(NcPopover): remove invalid aria-describedby
2 parents 5795690 + f0628ca commit 55644fc

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

src/components/NcPopover/NcPopover.vue

+32-10
Original file line numberDiff line numberDiff line change
@@ -279,23 +279,43 @@ export default {
279279
*/
280280
checkTriggerA11y() {
281281
if (window.OC?.debug) {
282-
// TODO: Vue 3: should be
283-
// this.$refs.popover.$refs.popper.$refs.reference
284-
const triggerContainer = this.$refs.popover.$refs.reference
282+
const triggerContainer = this.getPopoverTriggerContainerElement()
285283
const requiredTriggerButton = triggerContainer.querySelector('[aria-expanded]')
286284
if (!requiredTriggerButton) {
287285
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.')
288286
}
289287
}
290288
},
291289

290+
/**
291+
* Remove incorrect aria-describedby attribute from the trigger.
292+
* @see https://github.com/Akryum/floating-vue/blob/8d4f7125aae0e3ea00ba4093d6d2001ab15058f1/packages/floating-vue/src/components/Popper.ts#L734
293+
*/
294+
removeFloatingVueAriaDescribedBy() {
295+
// When the popover is shown, floating-vue mutates the root elements of the trigger adding data-popper-shown and incorrect aria-describedby attributes.
296+
const triggerContainer = this.getPopoverTriggerContainerElement()
297+
const triggerElements = triggerContainer.querySelectorAll('[data-popper-shown]')
298+
for (const el of triggerElements) {
299+
el.removeAttribute('aria-describedby')
300+
}
301+
},
302+
292303
/**
293304
* @return {HTMLElement|undefined}
294305
*/
295306
getPopoverContentElement() {
296307
return this.$refs.popover?.$refs.popperContent?.$el
297308
},
298309

310+
/**
311+
* @return {HTMLElement|undefined}
312+
*/
313+
getPopoverTriggerContainerElement() {
314+
// TODO: Vue 3: should be
315+
// this.$refs.popover.$refs.popper.$refs.reference
316+
return this.$refs.popover.$refs.reference
317+
},
318+
299319
/**
300320
* Add focus trap for accessibility.
301321
*/
@@ -368,14 +388,16 @@ export default {
368388
},
369389

370390
afterShow() {
371-
/**
372-
* Triggered after the tooltip was visually displayed.
373-
*
374-
* This is different from the 'show' and 'apply-show' which
375-
* run earlier than this where there is no guarantee that the
376-
* tooltip is already visible and in the DOM.
377-
*/
391+
this.removeFloatingVueAriaDescribedBy()
392+
378393
this.$nextTick(() => {
394+
/**
395+
* Triggered after the tooltip was visually displayed.
396+
*
397+
* This is different from the 'show' and 'apply-show' which
398+
* run earlier than this where there is no guarantee that the
399+
* tooltip is already visible and in the DOM.
400+
*/
379401
this.$emit('after-show')
380402
this.useFocusTrap()
381403
this.addEscapeStopPropagation()

0 commit comments

Comments
 (0)