Input
A labeled field with invalid, disabled, and bound values.
Type to try the bound value.
More examples
Labeled field with an icon
Source
<script lang="ts">
import 'portal-bits/styles.css';
import 'portal-bits/tokens.css';
import type { Snippet } from 'svelte';
let { children }: { children: Snippet } = $props();
</script>
{@render children()}
<script lang="ts">
import InputExample from './InputExample.svelte';
</script>
<InputExample invalid={false} disabled={false} required={false} />
<script lang="ts">
import { Input } from 'portal-bits';
let {
invalid = false,
disabled = false,
required = false,
}: { invalid?: boolean; disabled?: boolean; required?: boolean } = $props();
let value = $state('');
</script>
<div class="field">
<Input
label="Email"
type="email"
placeholder="alex@example.com"
bind:value
{invalid}
{required}
{disabled}
aria-describedby={invalid ? 'email-error' : undefined}
/>
{#if invalid}
<p id="email-error" class="error">Enter an email address, such as alex@example.com.</p>
{/if}
<p aria-live="polite">{value ? `Bound value: “${value}”` : 'Type to try the bound value.'}</p>
</div>
<style>
.field {
max-width: 340px;
}
.error {
color: var(--portal-error);
}
</style>
API reference
These tables list the props and snippets that Input declares. Attributes passed through to an element or primitive are listed under Forwarded attributes, not here.
Props
| Name | Type | Default | Required | Binding | Description |
|---|---|---|---|---|---|
label | string | None | Yes | One-way | The visible label, tied to the field with `for`. |
hideLabel | boolean | false | No | One-way | Keeps the label for assistive technology only. |
invalid | boolean | false | No | One-way | Sets `aria-invalid`. Render the error text yourself. |
value | string | "" | No | Bindable | The field value. |
id | string | Generated id | No | One-way | The input id. A stable id is generated when you omit it. |
class | string | "" | No | One-way | Extra classes, added after the component classes. |
Snippets
| Name | Type | Default | Required | Binding | Description |
|---|---|---|---|---|---|
icon | Snippet | None | No | One-way | A leading icon inside the field. |
Forwarded attributes
- Native input attributes except `value`: `type`, `name`, `placeholder`, `disabled`, `required`, `autocomplete`, `aria-*`, and handlers. They land on the `input` element.
No data attributes are documented as stable.
Limits
- The wrapper `div` takes no attributes. Pass layout classes to a parent.
- `value` is typed as a string, whatever the input `type`.