{% comment %}
left-1/2 stays physical: with -translate-x-1/2 it centres the menu, and the
centre is the same in either direction.
{% endcomment %}
item.closest('[role=menu]') === $el); const at = items.indexOf(document.activeElement); const closer = getComputedStyle($el).direction === 'rtl' ? 'ArrowRight' : 'ArrowLeft'; let next = null; if ($event.key === 'ArrowDown') next = items[(at + 1) % items.length]; else if ($event.key === 'ArrowUp') next = items[(at < 0 ? items.length : at) - 1 + (at === 0 ? items.length : 0)]; else if ($event.key === 'Home') next = items[0]; else if ($event.key === 'End') next = items.at(-1); else if (($event.key === 'Enter' || $event.key === ' ') && at >= 0) { $event.preventDefault(); $event.stopPropagation(); items[at].click(); } else if ($event.key === closer && $el.matches('[data-slot$=sub-content]')) { $event.preventDefault(); $event.stopPropagation(); subOpen = false; $el.parentElement.querySelector('[aria-haspopup=menu]')?.focus(); } else if ($event.key.length === 1 && !$event.ctrlKey && !$event.metaKey && !$event.altKey) next = [...items.slice(at + 1), ...items.slice(0, at + 1)].find(item => item.textContent.trim().toLowerCase().startsWith($event.key.toLowerCase())); if (next) { $event.preventDefault(); $event.stopPropagation(); next.focus(); }"
x-init="$watch('open', shown => shown ? $nextTick(() => ((viaKeyboard && $el.querySelector('[role^=menuitem]:not([data-disabled])')) || $el).focus()) : $el.contains(document.activeElement) && $root.querySelector('[data-slot=dropdown-menu-trigger]').querySelector('button, a[href], [tabindex]')?.focus())"
@focusout="$root.contains($event.relatedTarget) || (open = false)" class="
absolute top-full z-50 mt-1 min-w-[8rem] rounded-md border bg-popover p-1
text-popover-foreground shadow-md
{% if align == 'start' %}start-0
{% elif align == 'center' %}left-1/2 -translate-x-1/2
{% elif align == 'end' %}end-0
{% endif %}
{% if class %}
{{ class }}
{% endif %}
" data-slot="dropdown-menu-content" data-align="{{ align }}" {{ attrs }}>
{{ slot }}