Skip to content
On this page Addons (input group)

Inputs

TextField

Styled text input with label, helper text, error state and leading and trailing slots.

<script>
  import { TextField } from "@codeatlasdev/ui";
  let email = $state("");
</script>

<TextField label="Email" type="email" bind:value={email} />

An error replaces the description and is announced to assistive tech. On touch devices the input text stays at 16px or more so iOS Safari does not zoom on focus. Native input attributes (maxlength, inputmode, data-*, onkeydown, onfocus…) are spread on the <input>, and bind:ref gives you the element. For an inline field whose label is implied visually, set hideLabel (the label stays for screen readers) or pass aria-label without label. For a password, type="password" plus revealable adds the eye button inside the field: it toggles the input between password and text, has a localized name from the catalog (“Show password” / “Hide password”), aria-pressed, and a 44px hit area on touch without changing the field height. Do not rebuild it with trailing. below renders a snippet under the field, after the error or description: use it for a “Forgot password?” link or a strength meter. requiredIndicator={false} hides the asterisk of a required field when the form marks nothing as optional (the input stays required). Wrapper components such as MaskedField, MoneyInput and PhoneField forward these props to TextField.

#056

Default

Basic text inputs with a label.

Reference #056 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { TextField } from '@codeatlasdev/ui';

  let name = $state('');
  let email = $state('');
</script>

<div class="col">
  <TextField label="Full name" placeholder="Jane Smith" bind:value={name} />
  <TextField label="Email" placeholder="[email protected]" type="email" bind:value={email} />
</div>

<style>
  .col {
    display: flex;
    flex-direction: column;
    gap: var(--ca-space-4);
    width: 100%;
    max-width: 400px;
  }
</style>
#057

With icons

leading and trailing snippets. Interactive trailing content must be a real button with its own label; for a password reveal use revealable.

Reference #057 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { TextField } from '@codeatlasdev/ui';
  import { Search } from '@lucide/svelte';

  let password = $state('');
</script>

