Input

Displays a form input field for a single line of text.

Encrypted at rest. Rotate it any time.
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { VStack } from "@/components/ui/stack"
import { Text } from "@/components/ui/text"
import { widths } from "@/theme/widths"

export default function InputDemo() {
  return (
    <VStack gap={2} xstyle={widths.xs}>
      <Label htmlFor="input-demo-key">API key</Label>
      <Input id="input-demo-key" type="password" placeholder="sk-..." />
      <Text size="sm" tone="muted">
        Encrypted at rest. Rotate it any time.
      </Text>
    </VStack>
  )
}

Installation

pnpm dlx shadcn@latest add @arene/input

Needs the arene setup first.

Usage

import { Input } from "@/components/ui/input"
<Input type="email" placeholder="me@example.com" />

Basic

import { Input } from "@/components/ui/input"
import { widths } from "@/theme/widths"

export default function InputBasic() {
  return <Input placeholder="Enter text" xstyle={widths.xs} />
}

Label

Pair the input with a Label and match htmlFor to the input's id. A Field adds the description and error text around it.

import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { VStack } from "@/components/ui/stack"
import { widths } from "@/theme/widths"

export default function LabelDemo() {
  return (
    <VStack gap={2} xstyle={widths.xs}>
      <Label htmlFor="label-demo-email">Email</Label>
      <Input id="label-demo-email" type="email" placeholder="me@example.com" />
    </VStack>
  )
}

Disabled

Set disabled on Field to disable its control and dim its label, or on a bare control directly.

