For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/en/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/en/components/input.md.

Input

Enter single-line text, such as a name, email address or search query.

Basic usage

Use FormField to provide an accessible label. Placeholder text is not a replacement for a label.

basic.tsx
import { Form, FormField, Input } from '@ifhover/leaf-ui';

export function InputBasic() {
  return (
    <Form layout="vertical" onSubmit={(event) => event.preventDefault()}>
      <FormField label="Project name">
        <Input name="project" placeholder="Name your project" />
      </FormField>
    </Form>
  );
}

Examples

Prefixes and suffixes

Add an icon or text with prefix and suffix. These are decorative; place interactive controls outside the input.

affixes.tsx
import { Form, FormField, Input } from '@ifhover/leaf-ui';
import { Search } from 'lucide-react';

export function InputAffixes() {
  return (
    <Form layout="vertical">
      <FormField label="Search projects">
        <Input prefix={<Search />} placeholder="Enter a keyword" />
      </FormField>
      <FormField label="Domain">
        <Input suffix=".com" placeholder="example" />
      </FormField>
    </Form>
  );
}

Password input

Set type="password" to mask the input. Control visibility with visible and onVisibleChange, customize the toggle with visibilityIcon, or hide it with visibilityToggle={false}.

password.tsx
import { Form, FormField, Input } from '@ifhover/leaf-ui';
import { Eye, EyeOff } from 'lucide-react';
import { useState } from 'react';

export function InputPassword() {
  const [visible, setVisible] = useState(false);
  return (
    <Form layout="vertical">
      <FormField label="Password">
        <Input type="password" placeholder="Enter password" autoComplete="new-password" />
      </FormField>
      <FormField label="Controlled password">
        <Input
          type="password"
          defaultValue="leaf-garden"
          visible={visible}
          onVisibleChange={setVisible}
          visibilityIcon={(shown) => (shown ? <EyeOff size={16} /> : <Eye size={16} />)}
        />
      </FormField>
      <FormField label="No visibility toggle">
        <Input type="password" placeholder="No visibility toggle" visibilityToggle={false} />
      </FormField>
    </Form>
  );
}

Clear input

Set allowClear to show a clear button. Clearing fires onChange with an empty input value.

Current text: Leaf Garden
clear.tsx
import { Form, FormField, Input, Text } from '@ifhover/leaf-ui';
import { useState } from 'react';

export function InputClear() {
  const [value, setValue] = useState('Leaf Garden');

  return (
    <Form layout="vertical" onSubmit={(event) => event.preventDefault()}>
      <FormField label="Project name">
        <Input value={value} onChange={(event) => setValue(event.target.value)} allowClear />
      </FormField>
      <Text tone="muted" role="status">
        Current text: {value || 'Empty'}
      </Text>
    </Form>
  );
}

Character count

Use showCount for a built-in or custom count, and maxLength to limit input length.

11 / 30
4 characters
count.tsx
import { Form, FormField, Input } from '@ifhover/leaf-ui';

export function InputCount() {
  return (
    <Form layout="vertical">
      <FormField label="Default count">
        <Input defaultValue="Leaf Garden" showCount maxLength={30} />
      </FormField>
      <FormField label="Custom count">
        <Input defaultValue="Leaf" showCount={(value) => `${value.length} characters`} />
      </FormField>
    </Form>
  );
}

Sizes

Choose from sm, md and lg.

sizes.tsx
import { Form, FormField, Input } from '@ifhover/leaf-ui';

export function InputSizes() {
  return (
    <Form layout="vertical">
      <FormField label="Small">
        <Input size="sm" placeholder="Project name" />
      </FormField>
      <FormField label="Medium">
        <Input size="md" placeholder="Project name" />
      </FormField>
      <FormField label="Large">
        <Input size="lg" placeholder="Project name" />
      </FormField>
    </Form>
  );
}

States

disabled prevents interaction; readOnly keeps content readable without allowing edits. status changes appearance without performing validation. Use FormField for error messages.

states.tsx
import { Form, FormField, Input } from '@ifhover/leaf-ui';

export function InputStates() {
  return (
    <Form layout="vertical" onSubmit={(event) => event.preventDefault()}>
      <FormField label="Read only">
        <Input defaultValue="Leaf Garden" readOnly />
      </FormField>
      <FormField label="Disabled">
        <Input disabled placeholder="Currently unavailable" />
      </FormField>
      <FormField label="Error" error="Project name is required.">
        <Input placeholder="Enter a project name" />
      </FormField>
      <FormField label="Warning">
        <Input status="warning" defaultValue="A similar name already exists" />
      </FormField>
    </Form>
  );
}

Controlled input and Enter

Manage content with value and onChange. onPressEnter runs on Enter, except during IME composition or when the keyboard event has been prevented.

