Skip to content

Commit 4e6c382

Browse files
docs: keep drawer-toggle keyboard-focusable when drawer is open (#4608)
* keep drawer-toggle keyboard-focusable when drawer is open The `.drawer-open` modifier set the toggle checkbox to `display: none`, removing it from the keyboard tab order. For the responsive collapsible icon-only drawer — which stays open on large screens via `lg:drawer-open` and uses its button to toggle the sidebar *size* (icon-only <-> expanded) rather than open/close it — this made the toggle impossible to operate with the keyboard, while mouse users could still toggle it. Drop `@apply hidden` so the checkbox falls back to the base visually-hidden-but-focusable styling (`fixed h-0 w-0 opacity-0`). The always-open panel visibility is unchanged (it is driven by the `~ .drawer-side` sibling rules, not by the toggle's display), and keyboard users can now focus the toggle and get the focus outline forwarded to the `.drawer-button`. Docs: - add `drawer-button` to the icon-only example's toggle so the focus outline forwards to the visible button - add `lg:hidden` to the always-open example's input and to the docs site layout's toggle input, to avoid a phantom (invisible, no focus ring) tab stop at the lg breakpoint where the toggle button is already hidden - fix a `$$$$drawer-button` prefix-placeholder typo in two code samples Refs #4424 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * drawer: address review — keep core hidden, scope overrides to examples Per review, don't change the component for everyone: `.drawer-open > .drawer-toggle { @apply hidden }` is restored, and the exception is handled locally in the one example that needs it. - drawer.css: restore `@apply hidden` (revert the core change). - docs/components/drawer: navbar example (`my-drawer-2`) is the one with the real problem — it never uses `drawer-open`, so its toggle stayed focusable at `lg` with no visible control; add `lg:hidden` to it. - docs/components/drawer: always-visible example (`my-drawer-3`) doesn't need `lg:hidden` — the core `hidden` under `lg:drawer-open` already covers it; removed. - docs/components/drawer: icon-only example (`my-drawer-4`) is the exception — its button toggles the drawer size, so the toggle must stay focusable while `drawer-open`. Add `inline` to override the core `hidden` locally. - docs/+layout.svelte: revert the `lg:hidden` toggle. It only existed to compensate for the core change; the layout uses `lg:drawer-open` when a desktop sidebar exists, so the restored core `hidden` already handles it. Verified with a Tailwind build (daisyUI + utilities) in Chromium: | example | >= lg | < lg | |----------------------|----------------------|-----------------| | navbar + lg:hidden | none, not focusable | block, focusable| | always-visible | none, not focusable | block, focusable| | icon-only + inline | block, focusable | block, focusable| Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 374d637 commit 4e6c382

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

  • packages/docs/src/routes/(routes)/components/drawer

‎packages/docs/src/routes/(routes)/components/drawer/+page.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ You can check/uncheck the checkbox using JavaScript or by clicking the `label` t
8484
<input id="my-drawer-1" type="checkbox" class="$$drawer-toggle" />
8585
<div class="$$drawer-content">
8686
<!-- Page content here -->
87-
<label for="my-drawer-1" class="$$btn $$$$drawer-button">Open drawer</label>
87+
<label for="my-drawer-1" class="$$btn $$drawer-button">Open drawer</label>
8888
</div>
8989
<div class="$$drawer-side">
9090
<label for="my-drawer-1" aria-label="close sidebar" class="$$drawer-overlay"></label>
@@ -102,7 +102,7 @@ You can check/uncheck the checkbox using JavaScript or by clicking the `label` t
102102
#### Change screen size to show/hide menu
103103

104104
<div class="drawer h-56 rounded overflow-hidden">
105-
<input id="my-drawer-2" type="checkbox" autocomplete="off" class="drawer-toggle" />
105+
<input id="my-drawer-2" type="checkbox" autocomplete="off" class="drawer-toggle lg:hidden" />
106106
<div class="flex flex-col drawer-content">
107107
<div class="w-full navbar bg-base-300">
108108
<div class="flex-none lg:hidden">
@@ -131,7 +131,7 @@ You can check/uncheck the checkbox using JavaScript or by clicking the `label` t
131131

132132
```html
133133
<div class="$$drawer">
134-
<input id="my-drawer-2" type="checkbox" class="$$drawer-toggle" />
134+
<input id="my-drawer-2" type="checkbox" class="$$drawer-toggle lg:hidden" />
135135
<div class="$$drawer-content flex flex-col">
136136
<!-- Navbar -->
137137
<div class="$$navbar bg-base-300 w-full">
@@ -198,7 +198,7 @@ You can check/uncheck the checkbox using JavaScript or by clicking the `label` t
198198
<input id="my-drawer-3" type="checkbox" class="$$drawer-toggle" />
199199
<div class="$$drawer-content flex flex-col items-center justify-center">
200200
<!-- Page content here -->
201-
<label for="my-drawer-3" class="$$btn $$$$drawer-button lg:hidden">
201+
<label for="my-drawer-3" class="$$btn $$drawer-button lg:hidden">
202202
Open drawer
203203
</label>
204204
</div>
@@ -219,11 +219,11 @@ You can check/uncheck the checkbox using JavaScript or by clicking the `label` t
219219
#### In this example instead of completely hiding the drawer sidebar, we only show the icons when the drawer is closed. To add styles based on the state of the drawer, we use the `is-drawer-open` and `is-drawer-close` variants. For example `is-drawer-close:hidden` or `is-drawer-open:w-80`. Also we have tooltips when the drawer is closed and a switch button to open/close the drawer and rotates the button icon based on the state of the drawer.
220220

221221
<div class="drawer lg:drawer-open h-80">
222-
<input id="my-drawer-4" type="checkbox" autocomplete="off" class="drawer-toggle" />
222+
<input id="my-drawer-4" type="checkbox" autocomplete="off" class="drawer-toggle inline" />
223223
<div class="drawer-content">
224224
<!-- Navbar -->
225225
<nav class="navbar w-full bg-base-300">
226-
<label for="my-drawer-4" aria-label="open sidebar" class="btn btn-square btn-ghost">
226+
<label for="my-drawer-4" aria-label="open sidebar" class="btn btn-square btn-ghost drawer-button">
227227
<!-- Sidebar toggle icon -->
228228
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke-linejoin="round" stroke-linecap="round" stroke-width="2" fill="none" stroke="currentColor" class="my-1.5 inline-block size-4"><path d="M4 4m0 2a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2z"></path><path d="M9 4v16"></path><path d="M14 10l2 2l-2 2"></path></svg>
229229
</label>
@@ -260,11 +260,11 @@ You can check/uncheck the checkbox using JavaScript or by clicking the `label` t
260260

261261
```html
262262
<div class="$$drawer lg:$$drawer-open">
263-
<input id="my-drawer-4" type="checkbox" class="$$drawer-toggle" />
263+
<input id="my-drawer-4" type="checkbox" class="$$drawer-toggle inline" />
264264
<div class="$$drawer-content">
265265
<!-- Navbar -->
266266
<nav class="$$navbar w-full bg-base-300">
267-
<label for="my-drawer-4" aria-label="open sidebar" class="$$btn $$btn-square $$btn-ghost">
267+
<label for="my-drawer-4" aria-label="open sidebar" class="$$btn $$btn-square $$btn-ghost $$drawer-button">
268268
<!-- Sidebar toggle icon -->
269269
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke-linejoin="round" stroke-linecap="round" stroke-width="2" fill="none" stroke="currentColor" class="my-1.5 inline-block size-4"><path d="M4 4m0 2a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2z"></path><path d="M9 4v16"></path><path d="M14 10l2 2l-2 2"></path></svg>
270270
</label>

0 commit comments

Comments
 (0)