TextField

v0.1.3

Labeled text input with size variants, helper/error text, and common HTML input event handlers.

View as Markdown

Install

npx shadcn@latest add @signalos/text-field

Requires a configured @signalos registry and a valid SIGNALOS_REGISTRY_TOKEN - get access. Registry dependencies (@signalos/tokens, @signalos/utils, @signalos/skeleton) are pulled automatically.

Preview

Example & code

text-field.example.tsx
import * as React from "react"
import { Mail } from "lucide-react"

import { TextField } from "./TextField"

export default function Example() {
  const [email, setEmail] = React.useState("")

  return (
    <div className="max-w-sm">
      <TextField
        label="Email"
        type="email"
        placeholder="Enter your email"
        value={email}
        onChange={(e) => setEmail(e.target.value)}
        leadingIcon={<Mail className="h-4 w-4" />}
        helperText="We'll never share your email."
      />
    </div>
  )
}

Props

BaseInputProps

PropTypeDefaultDescription
idstring | undefined-Unique identifier for the input. Used to associate the input with a `<label>` using the `htmlFor` attribute.
namestring | undefined-Name of the input. Used when submitting forms.
typeHTMLInputTypeAttribute | undefined-Specifies the type of input. Common values: - `"text"` - `"email"` - `"password"` - `"number"` - `"search"` - `"tel"` - `"url"`
valuestring | number | readonly string[] | undefined-Current controlled value of the input.
defaultValuestring | number | readonly string[] | undefined-Initial value for an uncontrolled input.
placeholderstring | undefined-Placeholder text displayed when the input is empty.
disabledboolean | undefined-Disables the input. The user cannot edit or focus the field.
requiredboolean | undefined-Marks the field as required. Used for form validation.
readOnlyboolean | undefined-Makes the input read-only. Users can focus and copy the value but cannot edit it.
autoCompletestring | undefined-Enables browser autocomplete. Example: - `"email"` - `"username"` - `"current-password"`
autoFocusboolean | undefined-Automatically focuses the input when the component is mounted.
maxLengthnumber | undefined-Maximum number of characters allowed.
minLengthnumber | undefined-Minimum number of characters required.
minstring | number | undefined-Minimum numeric value. Used with number inputs.
maxstring | number | undefined-Maximum numeric value. Used with number inputs.
stepstring | number | undefined-Increment/decrement interval. Used with number inputs.
patternstring | undefined-Regular expression used for validation.
inputMode"text" | "url" | "none" | "search" | "tel" | "email" | "numeric" | "decimal" | undefined-Hints the appropriate keyboard on mobile devices. Example: - `"numeric"` - `"decimal"` - `"email"`
onChangeChangeEventHandler<HTMLInputElement> | undefined-Called whenever the input value changes.
onFocusFocusEventHandler<HTMLInputElement> | undefined-Called when the input receives focus.
onBlurFocusEventHandler<HTMLInputElement> | undefined-Called when the input loses focus.
onKeyDownKeyboardEventHandler<HTMLInputElement> | undefined-Called when a keyboard key is pressed down.
onKeyUpKeyboardEventHandler<HTMLInputElement> | undefined-Called when a keyboard key is released.

TextFieldProps

PropTypeDefaultDescription
labelReactNode-Label displayed above the input.
helperTextReactNode-Helper text displayed below the input. Usually used for hints or descriptions.
errorReactNode-Error message displayed below the input. Usually styled in red.
sizeTextFieldSize | undefined-Controls the overall size of the input. - `sm` → Small - `md` → Medium (default) - `lg` → Large
loadingboolean | undefined-Displays a loading state. Typically shows a loading skeleton or spinner and disables interaction.
linkTextReactNode-Optional clickable text displayed next to the label. Example: "Forgot Password?"
onLinkClick(() => void) | undefined-Callback fired when the link text is clicked.
leadingIconReactNode-Icon displayed at the beginning of the input. Example: `<Search />`
trailingIconReactNode-Icon displayed at the end of the input. Example: `<Eye />`
containerClassNamestring | undefined-Additional classes for the outer container.
labelClassNamestring | undefined-Additional classes for the label.
classNamestring | undefined-Additional classes for the input element.
data-testidstring | undefined-Test identifier used by automated testing tools. Example: `data-testid="email-input"`
idstring | undefined-Unique identifier for the input. Used to associate the input with a `<label>` using the `htmlFor` attribute.
namestring | undefined-Name of the input. Used when submitting forms.
typeHTMLInputTypeAttribute | undefined-Specifies the type of input. Common values: - `"text"` - `"email"` - `"password"` - `"number"` - `"search"` - `"tel"` - `"url"`
valuestring | number | readonly string[] | undefined-Current controlled value of the input.
defaultValuestring | number | readonly string[] | undefined-Initial value for an uncontrolled input.
placeholderstring | undefined-Placeholder text displayed when the input is empty.
disabledboolean | undefined-Disables the input. The user cannot edit or focus the field.
requiredboolean | undefined-Marks the field as required. Used for form validation.
readOnlyboolean | undefined-Makes the input read-only. Users can focus and copy the value but cannot edit it.
autoCompletestring | undefined-Enables browser autocomplete. Example: - `"email"` - `"username"` - `"current-password"`
autoFocusboolean | undefined-Automatically focuses the input when the component is mounted.
maxLengthnumber | undefined-Maximum number of characters allowed.
minLengthnumber | undefined-Minimum number of characters required.
minstring | number | undefined-Minimum numeric value. Used with number inputs.
maxstring | number | undefined-Maximum numeric value. Used with number inputs.
stepstring | number | undefined-Increment/decrement interval. Used with number inputs.
patternstring | undefined-Regular expression used for validation.
inputMode"text" | "url" | "none" | "search" | "tel" | "email" | "numeric" | "decimal" | undefined-Hints the appropriate keyboard on mobile devices. Example: - `"numeric"` - `"decimal"` - `"email"`
onChangeChangeEventHandler<HTMLInputElement> | undefined-Called whenever the input value changes.
onFocusFocusEventHandler<HTMLInputElement> | undefined-Called when the input receives focus.
onBlurFocusEventHandler<HTMLInputElement> | undefined-Called when the input loses focus.
onKeyDownKeyboardEventHandler<HTMLInputElement> | undefined-Called when a keyboard key is pressed down.
onKeyUpKeyboardEventHandler<HTMLInputElement> | undefined-Called when a keyboard key is released.

Supporting types

export type TextFieldSize = "sm" | "md" | "lg"

npm dependencies

lucide-react@^1.7.0

Changelog

text-field

0.1.3

  • Conditional rendering added for the error and help-text slots.

0.1.2

  • Content sync fix to bring source in line with published registry payload.

0.1.1

  • Minor updates.

0.1.0

  • Initial release.