From 1e55d46bc0c710730069509eaf04a39cacab1ce3 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Sat, 26 Oct 2019 23:53:13 +0100 Subject: [PATCH] Add Key handling to modal example This is a basic accessibility requirement for key access --- .../15-composition/04-modal/Modal.svelte | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/site/content/examples/15-composition/04-modal/Modal.svelte b/site/content/examples/15-composition/04-modal/Modal.svelte index 5ffa5989a4..8ddaf55921 100644 --- a/site/content/examples/15-composition/04-modal/Modal.svelte +++ b/site/content/examples/15-composition/04-modal/Modal.svelte @@ -2,7 +2,23 @@ import { createEventDispatcher } from 'svelte'; const dispatch = createEventDispatcher(); - + + const handleClose = () => dispatch('close') + + function handleKeydown(event) { + if (event.key == 'Escape') { + handleClose() + } else if (event.key == 'Tab') { + event.preventDefault() + } + } + + let closeButton + onMount(() => { + closeButton.focus() + }) + + - +