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

bind:files on Input component #1524

Open
1 task done
DDuran19 opened this issue Nov 28, 2024 · 2 comments
Open
1 task done

bind:files on Input component #1524

DDuran19 opened this issue Nov 28, 2024 · 2 comments
Labels
type: feature Introduction of new functionality to the application

Comments

@DDuran19
Copy link

Prerequisites

  • This feature already exists in shadcn/ui - if not, it won't be considered here so don't continue with your issue.

Describe the feature

Right now, we are unable to bind files for multiple uploads. Is it possible that we can add this feature too?

Here's my dirty implementation. if this is good, should I make a PR?

<script lang="ts">
	import type { HTMLInputAttributes } from 'svelte/elements';
	import type { WithElementRef } from 'bits-ui';
	import { cn } from '$lib/utils/index.js';

	let {
		ref = $bindable(null),
		value = $bindable(),
		files = $bindable(),
		class: className,
		type,
		...restProps
	}: WithElementRef<HTMLInputAttributes & { files?: FileList }> = $props();
	const defaultClass =
		'border-input placeholder:text-muted-foreground focus-visible:ring-ring flex h-9 w-full rounded-md border bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:outline-none focus-visible:ring-1 disabled:cursor-not-allowed disabled:opacity-50';
</script>

{#if type === 'file'}
	<input
		bind:this={ref}
		type="file"
		class={cn(defaultClass, className)}
		bind:value
		bind:files
		{...restProps}
	/>
{:else}
	<input bind:this={ref} {type} class={cn(defaultClass, className)} bind:value {...restProps} />
{/if}
@DDuran19 DDuran19 added the type: feature Introduction of new functionality to the application label Nov 28, 2024
@huntabyte
Copy link
Owner

The issue here is that now files exist on the type even for inputs that aren't of type file. Will need to look into this one further.

@DDuran19
Copy link
Author

DDuran19 commented Dec 1, 2024

Thanks hunter!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

2 participants