Fix Gallery cleanup on Escape and keyboard nav
src/lib/Gallery.svelte opens a native <dialog> with showModal(). The browser closes it on Escape, but the
component only tears down its state in its own close(), which
is wired to backdrop clicks.
Current State
- No
onclose/oncancelhandler on the dialog: after Escape,dialogOpenstaystrue,selectedIndexkeeps its value, the observer and thescrolllistener are never removed, preload links stay in<head> - Because
dialogOpenis stuck, the thumbnail never gets itsview-transition-nameback; the next open animates from the wrong element - Prev/next buttons have
tabindex="-1"and there is nokeydownhandler, so arrow keys do nothing - The scroll-to-close listener fires on the layout shift caused by opening on some mobile browsers
Tasks
- Handle
oncancel(preventDefault, callclose()) or run the cleanup fromonclose - Add ArrowLeft/ArrowRight/Home/End handling on the dialog
- Make the nav buttons focusable and move focus back to the opening thumbnail on close
- Add a component test: open, press Escape, assert listeners and state are reset
Read next