Submitted: Waiting for input
controlled.tsx
import { Form, FormField, Input, Text } from '@ifhover/leaf-ui';
import { useState } from 'react';

export function InputControlled() {
  const [value, setValue] = useState('');
  const [submitted, setSubmitted] = useState('');
  return (
    <Form layout="vertical" onSubmit={(event) => event.preventDefault()}>
      <FormField label="Enter and submit">
        <Input
          value={value}
          placeholder="Type and press Enter"
          onChange={(event) => setValue(event.target.value)}
          onPressEnter={() => setSubmitted(value)}
        />
      </FormField>
      <Text tone="muted" role="status">
        Submitted: {submitted || 'Waiting for input'}
      </Text>
    </Form>
  );
}

Search input

InputSearch calls onSearch with the current value when its search button is clicked or Enter is pressed.

Search: No search yet
search.tsx
import { Form, FormField, InputSearch, Text } from '@ifhover/leaf-ui';
import { useState } from 'react';

export function InputSearchDemo() {
  const [query, setQuery] = useState('');

  return (
    <Form layout="vertical" onSubmit={(event) => event.preventDefault()}>
      <FormField label="Search projects">
        <InputSearch placeholder="Enter a keyword" enterButton="Search" onSearch={setQuery} />
      </FormField>
      <Text tone="muted" role="status">
        Search: {query || 'No search yet'}
      </Text>
    </Form>
  );
}

Input groups

Use InputGroup to join adjacent controls. Give each input in the group its own accessible name.

group.tsx
import { Form, FormField, Input, InputGroup, Select } from '@ifhover/leaf-ui';
import { useId } from 'react';

export function InputGroupDemo() {
  const protocolId = useId();
  const domainId = useId();

  return (
    <Form layout="vertical" onSubmit={(event) => event.preventDefault()}>
      <FormField label="URL" htmlFor={domainId}>
        <InputGroup aria-label="URL">
          <Select
            id={protocolId}
            aria-label="Protocol"
            style={{ width: 110 }}
            defaultValue="https"
            options={[
              { value: 'https', label: 'https://' },
              { value: 'http', label: 'http://' },
            ]}
          />
          <Input id={domainId} aria-label="Domain" placeholder="example.com" />
        </InputGroup>
      </FormField>
    </Form>
  );
}

API

Input API

Forms

Set name to include the value in FormData. Uncontrolled fields restore their initial value on form reset; reset controlled values in application state. See Form for labels, help and errors.

PropertyTypeDefaultDescription
size'sm' | 'md' | 'lg''md'Control size
status'error' | 'warning'—Validation appearance
prefix / suffixReactNode—Decorative content before / after the input
onPressEnterKeyboardEventHandler<HTMLInputElement>—Runs when Enter is pressed
typeHTMLInputTypeAttribute'text'Input type; use 'password' for passwords
visibilityTogglebooleantrueShow the password visibility toggle
visible / defaultVisiblebooleanfalseControlled / initial password visibility
onVisibleChange(visible: boolean) => void—Password visibility change
visibilityIcon(visible: boolean) => ReactNode—Custom visibility toggle icon
value / defaultValuestring | number | readonly string[]—Controlled value / initial uncontrolled value
onChangeChangeEventHandler<HTMLInputElement>—Read event.target.value
disabled / readOnlybooleanfalseDisabled / read-only
refRef<HTMLInputElement>—DOM reference
allowClearbooleanfalseShow clear button
onClear() => void—After clearing; onChange also fires
showCountboolean | ((value: string, maxLength?: number) => ReactNode)falseShow or customize the character count

InputSearchProps API

Props for the submission behavior and actions of a search input.

PropertyTypeDefaultDescription
size'sm' | 'md' | 'lg''md'Input size.
status'error' | 'warning'—Display state
prefixReactNode—Content before the input
suffixReactNode—Content after the input
allowClearbooleanfalseShow the clear button
onClear() => void—Called after clearing the input
showCountboolean | ((value: string, maxLength?: number) => ReactNode)falseDisplay count or a custom renderer
visibilityTogglebooleantrueShow the password visibility toggle
visibleboolean—Controlled password visibility
defaultVisiblebooleanfalseInitial password visibility
onVisibleChange(visible: boolean) => void—Password visibility change
visibilityIcon(visible: boolean) => ReactNode—Custom password visibility icon
onPressEnterKeyboardEventHandler<HTMLInputElement>—Called when Enter is pressed
onSearch(value: string) => void—Search or Enter callback
loadingbooleanfalseLoading state
enterButtonReactNode—Search button label; omitted shows an icon

InputGroupProps API

Props for combining related input controls.

PropertyTypeDefaultDescription
compactboolean—Join adjacent controls