import { Field, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { VStack } from "@/components/ui/stack"
import { widths } from "@/theme/widths"

function BareDisabled() {
  return (
    <VStack gap={2} xstyle={widths.xs}>
      <Label htmlFor="input-disabled-email" disabled>
        Email
      </Label>
      <Input id="input-disabled-email" type="email" placeholder="me@example.com" disabled />
    </VStack>
  )
}

export default function DisabledExample() {
  return (
    <VStack gap={5}>
      <BareDisabled />
      <Field disabled>
        <FieldLabel>Email</FieldLabel>
        <Input type="email" placeholder="me@example.com" />
      </Field>
    </VStack>
  )
}

Invalid

Set invalid on Field to style its control, or aria-invalid on a bare control. The examples show both.

import { Input } from "@/components/ui/input"
import { Field, FieldLabel, FieldError } from "@/components/ui/field"
import { Label } from "@/components/ui/label"
import { VStack } from "@/components/ui/stack"

export default function InputInvalid() {
  return (
    <VStack gap={5} width="100%" maxWidth="24rem">
      <VStack gap={2}>
        <Label htmlFor="input-invalid-bare">Email</Label>
        <Input
          id="input-invalid-bare"
          defaultValue="not-an-email"
          aria-invalid
          aria-describedby="input-invalid-bare-error"
        />
        <FieldError id="input-invalid-bare-error">Enter a valid email address.</FieldError>
      </VStack>
      <Field invalid>
        <FieldLabel>Email</FieldLabel>
        <Input defaultValue="not-an-email" />
        <FieldError>Enter a valid email address.</FieldError>
      </Field>
    </VStack>
  )
}

File

Use type="file" for a file input. The browser's own button is restyled to the control's type scale so the height does not change.

import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { VStack } from "@/components/ui/stack"
import { widths } from "@/theme/widths"

export default function InputFile() {
  return (
    <VStack gap={2} xstyle={widths.xs}>
      <Label htmlFor="input-file-avatar">Avatar</Label>
      <Input id="input-file-avatar" type="file" accept="image/*" />
    </VStack>
  )
}

Required

Use the required attribute for required inputs. Mark the label too, since required alone is only announced once the control has focus.

import * as stylex from "@stylexjs/stylex"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { VStack } from "@/components/ui/stack"
import { color } from "@/theme/tokens.stylex"
import { widths } from "@/theme/widths"

const styles = stylex.create({
  marker: { color: color.destructive },
})

export default function InputRequired() {
  return (
    <VStack gap={2} xstyle={widths.xs}>
      <Label htmlFor="input-required-name">
        Workspace name
        <span {...stylex.props(styles.marker)} aria-hidden>
          *
        </span>
      </Label>
      <Input id="input-required-name" placeholder="Euler Labs" required />
    </VStack>
  )
}

Inline

Put the input and a button in an HStack for a one-line form.

import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { HStack } from "@/components/ui/stack"
import { widths } from "@/theme/widths"

export default function InputInline() {
  return (
    <HStack gap={2} xstyle={widths.xs}>
      <Input type="email" placeholder="me@example.com" aria-label="Email" />
      <Button variant="outline">Subscribe</Button>
    </HStack>
  )
}

Grid

Lay several inputs out in a grid to place them side by side.

import * as stylex from "@stylexjs/stylex"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { VStack } from "@/components/ui/stack"
import { space } from "@/theme/tokens.stylex"

const styles = stylex.create({
  grid: {
    display: "grid",
    gridTemplateColumns: "1fr 1fr",
    gap: space.s4,
    width: "100%",
    maxWidth: "26rem",
  },
})

export default function InputGrid() {
  return (
    <div {...stylex.props(styles.grid)}>
      <VStack gap={2}>
        <Label htmlFor="input-grid-first">First name</Label>
        <Input id="input-grid-first" placeholder="Ada" />
      </VStack>
      <VStack gap={2}>
        <Label htmlFor="input-grid-last">Last name</Label>
        <Input id="input-grid-last" placeholder="Lovelace" />
      </VStack>
    </div>
  )
}

Input group

To put an icon, a prefix or a button inside the field, wrap it in InputGroup. The input detects the group and drops its own border, fill and ring so the group can draw them once.

⌘K
import * as stylex from "@stylexjs/stylex"
import { InputGroup, InputGroupAddon, InputGroupText } from "@/components/ui/input-group"
import { Input } from "@/components/ui/input"
import { MagnifyingGlassIcon } from "@phosphor-icons/react/dist/csr/MagnifyingGlass"
import { width } from "@/theme/tokens.stylex"

const styles = stylex.create({
  group: { maxWidth: width.xs },
})

export default function InputInputGroup() {
  return (
    <InputGroup xstyle={styles.group}>
      <Input placeholder="Search docs" aria-label="Search docs" />
      <InputGroupAddon>
        <MagnifyingGlassIcon aria-hidden="true" />
      </InputGroupAddon>
      <InputGroupAddon align="inline-end">
        <InputGroupText>⌘K</InputGroupText>
      </InputGroupAddon>
    </InputGroup>
  )
}

Button group

To attach a button to the outside of the field, use ButtonGroup. Square the input's trailing corners yourself. The group's joining rules apply to Button, which reads the group through context, and Input does not.

import * as stylex from "@stylexjs/stylex"
import { Button } from "@/components/ui/button"
import { ButtonGroup } from "@/components/ui/button-group"
import { Input } from "@/components/ui/input"
import { CopyIcon } from "@phosphor-icons/react/dist/csr/Copy"
import { widths } from "@/theme/widths"

const styles = stylex.create({
  input: {
    flexGrow: 1,
    minWidth: 0,
    borderStartEndRadius: 0,
    borderEndEndRadius: 0,
    borderInlineEndWidth: 0,
  },
})

export default function InputButtonGroup() {
  return (
    <ButtonGroup xstyle={widths.xs} aria-label="Invite link">
      <Input
        readOnly
        defaultValue="https://arene.style/invite/8fa2"
        aria-label="Invite link"
        xstyle={styles.input}
      />
      <Button variant="outline" size="icon" aria-label="Copy link">
        <CopyIcon aria-hidden="true" />
      </Button>
    </ButtonGroup>
  )
}

Below the md breakpoint the font size is 16px rather than 14px. iOS Safari zooms the page when a focused control's text is any smaller, and the zoom does not reverse on blur.

API reference

Pass render to replace a part's element or compose it with another component.

Input wraps the Base UI Input part and accepts its props, including defaultValue, value and onValueChange. See the Base UI reference.

Input

PropTypeDefault
typeevery <input> typetext
disabledbooleanfalse
aria-invalidboolean—
onValueChange(value: string, details) => void—
renderReactElement | (props, state) => Element—
xstyleStyleXStyles—
classNamestring—

Inside an InputGroup the group's disabled and invalid win. An input can be disabled on its own, but it cannot opt out of a disabled group.

inputStyles

The style maps behind the component. Spread them onto any element.

KeyWhat it is
baseThe control: frame, fill, type scale, placeholder, disabled
invalidThe destructive border and ring
inGroupThe frameless form an InputGroup member takes

base is three styles, in merge order: the control's own, the shared states.focusRing, and states.fieldSurface, which is the hairline edge, the fill and the drop. invalid is states.invalidRing from theme/states.ts. Set a border of your own through --arene-border-color rather than borderColor. A flat borderColor replaces the property with all of its conditions, so the ring loses its focus colour.

Data attributes

AttributeOnEffect
data-slot="input"a standalone inputTargets the control from a parent
data-slot="input-group-control"an input in a groupWhat InputGroup watches to draw its ring
data-disabled, data-valid, data-dirtythe controlBase UI writes them inside a Field