Skip to content

Components

Input New

A text field of frosted glass. Type in it and its clear button pinches off its end as a droplet; clear it and the droplet melts back in. A value that fails its check shakes the field, and its message rises in under it.

Latest change Improved v3.1.4 The field is made of Button's glass now, as clear and as full of light as the GlassButton beside it (tint 0.6 and no frost by default, where it had Search's frosted field glass at 0.74 and 3.5 px), so a field and its button read as one material.
  1. v3.1.4 Improved The field is made of Button's glass now, as clear and as full of light as the GlassButton beside it (tint 0.6 and no frost by default, where it had Search's frosted field glass at 0.74 and 3.5 px), so a field and its button read as one material.
  2. v3.1.4 Improved GlassInputError takes onShownChange: it is called with true as the pill comes in and false as it starts to go, on the same frame. The pill floats and takes no room, so this is how what is below it makes room. The first example uses it: on a phone its Subscribe button goes under the field, in the middle, and moves down out of the message's way while it shows, its glass going with it.
  3. v3.1.0 New Input is a text field of frosted glass on UI SDK's Input. Type in it and its clear button pinches off its end as a droplet; press it and the text goes, the caret stays, and the droplet melts back in. Submit a value that fails its check and the field shakes while GlassInputError rises in under it as a pill, then goes up and out two seconds later: Lué Studio's contact form, frame for frame. It takes a Field's label, text or an icon around the value (start, end), three sizes, and every native input prop.
  4. All changes→
glass-input-basic.svelte

Use it for

  • Short text in a form: a name, an email address, a website, a code.
  • A value someone types once and gets right: a username, a coupon, a reference number.
  • Text with fixed words around it (https://, .com, a unit) that are not part of the value.

Not for

  • Looking in several kinds of things at once, with results: use Search.
  • Choosing from a known list: use Select.
  • Long text over several lines: a textarea.

Installation

npx shadcn-svelte@latest add https://liquidglass.pulse.city/r/input.json

The behaviour (the native field, the form it is in, UI SDK's Field and its label and errors, and the reason each change is made) comes from UI SDK's Input, so Input needs @ui-sdk/core and @ui-sdk/react. The install command adds them at the exact version this was built on: UI SDK is in beta and its API may still change.

Usage

app.tsx
import { Field, FieldLabel } from '@ui-sdk/react/field'
import { GlassInput, GlassInputError } from '@/components/liquid-glass/glass-input'

<form onSubmit={subscribe}>
  <Field name="email">
    <FieldLabel>Email</FieldLabel>
    <GlassInput type="email" required autoComplete="email" placeholder="you@example.com" clearLabel="Clear email" />
    <GlassInputError match="valueMissing">Enter your email address.</GlassInputError>
    <GlassInputError match="typeMismatch">Enter a valid email address.</GlassInputError>
  </Field>
  <GlassButton type="submit">Subscribe</GlassButton>
</form>

Empty, the field is one body of glass. Type, and its clear button pinches off the field's end as a droplet, the body pulling back to make room, and its cross comes in out of a blur once the droplet is out. Press it and the text goes, the caret stays in the field, and the droplet melts back in. The field is a surface: it holds still under the pointer, a press lights it where it lands, and placing the caret melts nothing. Its glass is Button's: clear and as full of light as a GlassButton beside it, so a field and its button are one material. It is clear, so it needs something behind it to bend.

Validation

Submit a form with a value that fails its check (required, type="email", pattern…) and the field shakes from side to side, two pixels each way in 200 ms (inside a Field the whole Field does, its label with it), while its message rises in under it as a pill: from a little below, a little small and blurred, on a spring that just passes its place. Two seconds later the pill goes up, grows and blurs away; submit again and a new one comes in as the old one leaves. The field also shakes when your code marks it invalid (the Field's invalid). GlassInputError is UI SDK's FieldError: put it right after the GlassInput inside the Field, one per message, with the same match. It takes no room of its own (the pill floats over what is below it), and the message stays for screen readers after the pill has gone; hideAfter={0} keeps the pill too. The shake and the pill are Lué Studio's contact form (lue.studio/contact), taken from its code and checked frame by frame against a recording of it.

API reference

PropTypeDefault
size

32, 40 or 48 px tall.

'sm' | 'md' | 'lg''md'
start

Inside the glass, before the text: an icon, or text such as https://. Not part of the value.

ReactNode—
end

Inside the glass, after the text and before the droplet.

ReactNode—
clearable

A clear button that pinches off the field's end as a droplet while there is text.

booleantrue
clearLabel

The clear button's accessible name. Write it in the page's language.

string'Clear'
shake

Shake from side to side when the value fails its check: on a submit, and when the Field marks it invalid. Inside a Field the whole Field shakes, its label and its message too.

booleantrue
value / defaultValue / onValueChange

As on UI SDK's Input: the value, for a controlled field, or the one it starts with; and the change, with its reason (input-change, clear-press, reset, imperative). details.cancel() keeps the text as it was.

UI SDK Input—
controller

From createInputController() of @ui-sdk/react/input: reads, writes, clears and focuses the field from anywhere.

InputController—
material

Clear glass frosts and bends what is behind; tinted takes the colour of your own bg-* class.

'clear' | 'tinted''clear'
tint

Clear glass: how much tint covers the backdrop (0–1), as on Button.

number0.6
blur

Clear glass: how much the backdrop is frosted, in px; 0 leaves it clear, as on Button.

number0
className

On the glass: its width (18rem by default) and, for tinted glass, its bg-*.

string—
inputClassName

On the native input inside.

string—
GlassInputError match

When the message shows, as on UI SDK's FieldError: a validity flag ('valueMissing', 'typeMismatch'…), true for an error of your own, or left out for any problem.

ValidityKey | boolean—
GlassInputError hideAfter

How long the pill stays before it goes up and out (ms); 0 keeps it while the value is wrong. The message stays for screen readers either way.

number2000
GlassInputError onShownChange

Called with true as the pill comes in and false as it starts to go, on the same frame. The pill takes no room, so this is how what is below makes room for it: the example moves its button down on a phone.

(shown: boolean) => void—
…

Every native input prop goes to the input: type, name, placeholder, autoComplete, required, pattern, disabled, readOnly…

input props—

Accessibility

  • A native <input>: text editing, selection, autocomplete and the form behave as they always do. Name it with a Field's label or aria-label.
  • The clear button is a button named by clearLabel. It is in the tab order only while there is text; pressing it empties the field, reports clear-press and puts the caret back.
  • Inside a Field, an invalid value marks the input aria-invalid and the Field's errors describe it.
  • A failed check marks the input aria-invalid, describes it with the message (UI SDK's FieldError) and moves the focus to it. The pill is a picture of that message, hidden from screen readers, and the message stays after the pill has gone.
  • With reduced motion the cross and the pill fade in and out, and the field does not shake; the droplet's own motion is the engine's, which reduced motion stills.
  • Without WebGL2 it is a plain frosted field with a clear button at its end.

Liquid Glass Svelte is open source and MIT licensed. If it saves you time, you can support the project.