Collection::join() plucks from objects, so joining the Js arguments gave an empty string and the sort and urgent threshold menus called setColumnSort() / setUrgentThreshold() with no arguments (500). Co-Authored-By: Claude Opus 5.5 <[email protected]>
60 lines
3.0 KiB
PHP
60 lines
3.0 KiB
PHP
{{--
|
|
A small header button that opens a list of choices (menuitemradio):
|
|
the urgent threshold and a column's order. Escape and a click outside
|
|
close it; focus returns to the button.
|
|
|
|
Props: `label` (the button's name), `heading`, `options` (value => text),
|
|
`current` (value), `method` and `args` (the Livewire call, with the
|
|
chosen value last), `active` (highlights the button).
|
|
--}}
|
|
@props(['id', 'label', 'heading', 'options', 'current', 'method', 'args' => [], 'active' => false])
|
|
|
|
<div class="relative" x-data="{ open: false }" x-on:keydown.escape.stop="if (open) { open = false; $refs.button.focus(); }" x-on:click.outside="open = false">
|
|
<button
|
|
type="button"
|
|
x-ref="button"
|
|
x-on:click="open = ! open; if (open) { $nextTick(() => $refs.menu.querySelector('[aria-checked=true]')?.focus()) }"
|
|
x-bind:aria-expanded="open.toString()"
|
|
aria-haspopup="menu"
|
|
aria-controls="{{ $id }}"
|
|
aria-label="{{ $label }}"
|
|
title="{{ $label }}"
|
|
@class([
|
|
'inline-flex size-6 items-center justify-center rounded transition focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-current',
|
|
'bg-black/20 ring-1 ring-current/40 dark:bg-white/25' => $active,
|
|
'hover:bg-black/15 dark:hover:bg-white/15' => ! $active,
|
|
])
|
|
>
|
|
{{ $slot }}
|
|
</button>
|
|
|
|
<div
|
|
id="{{ $id }}"
|
|
x-ref="menu"
|
|
x-show="open"
|
|
x-cloak
|
|
role="menu"
|
|
aria-label="{{ $heading }}"
|
|
class="absolute top-8 right-0 z-50 w-56 space-y-0.5 rounded-xl border border-neutral-300 bg-white p-1.5 text-neutral-900 shadow-2xl dark:border-[#3e4249] dark:bg-[#282a2e] dark:text-neutral-100"
|
|
>
|
|
<div class="px-2 py-1 text-[10px] font-bold tracking-wider text-neutral-600 uppercase dark:text-neutral-300" aria-hidden="true">{{ $heading }}</div>
|
|
@foreach ($options as $value => $text)
|
|
<button
|
|
type="button"
|
|
role="menuitemradio"
|
|
aria-checked="{{ $value === $current ? 'true' : 'false' }}"
|
|
wire:click="{{ $method }}({{ collect([...$args, $value])->map(fn ($arg): string => Js::from($arg)->toHtml())->implode(', ') }})"
|
|
x-on:click="open = false; $refs.button.focus()"
|
|
x-on:keydown.arrow-down.prevent="$el.nextElementSibling?.focus()"
|
|
x-on:keydown.arrow-up.prevent="$el.previousElementSibling?.matches('button') && $el.previousElementSibling.focus()"
|
|
class="flex w-full items-center justify-between rounded-lg px-2.5 py-1.5 text-left text-xs font-medium transition hover:bg-neutral-100 focus-visible:outline-2 focus-visible:outline-primary-600 dark:hover:bg-[#34373d] dark:focus-visible:outline-primary-300"
|
|
>
|
|
<span>{{ $text }}</span>
|
|
@if ($value === $current)
|
|
<x-icon name="check" class="size-4 text-primary-700 dark:text-primary-200" aria-hidden="true" />
|
|
@endif
|
|
</button>
|
|
@endforeach
|
|
</div>
|
|
</div>
|