Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a11y improvements for template to-do list #1207

Merged
merged 6 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lovely-apricots-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-svelte': patch
---

Improve a11y on to-do list in template
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script context="module" lang="ts">
import { tick } from 'svelte';
import { enhance } from '$lib/form';
import type { Load } from '@sveltejs/kit';

Expand Down Expand Up @@ -43,6 +44,21 @@
return t;
});
}

let addInput;
let todoInputs = [];
async function manageFocus(i) {
await tick();
const nextInput = todoInputs[i + 1];
const previousInput = todoInputs[i - 1];
if (nextInput) {
nextInput.focus();
} else if (previousInput) {
previousInput.focus();
} else {
addInput.focus();
}
}
</script>

<svelte:head>
Expand All @@ -60,10 +76,10 @@
form.reset();
}
}}>
<input name="text" placeholder="+ tap to add a todo">
<input name="text" aria-label="Add todo" placeholder="+ tap to add a todo" bind:this={addInput}>
</form>

{#each todos as todo (todo.uid)}
{#each todos as todo, i (todo.uid)}
<div class="todo" class:done={todo.done} transition:scale|local={{start:0.7}} animate:flip={{duration:200}}>
<form action="/todos/{todo.uid}.json?_method=patch" method="post" use:enhance={{
pending: (data) => {
Expand All @@ -78,12 +94,13 @@
<form class="text" action="/todos/{todo.uid}.json?_method=patch" method="post" use:enhance={{
result: patch
}}>
<input type="text" name="text" value={todo.text}>
<input aria-label="Edit todo" type="text" name="text" value={todo.text} bind:this={todoInputs[i]}>
<button class="save" aria-label="Save todo"/>
</form>

<form action="/todos/{todo.uid}.json?_method=delete" method="post" use:enhance={{
result: () => {
result: async () => {
await manageFocus(i);
geoffrich marked this conversation as resolved.
Show resolved Hide resolved
todos = todos.filter(t => t.uid !== todo.uid);
}
}}>
Expand Down Expand Up @@ -184,7 +201,8 @@
opacity: 0.2;
}

.delete:hover {
.delete:hover,
.delete:focus {
transition: opacity 0.2s;
opacity: 1;
}
Expand All @@ -196,7 +214,8 @@
background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20.5 2H3.5C2.67158 2 2 2.67157 2 3.5V20.5C2 21.3284 2.67158 22 3.5 22H20.5C21.3284 22 22 21.3284 22 20.5V3.5C22 2.67157 21.3284 2 20.5 2Z' fill='%23676778' stroke='%23676778' stroke-width='1.5' stroke-linejoin='round'/%3E%3Cpath d='M17 2V11H7.5V2H17Z' fill='white' stroke='white' stroke-width='1.5' stroke-linejoin='round'/%3E%3Cpath d='M13.5 5.5V7.5' stroke='%23676778' stroke-width='1.5' stroke-linecap='round'/%3E%3Cpath d='M5.99844 2H18.4992' stroke='%23676778' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E%0A");
}

.todo input:focus + .save {
.todo input:focus + .save,
.save:focus {
transition: opacity 0.2s;
opacity: 1;
}
Expand Down