fix: portal dropdown surfaces and close the review capability gaps
- Root and submenu surfaces render through the dropdown portal with the overlay z-index, so clipping/isolation ancestors no longer cut the menu; panel height is capped by the floating available height and the animation origin maps the real transform origin. - Standalone Menu is a static in-flow list: no scroll lock, no outside pointer blocking, no floating placement and no focus stealing. - Selection ownership is isolated per level: section disabled keys add to the menu list, and a nested Menu resets the section owner. - closeOnSelect resolves item > menu policy > per-mode default for selection items; actions and radio items close, checkboxes stay open. - Business keys no longer become DOM ids (instance ids + data-key), and submenu surfaces label themselves from the real trigger. - Long-press keydown runs the caller's handlers first and only opens when not cancelled; submenu panels merge caller keydown with the internal Escape. - Link items render a real anchor, aria labels land on the role=menu node, submenu panels forward placement/offset/collision props and caller attrs, and the popover provides the default Surface variant. - Wrapper parts declare real props/emits, plus the missing official capability props (disallowEmptySelection, escapeKeyBehavior, shouldFocusWrap, autoFocus, shouldCloseOnSelect, close, empty slot, isKeyboardDismissDisabled, shouldCloseOnInteractOutside, placement/offset family, scoped slots). - Ship an independent consumer fixture for browser-level verification.
This commit is contained in:
@@ -17,6 +17,11 @@ const LONG_PRESS_MOVE_PX = 10;
|
||||
|
||||
const SELECTION_KEYS = new Set(["Enter", " ", "Spacebar"]);
|
||||
|
||||
type Handler =
|
||||
| ((event: KeyboardEvent) => void)
|
||||
| ((event: KeyboardEvent) => void)
|
||||
| undefined;
|
||||
|
||||
/**
|
||||
* Trigger. In `longPress` mode this component owns the press lifecycle and
|
||||
* cancels Reka's own click/keydown activation through its documented
|
||||
@@ -79,11 +84,37 @@ export default defineComponent({
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
function onKeydown(event: KeyboardEvent) {
|
||||
/**
|
||||
* Long-press keyboard activation. The base trigger toggles on keydown, so
|
||||
* for Enter/Space the caller's own keydown handlers run first (on the
|
||||
* capture phase of the trigger region, with native Vue array semantics),
|
||||
* then this component either cancels or opens exactly once while the base
|
||||
* trigger's toggle is suspended — a cancelled keydown never opens the menu.
|
||||
*/
|
||||
function suspendBaseToggle() {
|
||||
const ctx = dropdownCtx;
|
||||
if (!ctx) return;
|
||||
ctx.suppressOpenRequests.value = true;
|
||||
setTimeout(() => {
|
||||
ctx.suppressOpenRequests.value = false;
|
||||
}, 0);
|
||||
}
|
||||
function decideKeydown(event: KeyboardEvent) {
|
||||
if (!isLongPress()) return;
|
||||
if (!SELECTION_KEYS.has(event.key)) return;
|
||||
if (event.defaultPrevented) return;
|
||||
event.preventDefault();
|
||||
dropdownCtx?.setOpen(!(dropdownCtx?.open.value ?? false));
|
||||
const ctx = dropdownCtx;
|
||||
// Open first, then suspend: the base trigger toggles later in the same
|
||||
// event and must not undo this decision.
|
||||
ctx?.setOpen(!(ctx.open.value ?? false));
|
||||
suspendBaseToggle();
|
||||
}
|
||||
function keydownChain() {
|
||||
if (!isLongPress()) return undefined;
|
||||
const user = (attrs as { onKeydown?: Handler }).onKeydown;
|
||||
const userHandlers = Array.isArray(user) ? user : user ? [user] : [];
|
||||
return [...userHandlers, decideKeydown];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,15 +151,18 @@ export default defineComponent({
|
||||
onPointercancelCapture: clearPress,
|
||||
onPointerleaveCapture: clearPress,
|
||||
onClickCapture: onActivation,
|
||||
onKeydownCapture: onKeydown,
|
||||
onKeydownCapture: keydownChain(),
|
||||
onContextmenuCapture: clearPress,
|
||||
};
|
||||
|
||||
return () => {
|
||||
const longPress = isLongPress();
|
||||
const triggerAttrs: Record<string, unknown> = { ...attrs };
|
||||
if (longPress) delete triggerAttrs.onKeydown;
|
||||
const trigger = h(
|
||||
RekaDropdownMenuTrigger as never,
|
||||
{
|
||||
...attrs,
|
||||
...triggerAttrs,
|
||||
ref: triggerRef,
|
||||
as: props.as,
|
||||
asChild: props.asChild ?? true,
|
||||
@@ -137,10 +171,15 @@ export default defineComponent({
|
||||
}),
|
||||
"data-slot": "dropdown-trigger",
|
||||
},
|
||||
slots,
|
||||
{
|
||||
default: () =>
|
||||
slots.default?.({
|
||||
isOpen: dropdownCtx?.open.value ?? false,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
if (!isLongPress()) return trigger;
|
||||
if (!longPress) return trigger;
|
||||
|
||||
return h(
|
||||
"span",
|
||||
|
||||
Reference in New Issue
Block a user