fix: complete submenu panel ARIA, focus and event passthrough
- Submenu panel name priority is explicit aria-label > menu content channel > this instance's trigger; an explicit label drops the id reference so it cannot be shadowed. - openAutoFocus and animationend chain with the caller's handlers like keydown and interact-outside, so caller callbacks run and can cancel. - The panel loop falls back to the menu-level shouldFocusWrap and is always passed as a boolean: an undefined -> true update is dropped by the base prop chain, so the menu policy never applied. - Add a jsdom CSSOM polyfill for CSS.escape via vitest setupFiles; the animationend test no longer raises an unhandled error.
This commit is contained in:
@@ -219,7 +219,9 @@ export default defineComponent({
|
||||
avoidCollisions: props.avoidCollisions ?? props.shouldFlip,
|
||||
collisionPadding:
|
||||
props.collisionPadding ?? props.containerPadding,
|
||||
loop: props.loop ?? contentAttrs?.loop.value,
|
||||
// Boolean on purpose: undefined -> true updates are dropped by
|
||||
// the base prop chain.
|
||||
loop: props.loop ?? contentAttrs?.loop.value ?? false,
|
||||
onAnimationend: chain<AnimationEvent>(
|
||||
"onAnimationend",
|
||||
onAnimationEnd,
|
||||
|
||||
@@ -137,19 +137,28 @@ export default defineComponent({
|
||||
shouldCloseOutside?: (event: Event) => boolean;
|
||||
} = { dismissDisabled: false };
|
||||
|
||||
// Accessible-name decision for the current render; the repair pass reads it.
|
||||
const panelAria: { label?: string; labelledBy?: string } = {};
|
||||
|
||||
/**
|
||||
* Reka labels the submenu surface with the id it generates for its own
|
||||
* trigger, but our trigger item keeps an instance id, so that reference
|
||||
* dangles. Point it at the real trigger element of this instance.
|
||||
* dangles. Priority: explicit aria-label (wins over any id reference) >
|
||||
* caller/Menu `aria-labelledby` > this instance's trigger element.
|
||||
*/
|
||||
function repairLabel(explicit?: string) {
|
||||
function repairLabel() {
|
||||
const content = contentElement.value;
|
||||
const trigger = elementFromValue(triggerRef.value);
|
||||
if (!content || !trigger) return;
|
||||
if (explicit) {
|
||||
content.setAttribute("aria-labelledby", explicit);
|
||||
if (!content) return;
|
||||
if (panelAria.label) {
|
||||
content.removeAttribute("aria-labelledby");
|
||||
return;
|
||||
}
|
||||
if (panelAria.labelledBy) {
|
||||
content.setAttribute("aria-labelledby", panelAria.labelledBy);
|
||||
return;
|
||||
}
|
||||
const trigger = elementFromValue(triggerRef.value);
|
||||
if (!trigger) return;
|
||||
if (!trigger.id) trigger.id = fallbackId;
|
||||
content.setAttribute("aria-labelledby", trigger.id);
|
||||
}
|
||||
@@ -240,7 +249,12 @@ export default defineComponent({
|
||||
collisionPadding:
|
||||
(popoverProps.collisionPadding as number | undefined) ??
|
||||
(popoverProps.containerPadding as number | undefined),
|
||||
loop: popoverProps.loop as boolean | undefined,
|
||||
// Always a boolean: an undefined -> true transition is dropped by the
|
||||
// base prop chain, so the menu-level policy would never apply.
|
||||
loop:
|
||||
(popoverProps.loop as boolean | undefined) ??
|
||||
contentAttrs.loop.value ??
|
||||
false,
|
||||
};
|
||||
const side = (popoverProps.side as string | undefined) ?? position.side;
|
||||
const align =
|
||||
@@ -255,7 +269,40 @@ export default defineComponent({
|
||||
...asArray(popoverProps.onInteractOutside as Handler),
|
||||
handleInteractOutside as (event: Event) => void,
|
||||
];
|
||||
const labelledBy = contentAttrs.labelledBy.value;
|
||||
const focusChain = [
|
||||
...asArray(popoverProps.onOpenAutoFocus as Handler),
|
||||
(event: Event) => {
|
||||
if (event.defaultPrevented) return;
|
||||
if (contentAttrs.autoFocus.value === false) event.preventDefault();
|
||||
},
|
||||
];
|
||||
const animationChain = [
|
||||
...asArray(popoverProps.onAnimationend as Handler),
|
||||
onAnimationEnd as (event: Event) => void,
|
||||
];
|
||||
|
||||
// Explicit caller values win over the Menu content channel; a label
|
||||
// always beats an id reference so it cannot be shadowed silently.
|
||||
const callerLabel = popoverProps["aria-label"] as string | undefined;
|
||||
const callerLabelledBy = popoverProps["aria-labelledby"] as
|
||||
string | undefined;
|
||||
const callerDescribedBy = popoverProps["aria-describedby"] as
|
||||
string | undefined;
|
||||
const effectiveLabel = callerLabel ?? contentAttrs.label.value;
|
||||
const effectiveLabelledBy =
|
||||
callerLabelledBy ?? contentAttrs.labelledBy.value;
|
||||
const describedBy = callerDescribedBy ?? contentAttrs.describedBy.value;
|
||||
panelAria.label = effectiveLabel;
|
||||
panelAria.labelledBy = effectiveLabelledBy;
|
||||
const ariaProps: Record<string, unknown> = {};
|
||||
if (effectiveLabel) {
|
||||
ariaProps["aria-label"] = effectiveLabel;
|
||||
// An id reference would win over the explicit label; drop it.
|
||||
ariaProps["aria-labelledby"] = undefined;
|
||||
} else if (effectiveLabelledBy) {
|
||||
ariaProps["aria-labelledby"] = effectiveLabelledBy;
|
||||
}
|
||||
if (describedBy) ariaProps["aria-describedby"] = describedBy;
|
||||
|
||||
return h(
|
||||
RekaDropdownMenuSub as never,
|
||||
@@ -302,8 +349,7 @@ export default defineComponent({
|
||||
...panelProps,
|
||||
side,
|
||||
align,
|
||||
"aria-label": contentAttrs.label.value,
|
||||
"aria-describedby": contentAttrs.describedBy.value,
|
||||
...ariaProps,
|
||||
class: [
|
||||
dropdownCtx?.slots.value.popover(),
|
||||
popoverProps.class,
|
||||
@@ -314,21 +360,17 @@ export default defineComponent({
|
||||
"data-exiting": exiting.value || undefined,
|
||||
onKeydown: keydownChain,
|
||||
onInteractOutside: interactChain,
|
||||
onAnimationend: onAnimationEnd,
|
||||
onOpenAutoFocus: (event: Event) => {
|
||||
if (event.defaultPrevented) return;
|
||||
if (contentAttrs.autoFocus.value === false)
|
||||
event.preventDefault();
|
||||
},
|
||||
onAnimationend: animationChain,
|
||||
onOpenAutoFocus: focusChain,
|
||||
onVnodeMounted: (vnode) => {
|
||||
contentElement.value = menuSurfaceFromVNode(vnode);
|
||||
void nextTick(() => repairLabel(labelledBy));
|
||||
void nextTick(repairLabel);
|
||||
},
|
||||
onVnodeUpdated: (vnode) => {
|
||||
const element = menuSurfaceFromVNode(vnode);
|
||||
if (!element) return;
|
||||
contentElement.value = element;
|
||||
void nextTick(() => repairLabel(labelledBy));
|
||||
void nextTick(repairLabel);
|
||||
},
|
||||
onVnodeUnmounted: () => {
|
||||
contentElement.value = null;
|
||||
|
||||
Reference in New Issue
Block a user