Input

A single-line text field.

Usage

Code
import { Input } from '@leverui/components';
Code
<Input />

Examples

Variants

Use the variant prop to change the visual style of the input.

Sizes

Use the size prop to change the size of the input.

Helper Text

Pair the input with the Field component to add helper text.

We'll never share your email.

Error Text

Pair the input with the Field component to add error text.

This field is required

Field

Compose the input with the Field component to add a label, helper text, and error text.

Hook Form

Here's an example of how to integrate the input with a native Solid form submission.

Element

Use the startElement and endElement on the InputGroup component to add an element to the start and end of the input.

Start Icon

Reserve space for the long inline URL prefix.

Start Text

https://

Place currency and unit text inside the input edges.

Start and End Text

$
USD

Show a search symbol and keyboard shortcut within one field.

Kbd

⌘K

Pair an inline URL prefix with a selectable domain.

Select

https://

Addon

Use the InputAddon and Group components to add an addon to the input.

Start Addon

https://

Attach the domain suffix outside the field border.

End Addon

.com

Attach currency and unit labels on both edges.

Start and End Addon

$
USD

Disabled

Use the disabled prop to disable the input.

Button

Use the Group component to attach a button to the input.

Focus and Error Color

Use the --leverui-input-focus-color and --leverui-input-error-color CSS custom properties to change the color of the input when it is focused or in an error state.

Placeholder Style

Use the ::placeholder pseudo-element in CSS to style the placeholder text.

Floating Label

Here's an example of how to build a floating label to the input.

Mask

Here's an example of formatting the input's value on each edit to mask its shape.

Character Counter

Here's an example of how to add a character counter to the input.

0 / 20

Card Number

Here's an example of using usePaymentInputs to create a card number input.

You can create a full card inputs for a card number, expiry date, and CVC.

Clear Button

Combine the Input and CloseButton components to create a clear button. This is useful for building search inputs.

Guides

Native control

A plain HTML input with Lever UI styles. Inside Field.Root, the field gives it the label and description IDs and the required, disabled, read-only, and invalid states.

Sizes and variants

size: 2xs, xs, sm, md, lg, xl, 2xl. Default: md. variant: outline, subtle, flushed. Default: outline. Both take a value per breakpoint (sm, md, lg, xl, 2xl). Your CSS can select the data-size-* and data-variant-* attributes they set on the input.

InputPropsProvider sets default props for the inputs inside it. The defaults are reactive. A prop on an input wins.

Field composition

Code
import { Field, Input } from '@leverui/components';

<Field.Root id="email" required>
  <Field.Label>Email</Field.Label>
  <Input type="email" />
  <Field.HelperText>We will send a receipt here.</Field.HelperText>
  <Field.ErrorText>Enter a valid email address.</Field.ErrorText>
</Field.Root>;

Set invalid or disabled on Field.Root to update the input and the state screen readers announce. An input on its own accepts required, disabled, and readOnly.

Values in Solid

defaultValue sets a starting value and the input tracks its own text. To control it, read value from a signal and update the signal in onInput. A form reset restores defaultValue. A controlled input keeps following its signal.

Code
import { createSignal } from 'solid-js';
import { Input } from '@leverui/components';

function AccountName() {
  const [name, setName] = createSignal('');

  function updateName(event: InputEvent & { currentTarget: HTMLInputElement }) {
    setName(event.currentTarget.value);
  }

  return <Input aria-label="Account name" value={name()} onInput={updateName} />;
}

as="textarea" renders a multiline textarea with its standard attributes and ref type. asChild takes a Solid render function that receives the input's merged props.

Payment fields

usePaymentInputs formats and checks the card number, expiry date, and security code as people type, and detects the card brand. Spread the props its functions return onto Input, as in the Card Number and Card Details examples.

Props

PropDefaultTypeDescription
colorPalettegraystringColor palette, built-in or your own.
sizemd'2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' or responsive mapInput size.
variantoutline'outline' | 'subtle' | 'flushed' or responsive mapInput style.
asinputNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the input's props.
unstyledfalsebooleanTurn off the Lever UI styles.

Also accepts the standard input attributes and events, a ref, class, and style.

Customize with CSS

Import your CSS after styles.css.

Code
.account-form {
  --leverui-colors-bg-muted: #f4f0fa;
}

.account-form .leverui-input {
  border-radius: 0.5rem;
}

Focus and invalid colors: set --leverui-input-focus-color or --leverui-input-error-color on the input or an element that contains it.

Use style for a one-off change, unstyled to turn off the Lever UI styles, and your own CSS to add variants. Input Addon, Element, and Group are separate components that go around the input.