InputNew
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 changeImprovedv3.1.4The 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.
- v3.1.4ImprovedThe field is made of Button's glass now, as clear and as full of light as the GlassButton beside it (
tint0.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. - v3.1.4ImprovedGlassInputError takes
onShownChange: it is called withtrueas the pill comes in andfalseas 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. - v3.1.0NewInput 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
GlassInputErrorrises 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. - All changes →
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@latest add https://liquidglass.onemorethink.dev/r/input.jsonThe 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
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="[email protected]" 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
| Prop | Type | Default |
|---|---|---|
size32, 40 or 48 px tall. | 'sm' | 'md' | 'lg' | 'md' |
startInside the glass, before the text: an icon, or text such as | ReactNode | — |
endInside the glass, after the text and before the droplet. | ReactNode | — |
clearableA clear button that pinches off the field's end as a droplet while there is text. | boolean | true |
clearLabelThe clear button's accessible name. Write it in the page's language. | string | 'Clear' |
shakeShake 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. | boolean | true |
value / defaultValue / onValueChangeAs on UI SDK's Input: the value, for a controlled field, or the one it starts with; and the change, with its reason ( | UI SDK Input | — |
controllerFrom | InputController | — |
materialClear glass frosts and bends what is behind; tinted takes the colour of your own | 'clear' | 'tinted' | 'clear' |
tintClear glass: how much tint covers the backdrop (0–1), as on Button. | number | 0.6 |
blurClear glass: how much the backdrop is frosted, in px; 0 leaves it clear, as on Button. | number | 0 |
classNameOn the glass: its width (18rem by default) and, for tinted glass, its | string | — |
inputClassNameOn the native input inside. | string | — |
GlassInputError matchWhen the message shows, as on UI SDK's FieldError: a validity flag ( | ValidityKey | boolean | — |
GlassInputError hideAfterHow long the pill stays before it goes up and out (ms); | number | 2000 |
GlassInputError onShownChangeCalled with | (shown: boolean) => void | — |
…Every native input prop goes to the input: | 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 oraria-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, reportsclear-pressand puts the caret back. - Inside a Field, an invalid value marks the input
aria-invalidand 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.
Sponsors
Liquid Glass is built and maintained by one person. If it saves you time, you can sponsor the work.