Add Key handling to modal example

This is a basic accessibility requirement for key access
pull/3799/head
Steve Lee 5 years ago committed by GitHub
parent b8107e7fa7
commit 1e55d46bc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,7 +2,23 @@
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
</script>
const handleClose = () => dispatch('close')
function handleKeydown(event) {
if (event.key == 'Escape') {
handleClose()
} else if (event.key == 'Tab') {
event.preventDefault()
}
}
let closeButton
onMount(() => {
closeButton.focus()
})
</cript>
<style>
.modal-background {
@ -16,8 +32,7 @@
.modal {
position: absolute;
left: 50%;
top: 50%;
left: 50%; top: 50%;
width: calc(100vw - 4em);
max-width: 32em;
max-height: calc(100vh - 4em);
@ -33,7 +48,7 @@
}
</style>
<div class='modal-background' on:click='{() => dispatch("close")}'></div>
<div class='modal-background' on:click='{handleClose}'></div>
<div class='modal'>
<slot name='header'></slot>
@ -41,5 +56,5 @@
<slot></slot>
<hr>
<button on:click='{() => dispatch("close")}'>close modal</button>
<button on:click='{() => dispatch("close")}' bind:this={closeButton}>close modal</button>
</div>

Loading…
Cancel
Save