TextInput
Single-line text input with optional leading icon, optional prefix text after the icon, and optional trailing suffix. Supports multiple HTML input types, three sizes, four visual variants, and callbacks for both input and change events.
import { TextInput, PhiIcons } from "phoundry-ui";Basic
Loading interactive example…
View source
<script lang="ts"> import { TextInput } from "phoundry-ui";
let basic = $state("");</script>
<div class="max-w-sm"> <TextInput value={basic} oninput={(v: string) => { basic = v; }} placeholder="Your name" /></div>Full width
Loading interactive example…
View source
<script lang="ts"> import { TextInput } from "phoundry-ui";</script>
<div class="w-80 max-w-full"> <TextInput fullWidth placeholder="Fills the container" /></div>With Icon
Loading interactive example…
View source
<script lang="ts"> import { TextInput } from "phoundry-ui"; import { PhiIcons } from "phoundry-ui";
let withIcon = $state("");
let search = $state("");</script>
<div class="max-w-sm"> <TextInput value={withIcon} oninput={(v: string) => { withIcon = v; }} placeholder="Search..." icon={PhiIcons.search} /></div>Clearable
Loading interactive example…
View source
<script lang="ts"> import { TextInput } from "phoundry-ui";
import { PhiIcons } from "phoundry-ui";
let search = $state("");
let clearablePlain = $state("hello");
let clearableWithIcon = $state("phoundry");</script>
<div class="flex max-w-sm flex-col gap-3"> <TextInput value={clearablePlain} oninput={(v: string) => { clearablePlain = v; }} placeholder="Type something..." clearable /> <TextInput value={clearableWithIcon} oninput={(v: string) => { clearableWithIcon = v; }} icon={PhiIcons.search} placeholder="Search..." clearable /></div><p class="mt-2 text-xs text-txt-tertiary"> The clear button appears only when the input has a value.</p>Suffix
Loading interactive example…
View source
<script lang="ts"> import { TextInput } from "phoundry-ui";
let suffixOnly = $state("");
let suffixBgDemo = $state("");</script>
<div class="flex max-w-sm flex-col gap-3"> <TextInput value={suffixOnly} oninput={(v: string) => { suffixOnly = v; }} suffix=".md" placeholder="notes" /> <TextInput value={suffixBgDemo} oninput={(v: string) => { suffixBgDemo = v; }} suffix=".md" suffixBg placeholder="notes" /></div>Prefix
Loading interactive example…
View source
<script lang="ts"> import { TextInput } from "phoundry-ui"; import { PhiIcons } from "phoundry-ui";
let search = $state("");
let prefixOnly = $state("");
let prefixWithIcon = $state("");
let prefixBgDemo = $state("");</script>
<div class="flex max-w-sm flex-col gap-3"> <TextInput value={prefixOnly} oninput={(v: string) => { prefixOnly = v; }} prefix="$" placeholder="0.00" /> <TextInput value={prefixWithIcon} oninput={(v: string) => { prefixWithIcon = v; }} icon={PhiIcons.search} prefix="#" placeholder="lookup" /> <TextInput value={prefixBgDemo} oninput={(v: string) => { prefixBgDemo = v; }} icon={PhiIcons.search} prefix="USD" prefixBg placeholder="0.00" /></div>Sizes
Loading interactive example…
View source
<script lang="ts"> import { TextInput } from "phoundry-ui";
let small = $state("");
let medium = $state("");
let large = $state("");</script>
<div class="flex max-w-sm flex-col gap-3"> <TextInput value={small} oninput={(v: string) => { small = v; }} placeholder="Small" size="sm" clearable /> <TextInput value={medium} oninput={(v: string) => { medium = v; }} placeholder="Medium" size="md" clearable /> <TextInput value={large} oninput={(v: string) => { large = v; }} placeholder="Large" size="lg" clearable /></div>Read-only & disabled
Loading interactive example…
View source
<script lang="ts"> import { TextInput } from "phoundry-ui";
let readOnlyDemo = $state("Read-only value");
let disabledDemo = $state("Disabled");</script>
<div class="flex max-w-sm flex-col gap-3"> <TextInput value={readOnlyDemo} oninput={(v: string) => (readOnlyDemo = v)} readonly placeholder="Cannot edit" /> <TextInput value={disabledDemo} oninput={(v: string) => (disabledDemo = v)} disabled /></div>Types (password, search)
Loading interactive example…
View source
<script lang="ts"> import { TextInput } from "phoundry-ui"; import { PhiIcons } from "phoundry-ui";
let password = $state("");
let search = $state("");</script>
<div class="flex max-w-sm flex-col gap-3"> <TextInput type="password" value={password} oninput={(v: string) => { password = v; }} placeholder="Password" /> <TextInput type="search" value={search} oninput={(v: string) => { search = v; }} placeholder="Search..." icon={PhiIcons.search} /></div>Variants
Loading interactive example…
View source
<script lang="ts"> import { TextInput } from "phoundry-ui";
let outline = $state("");
let fill = $state("");
let ghost = $state("");
let trueGhost = $state("");</script>
<div class="flex max-w-sm flex-col gap-3"> <TextInput variant="outline" value={outline} oninput={(v: string) => { outline = v; }} placeholder="Outline (default)" /> <TextInput variant="fill" value={fill} oninput={(v: string) => { fill = v; }} placeholder="Fill" /> <TextInput variant="ghost" value={ghost} oninput={(v: string) => { ghost = v; }} placeholder="Ghost" /> <TextInput variant="trueGhost" value={trueGhost} oninput={(v: string) => { trueGhost = v; }} placeholder="True ghost" /></div>Autocomplete
Loading interactive example…
View source
<script lang="ts"> import { TextInput } from "phoundry-ui";
let email = $state("");</script>
<div class="flex max-w-sm flex-col gap-3"> <TextInput type="email" value={email} oninput={(v: string) => { email = v; }} autocomplete="email" placeholder="Email address" /> <p class="text-xs text-txt-tertiary"> Browser may suggest saved email addresses </p></div>API
From phoundry-ui@0.4.21
| Name | Type | Default | Description |
|---|---|---|---|
valuebindable | string | '' | Current input value (bind:value friendly). |
onchange | (value: string) => void | — | Fires on blur / Enter after value changes |
oninput | (value: string) => void | — | Fires on every keystroke |
type | "text" | "url" | "email" | "password" | "search" | "tel" | 'text' | HTML input type |
placeholder | string | — | Placeholder text |
size | "sm" | "md" | "lg" | 'md' | Shared Button control scale: sm 1.5rem, md 1.75rem, lg 2rem outer height |
variant | TextFieldVariant | 'outline' | Visual style. trueGhost has no border, fill, or hover/focus chrome. |
fullWidth | boolean | false | Stretch the whole control to its parent width. Otherwise uses its intrinsic input width. |
disabled | boolean | false | Disables the input |
readonly | boolean | false | Makes the input read-only |
icon | string | — | Iconify icon string shown at the leading edge |
prefix | string | — | Fixed text after the icon and before the typed value (e.g. currency symbol) |
fixedPrefixWidth | string | — | CSS width for the prefix cell (e.g. 5.5rem). Long text truncates with ellipsis. Requires prefix. |
prefixBg | boolean | false | Inset background on the combined icon/prefix region |
suffix | string | — | Fixed text after the typed value (e.g. file extension) |
suffixBg | boolean | false | Inset background on the suffix region |
clearable | boolean | false | Shows a trailing clear button when the input has a value |
class | ClassValue | — | Additional classes on the root shell |
style | string | — | Inline styles on the root shell |
id | string | — | HTML id attribute |
name | string | — | HTML name attribute for forms |
autocomplete | AutoFill | — | Browser autocomplete hint |
elementbindable | HTMLInputElement | — | Bindable reference to the underlying input element |
…rest: Forwarded to the inner <input> (e.g. aria-*, inputmode, maxlength).
Usage tips
- Use
oninputfor real-time feedback (e.g. live search) andonchangefor commit-on-blur behavior. - Set
type="search"with an icon for a native-feeling search field that shows a clear button in some browsers. - Pair with
FormFieldto get labels, descriptions, and error messaging for free. - Use
variant="trueGhost"for inline editing where the parent already supplies hover/focus treatment. It has no border, fill, or focus ring — provide your own affordance if the field stands alone.
Width and styling
fullWidth defaults to false for plain, clearable, and affixed inputs. Set it when the field should fill its container:
<TextInput fullWidth placeholder="Your name" /><TextInput fullWidth icon={PhiIcons.search} clearable placeholder="Search..." />The stable root hook is .ph-text-input. class and style apply to this shell in every configuration; element, native attributes, events, and attachments target the inner input. Do not depend on the internal DOM or part classes.
The root always exposes data-size, data-variant, and data-full-width; boolean states use exact values such as [data-full-width='true']. Disabled and read-only state remain native input attributes.
Sizes consume the published --ph-comp-h-sm, --ph-comp-h-md, and --ph-comp-h-lg tokens and corresponding --ph-comp-icon-* tokens from phoundry-ui/styles/components.css. Color values come from the applied named Theme. Local --_ph-* properties are implementation details. Scoped, unlayered styles may take precedence over utility classes; use fullWidth for full-width layout and root inline styles for custom dimensions.
When upgrading, replace size="xs" with size="sm" and add fullWidth wherever the previous automatic full width was required. sm now uses the shared 1.5rem height (previously 1.375rem). Replace .text-input root selectors with .ph-text-input. Styles that previously targeted a plain input now target the shell; keep input bindings and native attributes on the component as before. Focus uses the same variant chrome as hover, without a blue or accent-colored focus ring. This includes the clear button. trueGhost stays chrome-free.
The shared .ph-text-field primitive in phoundry-ui/styles/components.css keeps variant chrome and size configuration aligned with NumberInput. All three fields use --ph-field-radius (0.5rem) and --ph-input-shadow for outline surfaces. Focus and hover share the same appearance; native blue focus rings are suppressed.
outline has a quiet translucent background, muted border, and input shadow. fill uses the stronger neutral control background with no visible border or shadow; the distinction remains on hover and focus.