From 423124d0f89af54cf754e57ee84868b51263bd3a Mon Sep 17 00:00:00 2001 From: Guilhem Lemouel Date: Wed, 11 Nov 2026 08:45:07 -0800 Subject: [PATCH] fix: let the folder dialog's buttons and the grant navigator answer their own keys Co-Authored-By: Claude Opus 5.5 --- .../src/lib/components/AccessDrawer.svelte | 6 ++++-- .../src/lib/components/DrillPicker.svelte | 13 +++++++++++++ .../components/access/GrantNavigator.svelte | 19 +++++++++++++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/frontend/src/lib/components/AccessDrawer.svelte b/frontend/src/lib/components/AccessDrawer.svelte index 0c91dbf08d..7b2064c258 100644 --- a/frontend/src/lib/components/AccessDrawer.svelte +++ b/frontend/src/lib/components/AccessDrawer.svelte @@ -57,6 +57,7 @@ let openState: Record = $state({}) let expandAll: boolean | undefined = $state() let grantOpen = $state(false) + let navigator: GrantNavigator | undefined = $state() /** The row menu that is open, as `kind:path`. */ let openMenu: string | undefined = $state() let grantPopover: Popover | undefined = $state() @@ -308,12 +309,13 @@ + before either sees it. The navigator's own dialog or row dropdown closes first. --> { if (e.key !== 'Escape' || (!grantOpen && !openMenu)) return e.stopPropagation() e.preventDefault() + if (grantOpen && navigator?.escape(e.target)) return grantOpen = false openMenu = undefined }} @@ -380,7 +382,7 @@ {/snippet} {#snippet content()} {#if access} - + {/if} {/snippet} diff --git a/frontend/src/lib/components/DrillPicker.svelte b/frontend/src/lib/components/DrillPicker.svelte index 82a84436c2..e57c610fbb 100644 --- a/frontend/src/lib/components/DrillPicker.svelte +++ b/frontend/src/lib/components/DrillPicker.svelte @@ -553,6 +553,19 @@ leaves and ignores the current scope. const mainAction = $derived(highlightedActions.find((a) => a.preferred) ?? highlightedActions[0]) const otherActions = $derived(highlightedActions.filter((a) => a !== mainAction)) let actionMenuOpen = $state(false) + + /** Answers an Escape a host takes before the picker can: closes a row's dropdown, which hands + * focus back to its chevron, or leaves a row's button for the search field. False when neither + * applies, so the host closes instead. */ + export function escape(target: EventTarget | null): boolean { + if (actionMenuOpen) { + actionMenuOpen = false + return true + } + if (!(target as HTMLElement | null)?.closest?.('[data-drill-action]')) return false + focus() + return true + } let actionsWidth = $state(0) diff --git a/frontend/src/lib/components/access/GrantNavigator.svelte b/frontend/src/lib/components/access/GrantNavigator.svelte index 1010aed63e..2ca576ca9a 100644 --- a/frontend/src/lib/components/access/GrantNavigator.svelte +++ b/frontend/src/lib/components/access/GrantNavigator.svelte @@ -75,7 +75,9 @@ changes the grant on the whole folder. const data = $derived(source ?? api) const own = $derived(data.ownSpace) - let picker: { focus: () => void } | undefined = $state() + let picker: + | { focus: () => void; escape: (target: EventTarget | null) => boolean } + | undefined = $state() let folders: BrowseAccessFoldersResponse | undefined = $state() /** Rows by top-level branch (`u/alice`, `f/billing`), then by `kind:path`. */ let rows: Record> = $state({}) @@ -404,12 +406,25 @@ changes the grant on the whole folder. * the access drawer shows this list. */ function dialogKeys(e: KeyboardEvent) { if (!confirming || e.key === 'Tab') return - e.preventDefault() e.stopPropagation() + // A focused dialog button activates itself, so Enter on Cancel cancels. + const onButton = !!(e.target as HTMLElement | null)?.closest?.('button') + if (onButton && (e.key === 'Enter' || e.key === ' ')) return + e.preventDefault() if (e.key === 'Enter') confirmFolder() else if (e.key === 'Escape') cancelFolder() } + /** Answers an Escape a host takes before the navigator can: cancels the folder dialog, or + * passes it to the picker. False when nothing here was open, so the host closes instead. */ + export function escape(target: EventTarget | null): boolean { + if (confirming) { + cancelFolder() + return true + } + return !!picker?.escape(target) + } + let root: HTMLElement | undefined = $state() // The dialog covers this list rather than the page: a click on a dialog over the page lands // outside the drawer's popover, which closes it and the dialog with it.