fix: let the folder dialog's buttons and the grant navigator answer their own keys

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Guilhem Lemouel
2026-11-11 08:45:07 -08:00
co-authored by Claude Opus 5.5
parent 303cbc71f9
commit 423124d0f8
3 changed files with 34 additions and 4 deletions
@@ -57,6 +57,7 @@
let openState: Record<string, boolean> = $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 @@
<!-- The drawer answers Escape on window too, and `preventEscape` is read after a popover or menu
has already closed, so with the Grant popover or a row menu open its Escape is taken here
before either sees it. -->
before either sees it. The navigator's own dialog or row dropdown closes first. -->
<svelte:window
onkeydowncapture={(e) => {
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}
<GrantNavigator {principal} {access} onChange={reload} />
<GrantNavigator bind:this={navigator} {principal} {access} onChange={reload} />
{/if}
{/snippet}
</Popover>
@@ -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)
</script>
@@ -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<string, Record<string, Row>> = $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.