Skip to content

Commit c0e9ca9

Browse files
authored
Implement P&M focused in CSS, instead of JS (#82)
1 parent d1577e4 commit c0e9ca9

4 files changed

Lines changed: 10 additions & 24 deletions

File tree

src/lib/components/motions/form/InputSpeakingTime.svelte

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<script lang="ts">
2-
import { fade } from "svelte/transition";
3-
42
import type { InputComponentProps } from "$lib/motions/definitions";
53
import { parseTime, sanitizeTime, stringifyTime } from "$lib/util/time";
64
75
type Props = InputComponentProps<string>;
86
let {
97
name,
10-
focused = false,
118
value = $bindable(),
129
error,
1310
isExtending
@@ -21,16 +18,14 @@
2118
2219
const inpId = $props.id();
2320
</script>
24-
<label class="label" for="input-stime-{inpId}">
21+
<label class="label group" for="input-stime-{inpId}">
2522
<div class="flex justify-between">
2623
<span>
2724
Speaking Time
28-
{#if focused}
29-
<!-- Time guide -->
30-
<span class="text-surface-500" transition:fade={{ duration: 150 }}>
31-
&middot; {sanitizeTime(value)}
32-
</span>
33-
{/if}
25+
<!-- Time guide -->
26+
<span class="text-surface-500 not-group-has-focus-within:opacity-0 transition-opacity duration-150">
27+
&middot; {sanitizeTime(value)}
28+
</span>
3429
</span>
3530
<div class="flex gap-1 items-center">
3631
<!-- Items are const and won't change, so key not necessary -->

src/lib/components/motions/form/InputTotalTime.svelte

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<script lang="ts">
2-
import { fade } from "svelte/transition";
3-
42
import type { InputComponentProps } from "$lib/motions/definitions";
53
import { a11yLabel, hasKey, lazyslide } from "$lib/util";
64
import { sanitizeTime, stringifyTime } from "$lib/util/time";
@@ -10,7 +8,6 @@
108
let {
119
name,
1210
error,
13-
focused = false,
1411
value = $bindable(),
1512
isExtending,
1613
motion
@@ -26,16 +23,14 @@
2623
}
2724
}
2825
</script>
29-
<label class="label">
26+
<label class="label group">
3027
<div class="flex justify-between">
3128
<span>
3229
Total Time
33-
{#if focused}
34-
<!-- Time guide -->
35-
<span class="text-surface-500" transition:fade={{ duration: 150 }}>
36-
&middot; {sanitizeTime(value)}
37-
</span>
38-
{/if}
30+
<!-- Time guide -->
31+
<span class="text-surface-500 not-group-has-focus-within:opacity-0 transition-opacity duration-150">
32+
&middot; {sanitizeTime(value)}
33+
</span>
3934
</span>
4035
{#if isExtending}
4136
<button

src/lib/components/motions/form/MotionForm.svelte

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
}
8484
}
8585
86-
let activeElement = $state<HTMLElement>();
8786
// Motions that you can input into dropdown (taking into account provided preferences)
8887
let allowedMotions = $derived.by(() => {
8988
// A map indicating whether a given motion type should appear.
@@ -182,7 +181,6 @@
182181
}
183182
</script>
184183

185-
<svelte:document bind:activeElement />
186184
<form
187185
onsubmit={submitMotion}
188186
oninput={() => inputError = undefined}
@@ -229,7 +227,6 @@
229227
<Component
230228
{name}
231229
error={inputError?.path.includes(name)}
232-
focused={(activeElement as any)?.name === name}
233230
bind:value={(inputMotion as any)[name]}
234231
isExtending={isExtending(inputMotion)}
235232
motion={$selectedMotion}

src/lib/motions/definitions.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export const MOTION_DEFS = {
7171
export type InputComponentProps<V> = {
7272
name: string,
7373
error?: boolean,
74-
focused?: boolean,
7574
value?: V,
7675
isExtending?: boolean,
7776
motion: Motion | null

0 commit comments

Comments
 (0)