<div class="col">
  <TextField label="Search" placeholder="Type to search…">
    {#snippet leading()}<Search size={16} stroke-width={2} />{/snippet}
  </TextField>
  <TextField label="Password" type="password" revealable placeholder="••••••••" bind:value={password} />
</div>

<style>
  .col {
    display: flex;
    flex-direction: column;
    gap: var(--ca-space-4);
    width: 100%;
    max-width: 400px;
  }
</style>
#058

States

Helper text, error, required, read-only, disabled and the small size.

3–20 characters, letters and underscores only.

Reference #058 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { TextField } from '@codeatlasdev/ui';

  let wrong = $state('wrong@');
</script>

<div class="col">
  <TextField label="Username" placeholder="john_doe" description="3–20 characters, letters and underscores only." />
  <TextField label="Email" bind:value={wrong} error="Please enter a valid email address." />
  <TextField label="Company" required />
  <TextField label="Read-only field" value="Cannot edit this" readonly />
  <TextField label="Disabled field" value="Cannot edit this" disabled />
  <TextField label="Small" size="sm" placeholder="Compact height" />
</div>

<style>
  .col {
    display: flex;
    flex-direction: column;
    gap: var(--ca-space-4);
    width: 100%;
    max-width: 400px;
  }
</style>
#982

Text addons

`prefix` and `suffix` as strings: fixed context inside the border, read with the label.

https:// .com

Read with the label: https:// acme .com

$ USD
@
.dev
https://

Reference #982 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { TextField } from '@codeatlasdev/ui';

  let site = $state('acme');
  let price = $state('49');
</script>

<div class="col">
  <TextField label="Website" prefix="https://" suffix=".com" bind:value={site} description="Read with the label: https:// acme .com" />
  <TextField label="Price" prefix="$" suffix="USD" bind:value={price} inputmode="decimal" />
  <TextField label="Handle" prefix="@" size="sm" value="codeatlas" />
  <TextField label="Domain" suffix=".dev" error="Already taken" value="acme" />
  <TextField label="Disabled" prefix="https://" disabled value="locked" />
</div>

<style>
  .col { display: grid; gap: var(--ca-space-4); width: 100%; max-width: 24rem; }
</style>
#983

Button addons

`prefix` and `suffix` as snippets: a Button or IconButton keeps its own name and Tab stop.

Reference #983 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { Button, IconButton, TextField } from '@codeatlasdev/ui';
  import { Check, Copy } from '@lucide/svelte';

  let copied = $state(false);
  let code = $state('');
</script>

{#snippet copyBtn()}
  <IconButton
    variant="text"
    size="sm"
    aria-label={copied ? 'Link copied' : 'Copy link'}
    onclick={() => { copied = true; }}
  >
    {#if copied}<Check size={14} />{:else}<Copy size={14} />{/if}
  </IconButton>
{/snippet}
{#snippet applyBtn()}
  <Button variant="ghost" size="sm" disabled={!code}>Apply</Button>
{/snippet}

<div class="col">
  <TextField label="Share link" readonly value="https://ca.dev/s/x7Qk" suffix={copyBtn} />
  <TextField label="Coupon code" placeholder="SPRING25" bind:value={code} suffix={applyBtn} />
</div>

<style>
  .col { display: grid; gap: var(--ca-space-4); width: 100%; max-width: 24rem; }
</style>
#500

Password

revealable adds the show/hide eye, below holds the Forgot password link, requiredIndicator={false} drops the asterisk.

Reference #500 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { TextField } from '@codeatlasdev/ui';

  let email = $state('');
  let password = $state('');
</script>

<div class="col">
  <TextField label="Email" type="email" autocomplete="email" required requiredIndicator={false} bind:value={email} />
  <TextField
    label="Password"
    type="password"
    revealable
    required
    requiredIndicator={false}
    autocomplete="current-password"
    bind:value={password}
  >
    {#snippet below()}
      <a href="/forgot-password">Forgot password?</a>
    {/snippet}
  </TextField>
</div>

<style>
  .col {
    display: flex;
    flex-direction: column;
    gap: var(--ca-space-4);
    width: 100%;
    max-width: 400px;
  }
</style>
#389

Hidden label

hideLabel keeps the label for assistive tech only; maxlength and ref reach the native input.

Reference #389 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { Button, TextField } from '@codeatlasdev/ui';

  let items = $state([{ name: 'Design review' }, { name: 'Ship 4.3' }]);
  let first = $state<HTMLInputElement | null>(null);
</script>

<div class="col">
  {#each items as item, i (i)}
    <TextField
      label="Task name"
      hideLabel
      bind:value={item.name}
      bind:ref={first}
      maxlength={40}
      autocomplete="off"
    />
  {/each}
  <Button size="sm" variant="text" onclick={() => first?.focus()}>Focus the last field</Button>
</div>

<style>
  .col {
    display: flex;
    flex-direction: column;
    gap: var(--ca-space-3);
    width: 100%;
    max-width: 400px;
  }
</style>

Addons (input group)

prefix and suffix put an addon inside the field border, flush with it and set apart from the input by a divider (shadcn’s InputGroup). Differences from leading and trailing, which are bare icons inside the padding:

  • A string is static text (https://, $, .com, USD). It is part of the field’s accessible description (read after the label, before the description or error) and a click on it focuses the input. It is not repeated as a label: name the field itself with label.
  • A snippet is interactive content: an IconButton (variant="text" size="sm"), a Button (variant="ghost" size="sm") or a native select. It is not hidden from assistive tech, keeps its own accessible name and Tab stop (input first, then a suffix button, in reading order), and a button must have a visible text or an aria-label.
  • The focus ring wraps the whole group while the input or an addon button has focus; error and disabled reach the addons.
  • --ca-tf-addon-bg sets the addon fill (default --ca-action-hover).

Tokens

--ca-field-gap (label to box to hint, default --ca-space-1) and --ca-field-label-leading (default --ca-line-height-snug) are shared with TextArea; --ca-tf-gap and --ca-tf-label-line-height set this component only and win.

Props

PropTypeDefaultDescription
labelstring–Label text.
hideLabelbooleanfalseRenders the label with `.ca-sr-only`: read by screen readers, not shown.
placeholderstring''Input placeholder.
valuestring''Bindable input value.
typestring'text'HTML input type.
errorstring–Validation error message. Puts the field in the error state.
descriptionstring–Non-error hint shown below the field.
helperTextstring–Deprecated alias of description.
disabledbooleanfalseDisables the input.
requiredbooleanfalseMarks the field as required.
requiredIndicatorbooleantrue`false` hides the asterisk of a `required` field; the input stays `required`.
readonlybooleanfalseMakes the input read-only.
autocompleteHTMLInputAttributes['autocomplete']–Native autocomplete hint.
namestring–Native name, for form submission.
size'sm' | 'md''md'Field height.
leadingSnippet–Icon or element before the input.
trailingSnippet–Icon or element after the input.
prefixstring | Snippet–Addon before the input, inside the border. A string is text read as part of the description; a snippet is interactive content (Button, IconButton, select).
suffixstring | Snippet–Addon after the input, same rules as `prefix`.
revealablebooleanfalseWith `type="password"`: adds a show/hide eye button inside the field (`aria-pressed`, localized name, 44px on touch).
belowSnippet–Content under the field and its hint or error: a link such as Forgot password, or a strength meter.
skeletonbooleanfalseLoading placeholder with the exact size of the loaded field (disabled, `aria-busy`). See Skeleton.
classstring–Extra classes on the root.
refHTMLInputElement | null–Bindable native input element.
oninput(value: string) => void–Called on every keystroke with the new value.
onchange(value: string) => void–Called when the value is committed (blur or Enter).
onfocus(e: FocusEvent) => void–Called when the input gains focus.
onblur(e: FocusEvent) => void–Called when the input loses focus.