Skip to content

Commit 5454229

Browse files
committed
Fixed keyboard accessibility of dropdowns.
1 parent 01fad87 commit 5454229

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Dates should be in`YYYY-MM-DD` format and versions are in [semantic versioning](
99

1010
- Replaced how delete button with confirm button, to prevent data loss.
1111
- Fixed incorrect next date in periods computations. All off by one.
12+
- Fixed keyboard accessibility of dropdowns.
1213

1314
## v0.7.12 2025-02-18
1415

src/lib/Button.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
end?: boolean;
1414
chromeless?: boolean;
1515
children?: import('svelte').Snippet;
16+
onkeydown?: (event: KeyboardEvent) => void;
1617
}
1718
1819
let {
@@ -23,7 +24,8 @@
2324
warning = false,
2425
end = false,
2526
chromeless = false,
26-
children
27+
children,
28+
onkeydown
2729
}: Props = $props();
2830
2931
let confirm = $state(false);
@@ -34,6 +36,7 @@
3436
<button onclick={() => (confirm = false)}>{Delete}</button><button
3537
type={submit ? 'submit' : null}
3638
class:warning
39+
{onkeydown}
3740
onclick={action}>{Confirm}</button
3841
>
3942
</div>
@@ -46,6 +49,7 @@
4649
aria-disabled={!active}
4750
title={tip}
4851
aria-label={tip}
52+
{onkeydown}
4953
onclick={(event) => {
5054
if (warning) confirm = true;
5155
else if (active) {

src/lib/Options.svelte

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,41 +52,49 @@
5252
5353
function handleKey(event: KeyboardEvent, option: string | undefined) {
5454
if (!(event.currentTarget instanceof HTMLElement)) return;
55+
const isOption = event.currentTarget.classList.contains('option');
5556
switch (event.key) {
5657
case 'Enter':
57-
if (event.currentTarget === dropdown) {
58+
if (!isOption) {
5859
expanded = !expanded;
5960
event.stopPropagation();
6061
} else {
6162
choose(option);
6263
event.stopPropagation();
6364
event.preventDefault();
65+
dropdown?.focus();
6466
break;
6567
}
6668
case 'ArrowDown':
67-
if (event.currentTarget === search || event.currentTarget === dropdown) {
69+
if (!isOption) {
6870
if (list?.firstElementChild instanceof HTMLElement) {
6971
expanded = true;
7072
list.firstElementChild.focus();
73+
event.stopPropagation();
74+
event.preventDefault();
7175
}
72-
} else if (event.currentTarget.parentElement === list) {
76+
} else {
7377
const next = event.currentTarget.nextElementSibling;
7478
if (next instanceof HTMLElement) next.focus();
79+
event.stopPropagation();
80+
event.preventDefault();
7581
}
76-
event.stopPropagation();
77-
event.preventDefault();
7882
break;
7983
case 'ArrowUp':
80-
if (event.currentTarget.parentElement === list) {
84+
if (isOption) {
8185
const prev = event.currentTarget.previousElementSibling;
8286
if (prev instanceof HTMLElement) prev.focus();
8387
else search !== undefined ? search?.focus() : dropdown?.focus();
88+
event.stopPropagation();
89+
event.preventDefault();
8490
}
85-
event.stopPropagation();
86-
event.preventDefault();
8791
break;
8892
case 'Escape':
8993
expanded = false;
94+
dropdown?.focus();
95+
event.stopPropagation();
96+
event.preventDefault();
97+
break;
9098
}
9199
}
92100
</script>
@@ -144,6 +152,7 @@
144152
<Button
145153
chromeless
146154
tip="search"
155+
onkeydown={(event) => handleKey(event, undefined)}
147156
action={() => {
148157
searching = !searching;
149158
tick().then(() => search?.focus());
@@ -154,6 +163,7 @@
154163
chromeless
155164
{tip}
156165
{active}
166+
onkeydown={(event) => handleKey(event, undefined)}
157167
action={() => {
158168
expanded = !expanded;
159169
}}

src/routes/org/[orgid]/process/[processid]/+page.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@
149149
{#snippet concernView(value: string | undefined)}
150150
{#if value}
151151
<Concern concern={value} />
152+
{:else}
153+
&mdash;
152154
{/if}
153155
{/snippet}
154156

0 commit comments

Comments
 (0)