Skip to content

Commit

Permalink
update: allow focus on labels to trigger enter hit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ItzNotABug committed Jan 29, 2025
1 parent a72a538 commit 242c9bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/lib/components/regionCard.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<script lang="ts">
import { onMount } from 'svelte';
export let name: string;
export let group: string;
export let value: string | number | boolean;
export let disabled = false;
export let padding = 1;
export let autofocus = false;
export let fullHeight = true;
export let borderRadius: 'xsmall' | 'small' | 'medium' | 'large' = 'small';
Expand All @@ -13,9 +16,18 @@
medium = '--border-radius-medium',
large = '--border-radius-large'
}
let labelReference: HTMLLabelElement | null = null;
onMount(() => {
if (autofocus) {
labelReference?.focus();
}
});
</script>

<label
bind:this={labelReference}
class="box u-cursor-pointer u-flex u-flex-vertical u-gap-16"
class:is-allow-focus={!disabled}
class:is-disabled={disabled}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@
return 1;
}
return -1;
}) as region}
}) as region, index}
<li>
<RegionCard
name="region"
bind:group={$createProject.region}
value={region.$id}
disabled={region.disabled}>
disabled={region.disabled}
autofocus={index === 0}>
<!-- focus first item so enter key works! -->
<div
class="u-flex u-flex-vertical u-gap-8 u-justify-main-center u-cross-center u-margin-inline-auto">
{#if region.disabled}
Expand Down

0 comments on commit 242c9bd

Please sign in to comment.