Skip to content

Input

Input

A single-line text input with Fluent styling: a 1px border with an accessible bottom stroke, a primary bottom border while focused, optional contentBefore/contentAfter slots and an optional error message. Inside a Field it picks up the label, hint, error, required (native attribute) and invalid state automatically.

size resolves from its own prop, then the surrounding Field's size, then WaveProvider inputDefaults.size, else 'medium'; appearance from its own prop, then WaveProvider inputDefaults.appearance, else 'outline'; both render as data-size and data-appearance on the element that draws the field (the <input>, or the wrapper with slot content).

Every prop reaches the <input>, except with slot content: then a bordered <span> wrapper draws the field and receives className, style and hidden (ref stays on the input).

Examples

Default

export const Default: Story = {};

With Content Before

export const WithContentBefore: Story = {
  args: {
    'aria-label': 'Search',
    placeholder: 'Search...',
    contentBefore: { children: '🔍', 'aria-hidden': true },
  },
};

With Content After

kg
export const WithContentAfter: Story = {
  args: {
    'aria-label': 'Weight',
    placeholder: '0',
    contentAfter: { children: 'kg' },
  },
};

Error

This field is required
export const Error: Story = {
  args: {
    'aria-label': 'Email',
    placeholder: 'you@example.com',
    error: 'This field is required',
    defaultValue: '',
  },
};

Error Flag Only

export const ErrorFlagOnly: Story = {
  args: {
    'aria-label': 'Email',
    placeholder: 'you@example.com',
    error: true,
  },
};

Disabled

export const Disabled: Story = {
  args: {
    'aria-label': 'Disabled input',
    placeholder: 'Disabled',
    disabled: true,
  },
};

Sizes And Appearances

export const SizesAndAppearances: Story = {
  render: (args) => (
    <SizeAppearanceGrid
      render={(size, appearance) => (
        <Input
          {...args}
          size={size}
          appearance={appearance}
          aria-label={`${size} ${appearance}`}
          placeholder={`${size} ${appearance}`}
        />
      )}
    />
  ),
};

Props

NameTypeRequiredDefaultDescription
errorstring | booleanNo

Validation error.
- A non-empty string renders the message in a role="alert" element **after** the field (a sibling, so it does not change which element receives ref, className or style) and links it through aria-describedby and aria-errormessage. Inside a Field that renders its own error, the message is not repeated.
- true only marks the input invalid (aria-invalid and the error border), as in 0.4.

The error border also shows whenever the input ends up aria-invalid="true" without this prop (an error on the surrounding Field, or your own aria-invalid). Your own aria-invalid={false} (or "false") wins over this prop: the input is reported valid and shows neither the error border nor the message. Use Field (label, hint, error) for a complete field layout.

errorMessagePropsInputErrorMessagePropsNo

Props of the error message element (id, className, …) rendered for a string error.

size'small' | 'medium' | 'large'No

Size of the field: small (24px tall), medium (32px) or large (40px). Default: the surrounding Field's size, else WaveProvider inputDefaults.size, else 'medium'. A value outside the three sizes (a number from untyped code included) renders as if size were not set. The native size attribute, the visible width in characters, is htmlSize.

htmlSizenumberNo

The native size attribute: the visible width of the field in characters.

appearance'outline' | 'underline' | 'filled-darker' | 'filled-lighter'No

Look of the field: outline (a full border), underline (a bottom stroke only), filled-darker or filled-lighter (a fill without a visible stroke: give the field a visible label). Default: WaveProvider inputDefaults.appearance, else 'outline'.

contentBeforeSlot<'span'>No

Slot rendered before the input text (e.g., an icon). With content in either slot, a bordered <span> around the input draws the field: it receives className, style and hidden, while ref, id, aria-*, data-*, handlers and native attributes stay on the <input>. A value that renders nothing (false, '', []) is no slot.

contentAfterSlot<'span'>No

Slot rendered after the input text (e.g., a suffix). Same wrapper as contentBefore.

onValueChange(value: string) => voidNo

Called with the new string value on every change, next to the native onChange event handler (onValueChange={setName} instead of onChange={(e) => setName(e.target.value)}).

refReact.Ref<HTMLInputElement>No

Ref to the <input> element (also with contentBefore/contentAfter).

slotProps{ root?: SlotPartWithRef<'span', HTMLElement>; input?: SlotPart<'input'> }No

Props for the elements the Input draws, by part, merged into each part's own (Fluent UI's root and input slot props): your classes after the part's (yours win a conflict), your styles over its styles, your handlers before its handlers (preventDefault() in yours skips the Input's handling of the event, its own on… prop included), your ref beside its ref, and your ids added to its aria-labelledby and aria-describedby. Every attribute the Input sets on a part is locked and keeps the Input's value (set it through the Input's own props, which win over these); you add the attributes it does not set. A part takes no children.

Without contentBefore and contentAfter the field is one <input>, the root and the input at once: root and input both apply to it, input after root, so a prop set in both takes the value of input.

Any other prop is passed to the element it renders (HTMLInputElement).

Parts

  • root
  • input

Stable class names

PartClass
rootwave-input
inputwave-input__input
contentBeforewave-input__content-before
contentAfterwave-input__content-after
errorMessagewave-input__error-message