# Input

A text input component for forms and user data entry with built-in styling and accessibility features.

Section: Components / Inputs
Page: https://ui.heyramzi.com/components/input
Import path: `@heyramzi/ui/shadcn/input`

## Import

```ts
import { Input } from "@heyramzi/ui/shadcn/input";
```

## Examples

### With a label and hint

Wrap the input in a Field so the label, the hint and the input line up and read as one.

```svelte
<script lang="ts">
	import * as Field from "@heyramzi/ui/shadcn/field";
	import { Input } from "@heyramzi/ui/shadcn/input";
</script>

<Field.Field class="max-w-xs">
	<Field.Label for="example-username">Username</Field.Label>
	<Input id="example-username" placeholder="ada" aria-describedby="example-username-hint" />
	<Field.Description id="example-username-hint">It shows on your public profile.</Field.Description>
</Field.Field>
```

### Disabled

A disabled input dims, takes no clicks and drops out of the tab order.

```svelte
<script lang="ts">
	import * as Field from "@heyramzi/ui/shadcn/field";
	import { Input } from "@heyramzi/ui/shadcn/input";
</script>

<Field.Field class="max-w-xs" data-disabled="true">
	<Field.Label for="example-workspace">Workspace</Field.Label>
	<Input id="example-workspace" value="acme-studio" disabled />
</Field.Field>
```

### Invalid

Set aria-invalid on the input and the border and ring turn red, with the error read out below.

```svelte
<script lang="ts">
	import * as Field from "@heyramzi/ui/shadcn/field";
	import { Input } from "@heyramzi/ui/shadcn/input";
</script>

<Field.Field class="max-w-xs" data-invalid="true">
	<Field.Label for="example-email">Email</Field.Label>
	<Input
		id="example-email"
		type="email"
		autocomplete="email"
		value="ada@"
		aria-invalid="true"
		aria-describedby="example-email-error"
	/>
	<Field.Error id="example-email-error">Add the part after the @.</Field.Error>
</Field.Field>
```

### File

Set type to file and bind files to get the FileList back.

```svelte
<script lang="ts">
	import * as Field from "@heyramzi/ui/shadcn/field";
	import { Input } from "@heyramzi/ui/shadcn/input";

	let files = $state<FileList>();
</script>

<Field.Field class="max-w-xs">
	<Field.Label for="example-avatar">Avatar</Field.Label>
	<Input id="example-avatar" type="file" accept="image/png, image/jpeg" bind:files />
	<Field.Description>PNG or JPG, up to 2 MB.</Field.Description>
</Field.Field>
```

## Demo

```svelte
<script lang="ts">
	import { Input } from "@heyramzi/ui/shadcn/input";
</script>

<Input type="email" placeholder="Email" class="max-w-xs" />
```

## API

### Input.Root

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `type` | `InputType` |  |  |
| `files` | `undefined` |  | bindable |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `value` |  |  | bindable |
| `class` | `string` |  |  |
| `data-slot` | `string` | `"input"` |  |

Every prop of `HTMLInputAttributes` from `svelte/elements`, except `type`.

### Input.SecretInput

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `variant` | `"lock" \| "obfuscate"` | `"lock"` |  |
| `value` | `string` | `""` | bindable |
| `class` | `string` |  |  |
| `revealLabel` | `string` | `"Reveal value"` | The reveal button's name while the value is hidden, in the app's language. |
| `hideLabel` | `string` | `"Hide value"` | The same button's name while the value shows. |
| `maskedLabel` | `string` | `"Encrypted value"` | The name of the `obfuscate` box. |

Every prop of `HTMLInputAttributes` from `svelte/elements`, except `class, files, type, value`.
