Skip to content
portalbits
Home Docs GitHub(opens in a new tab)

Guides

Get startedFoundationsMotion

Components

All components

Buttons

ButtonIconButton

Inputs

InputSelectTextareaSlider

Selection

CheckboxToggleToggleGroupSwitchRadioGroup

Identity

AvatarBadge

Overlays

DialogPopoverTooltipDropdownMenuAlertDialog

Disclosure

TabsAccordion

Cards

AppCardArticleCardFeatureCard

Content

CarouselSectionHeaderEmptyStateAlertProgressSeparatorRowListRow

Chrome

PortalShellSidebarNavMobileNavTopBarAuthFrameColorSelectorFloatingNav

Input

A labeled field with invalid, disabled, and bound values.

Type to try the bound value.

Variations
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

NameTypeDefaultRequiredBindingDescription
labelstringNoneYesOne-wayThe visible label, tied to the field with `for`.
hideLabelbooleanfalseNoOne-wayKeeps the label for assistive technology only.
invalidbooleanfalseNoOne-waySets `aria-invalid`. Render the error text yourself.
valuestring""NoBindableThe field value.
idstringGenerated idNoOne-wayThe input id. A stable id is generated when you omit it.
classstring""NoOne-wayExtra classes, added after the component classes.

Snippets

NameTypeDefaultRequiredBindingDescription
iconSnippetNoneNoOne-wayA 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`.

Related

  • Select
  • Checkbox
Previous IconButton Next Select

On this page

  • Preview
  • Source
  • API reference
  • Props
  • Snippets
  • Forwarded attributes
  • Limits