Skip to content

Commit 6eab253

Browse files
committed
Implement required prop for SingleFileInput
1 parent 78b576b commit 6eab253

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

web/src/lib/components/files/MultimodalFileInput.svelte

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,8 @@
111111
{/if}
112112
</div>
113113

114-
<!-- TODO: Implement required prop for SingleFileInput -->
115114
{#snippet fileInput()}
116-
<SingleFileInput bind:file={instance.file} class="flex w-fit items-center gap-2 rounded-md border btn-ghost px-2 py-1 has-focus-visible:outline-2">
117-
<span class="iconify size-4 shrink-0 text-em-disabled octicon--file-16"></span>
118-
{#if instance.file}
119-
{instance.file.name}
120-
{:else}
121-
<span class="font-light">{label}</span>
122-
{/if}
123-
<span class="iconify size-4 shrink-0 text-em-disabled octicon--triangle-down-16"></span>
124-
</SingleFileInput>
115+
<SingleFileInput required bind:file={instance.file} />
125116
{/snippet}
126117

127118
{#snippet urlInput()}
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<script lang="ts">
2-
import { useId } from "bits-ui";
3-
import { type RestProps } from "$lib/types";
4-
import { type Snippet } from "svelte";
52
import { watch } from "runed";
63
74
type Props = {
8-
children?: Snippet<[{ file?: File }]>;
5+
label?: string;
6+
required?: boolean;
97
file?: File;
10-
} & RestProps;
8+
};
119
12-
let { children, file = $bindable<File | undefined>(undefined), ...restProps }: Props = $props();
10+
let { label = "File", required = false, file = $bindable<File | undefined>(undefined) }: Props = $props();
1311
1412
let files = $state<FileList | undefined>();
1513
@@ -22,11 +20,18 @@
2220
},
2321
);
2422
25-
const labelId = useId();
26-
const inputId = useId();
23+
const uid = $props.id();
24+
const labelId = `${uid}-label`;
25+
const inputId = `${uid}-input`;
2726
</script>
2827

29-
<label id={labelId} for={inputId} {...restProps}>
30-
{@render children?.({ file })}
31-
<input id={inputId} aria-labelledby={labelId} type="file" bind:files class="sr-only" />
28+
<label id={labelId} for={inputId} class="relative flex w-fit items-center gap-2 rounded-md border btn-ghost px-2 py-1 has-focus-visible:outline-2">
29+
<span class="iconify size-4 shrink-0 text-em-disabled octicon--file-16"></span>
30+
{#if file}
31+
{file.name}
32+
{:else}
33+
<span class="font-light">{label}</span>
34+
{/if}
35+
<span class="iconify size-4 shrink-0 text-em-disabled octicon--triangle-down-16"></span>
36+
<input id={inputId} aria-labelledby={labelId} type="file" {required} bind:files class="absolute top-0 left-0 size-full opacity-0" />
3237
</label>

0 commit comments

Comments
 (0)