Skip to content
Bladewell

<x-widget.text-input>

Text input Blade component for Laravel and Livewire

A text field with label, hint and error, filled back from the session after a failed submit. Takes any input type, plus prefix, suffix and a leading icon. Works with Livewire wire:model, name optional. Password, number, select and the other form controls are components of their own.

php artisan bladewell:add text-input
Also adds
Icon
Used by
Filter builder
Works with
Laravel 12 and 13, Livewire 3 and 4, Tailwind CSS 4.1+, PHP 8.3+
Guides
Build a Laravel form from your validation rules · Editable table cells in Laravel with Livewire · A Livewire modal that stays open through re-renders · Using Blade components in Livewire 3 and 4 · Two-factor authentication screens for Laravel Fortify · Passkey sign-in for Laravel with Fortify · AI agent actions with Approve and Deny in Laravel · Livewire multi-step form with validation per step

Usage

Livewire form

Every input binds with wire:model (deferred) or wire:model.live, and a name isn't needed: the property names the field, its id stays the same on every render (so typing keeps focus) and $errors are read under it. Without :value a field shows the bound property, so setting or clearing it in PHP updates the field, the grouped number's display, the phone's country and the OTP boxes included. The password is never rendered back, Livewire included. In Livewire an error stays until the component validates again; call $this->validateOnly($property) in updated() to clear it as people type.

Blade
<form wire:submit="save" class="space-y-5">
    <x-widget.text-input label="Name" wire:model.live="name" counter maxlength="60" />
    <x-widget.text-input label="Email" type="email" wire:model="email" />
    <x-widget.password label="Password" new :min="8" numbers wire:model="password" />
    <x-widget.number label="Amount" grouped wire:model.live="amount" suffix="USD" />
    <x-widget.number label="Seats" stepper :decimals="0" min="1" max="20" wire:model.live="seats" />
    <x-widget.phone label="Phone" country="US" wire:model="phone" />
    <x-widget.textarea label="Notes" counter maxlength="500" wire:model="notes" />
    <x-widget.radio label="Plan" :options="['free' => 'Free', 'pro' => 'Pro']" wire:model.live="plan" />
    <x-widget.checkbox label="I agree to the terms" wire:model="agree" />
    <x-widget.switch label="Email me updates" wire:model="updates" />
    <x-widget.otp label="Code we sent you" :length="6" wire:model="otp" />

    <button type="submit">Save</button>
</form>

On the server

The text input can't stop a request that skips it. Here's what to check on your server.

Security

Examples

Text

Old input and validation errors for the field's name are filled in from the session.

We'll never share your email.

Show code
Blade
<div class="grid gap-6 sm:grid-cols-2">
    <x-widget.text-input name="full_name" label="Full name" placeholder="Jane Doe" />
    <x-widget.text-input name="email" type="email" label="Email" placeholder="[email protected]" info="We'll never share your email." />
</div>

States

The error clears the moment the user edits the field.

Name must be at least 2 characters.

Show code
Blade
<div class="grid gap-6 sm:grid-cols-3">
    <x-widget.text-input name="display_name" label="With error" value="x" error="Name must be at least 2 characters." />
    <x-widget.text-input name="account_id" label="Read-only" value="ACC-20931" readonly />
    <x-widget.text-input name="referral" label="Disabled" placeholder="Not editable" disabled />
</div>

Prefix and suffix

prefix, suffix and a leading icon sit inside the box. required marks the label; the input's own required attribute is what browsers and screen readers use.

https://
kg
@
Show code
Blade
<div class="grid gap-6 sm:grid-cols-2">
    <x-widget.text-input name="website" type="url" label="Website" prefix="https://" placeholder="example.com" />
    <x-widget.text-input name="weight" label="Weight" suffix="kg" placeholder="0" inputmode="decimal" />
    <x-widget.text-input name="wallet_name" label="Wallet name" icon="wallet" placeholder="Savings" required />
    <x-widget.text-input name="handle" label="Username" prefix="@" placeholder="jane" required />
</div>

Counter

counter shows characters used against maxlength. It's opt-in, so a name field with maxlength="255" doesn't get one.

0 / 60

Show code
Blade
<x-widget.text-input name="headline" label="Headline" maxlength="60" counter placeholder="What's new?" />

Props

Other attributes, such as autocomplete or data-*, are passed through to the element. class styles the component's outer wrapper.

<x-widget.text-input>

Prop Default Description
name null What it submits as; its error and old input are found under it. Optional with wire:model, which then names it.
id null Defaults to one made from the name (or the wire:model property).
type 'text' Any text-like type: text, email, url, tel, search… (email, url and tel get the matching autocomplete).
label null Shown above the field, and its name for screen readers.
value null The value to show. Old input wins after a failed submit; with wire:model and no value, the bound Livewire property.
placeholder null Shown while it's empty.
error null An error message of your own; otherwise the validation error for the name, from the session or Livewire.
info null A hint under the field.
bag 'default' Which error bag to read the error from.
disabled false Greyed out: it can't be changed.
readonly false Shown, and submitted, but it can't be edited.
prefix null Text at the start, inside the field (e.g. https://).
suffix null Text or a small control at the end, inside the field (e.g. a unit).
icon null An icon name, shown at the start.
counter false With maxlength: a live count under the field (12 / 40).

Accessibility

All 4 examples above are checked with axe-core against the WCAG 2.2 A and AA rules, in the light theme and the dark one, both as the page draws and with each popover, dialog, toast and tooltip opened, on every change. A change that fails can't be merged. Where axe can't decide, such as contrast on SVG text, the test measures the colours itself instead of letting it pass.

Automated checks can't judge everything: how it sounds in a screen reader, and how it feels to use from the keyboard, still need a person. Check those on your own pages too.

Source

What bladewell:add text-input writes to your app with the default namespaces. Prefer to copy by hand? Take these files, plus the ones from the components it also adds and Field, and the theme and base CSS.

resources/views/components/widget/text-input/index.blade.php Show
index.blade.php
app/View/Widget/ElementIds.php Show
ElementIds.php
app/View/Widget/FormField.php Show
FormField.php