Let the theme be chosen by clicking its label in the profile menu
Clicking a theme option's text moved focus nowhere, and the focusout rule closed the panel before the radio was checked. The panel now closes only when focus moves to an element outside it; clicks outside and Escape still close it. Each theme option is a full-width row with a hover state, and the chosen one is also shown in bold. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -7,14 +7,15 @@
|
|||||||
The signed-in user's profile menu: a disclosure button (WAI-ARIA disclosure, not role="menu") that opens a panel
|
The signed-in user's profile menu: a disclosure button (WAI-ARIA disclosure, not role="menu") that opens a panel
|
||||||
with the language (kept on the account), the theme (kept on this device by tallstackui_darkTheme() on <html>,
|
with the language (kept on the account), the theme (kept on this device by tallstackui_darkTheme() on <html>,
|
||||||
whose "mode" the radios bind to) and logging out. Escape and a click outside close it, and so does moving focus
|
whose "mode" the radios bind to) and logging out. Escape and a click outside close it, and so does moving focus
|
||||||
out of it. The button's name stays the same; aria-expanded tells whether the panel is open.
|
out of it to another element (a click on a radio's label text moves focus nowhere, so it must not close the
|
||||||
|
panel). The button's name stays the same; aria-expanded tells whether the panel is open.
|
||||||
--}}
|
--}}
|
||||||
<div
|
<div
|
||||||
class="relative"
|
class="relative"
|
||||||
x-data="{ open: false }"
|
x-data="{ open: false }"
|
||||||
x-on:keydown.escape="if (open) { open = false; $refs.trigger.focus() }"
|
x-on:keydown.escape="if (open) { open = false; $refs.trigger.focus() }"
|
||||||
x-on:click.outside="open = false"
|
x-on:click.outside="open = false"
|
||||||
x-on:focusout="if (open && ! $el.contains($event.relatedTarget)) open = false"
|
x-on:focusout="if (open && $event.relatedTarget && ! $el.contains($event.relatedTarget)) open = false"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -76,7 +77,7 @@
|
|||||||
<legend class="mb-2 font-semibold">{{ __('layout.profile.theme') }}</legend>
|
<legend class="mb-2 font-semibold">{{ __('layout.profile.theme') }}</legend>
|
||||||
<div class="space-y-1">
|
<div class="space-y-1">
|
||||||
@foreach (['light' => 'theme_light', 'dark' => 'theme_dark', 'system' => 'theme_system'] as $mode => $label)
|
@foreach (['light' => 'theme_light', 'dark' => 'theme_dark', 'system' => 'theme_system'] as $mode => $label)
|
||||||
<label class="flex min-h-6 cursor-pointer items-center gap-2">
|
<label class="flex min-h-8 w-full cursor-pointer items-center gap-2 rounded-md px-2 py-1 hover:bg-zinc-700 has-checked:bg-zinc-700 has-checked:font-semibold">
|
||||||
<input
|
<input
|
||||||
type="radio"
|
type="radio"
|
||||||
name="profile-theme"
|
name="profile-theme"
|
||||||
|
|||||||
@@ -27,6 +27,16 @@ it('opens and closes the profile menu with the keyboard', function () {
|
|||||||
->assertScript('document.activeElement.hasAttribute("data-profile-menu")', true);
|
->assertScript('document.activeElement.hasAttribute("data-profile-menu")', true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('chooses the theme by clicking the text of an option', function () {
|
||||||
|
visit(route('customers.index'))->inLightMode()
|
||||||
|
->click(PROFILE_MENU)
|
||||||
|
->click('#profile-menu-panel label:has([data-theme-option="dark"])')
|
||||||
|
->assertScript('document.documentElement.classList.contains("dark")', true)
|
||||||
|
->assertChecked('[data-theme-option="dark"]')
|
||||||
|
->assertAttribute(PROFILE_MENU, 'aria-expanded', 'true')
|
||||||
|
->assertVisible('#profile-menu-panel');
|
||||||
|
});
|
||||||
|
|
||||||
it('changes the language from the profile menu', function () {
|
it('changes the language from the profile menu', function () {
|
||||||
$page = visit(route('customers.index'))->inLightMode()
|
$page = visit(route('customers.index'))->inLightMode()
|
||||||
->click(PROFILE_MENU)
|
->click(PROFILE_MENU)
|
||||||
|
|||||||
Reference in New Issue
Block a user