PeakUI

InputGroup

An input or a text area with a prefix and a suffix inside one shared frame.

Usage

import {InputGroup} from "@peakui/react";

Anatomy

import {InputGroup} from "@peakui/react";

export default () => (
  <InputGroup>
    <InputGroup.Prefix />
    <InputGroup.Input /> {/* or <InputGroup.TextArea /> */}
    <InputGroup.Suffix />
  </InputGroup>
);

The group draws the frame and the focus ring; the control inside it is borderless. Clicking the prefix or the suffix focuses the control, unless the click lands on something interactive of its own, such as a button.

Examples

With Prefix

With Suffix

With Prefix and Suffix

With a Button

A button in the suffix keeps its own behavior: pressing it does not move focus to the input.

With TextArea

Variants

In a TextField

Inside a TextField the group takes the field's label, invalid and disabled states, and its variant.

Customization

Tailwind CSS

<InputGroup className="rounded-full">
  <InputGroup.Prefix className="text-accent">@</InputGroup.Prefix>
  <InputGroup.Input aria-label="Username" />
</InputGroup>

Global CSS

@layer components {
  .input-group {
    --input-group-radius: var(--radius-lg);
  }

  .input-group__prefix,
  .input-group__suffix {
    @apply text-xs uppercase;
  }
}

Styling Reference

CSS Classes

The InputGroup component uses these CSS classes (view source styles):

Base & Variant Classes

  • .input-group - The frame around the control and its slots
  • .input-group--primary - Primary variant
  • .input-group--secondary - Secondary variant
  • .input-group--full-width - Stretches to the container's width

Element Classes

  • .input-group__input - The control, both the input and the text area
  • .input-group__prefix - Content before the control
  • .input-group__suffix - Content after the control

Slots

  • [data-slot="input-group"]
  • [data-slot="input-group-input"]
  • [data-slot="input-group-textarea"]
  • [data-slot="input-group-prefix"]
  • [data-slot="input-group-suffix"]

CSS Variables

VariablePurpose
--input-group-bgBackground color
--input-group-bg-hoverBackground color when hovered
--input-group-bg-focusBackground color when the control is focused
--input-group-fgText color
--input-group-placeholderPlaceholder color
--input-group-borderBorder color
--input-group-border-hoverBorder color when hovered
--input-group-border-focusBorder color when the control is focused
--input-group-radiusCorner radius
--input-group-shadowBox shadow

Interactive States

  • Hover: :hover or [data-hovered]
  • Focus: the control's :focus or [data-focused], styled on the group itself. [data-focus-within] is not styled: it is also set when a button in the prefix or suffix has focus, and the group should not look like a focused field then
  • Invalid: [data-invalid] or [aria-invalid="true"]
  • Disabled: [data-disabled] or [aria-disabled="true"]

API Reference

InputGroup

PropTypeDefaultDescription
variant'primary' | 'secondary''primary'Surface style. Inside a TextField it defaults to the field's variant
fullWidthbooleanfalseWhether the group takes the full width of its container
isDisabledbooleanfalseWhether the group is disabled. Set by the field when inside a TextField
isInvalidbooleanfalseWhether the group is invalid. Set by the field when inside a TextField
childrenReact.ReactNode | (values: GroupRenderProps) => React.ReactNode-The control and its slots
classNamestring | (values: GroupRenderProps) => string-Additional classes, or a function of the group's state

InputGroup.Input

Renders an <input> and accepts its attributes, such as type, placeholder, value, defaultValue and onChange.

PropTypeDefaultDescription
classNamestring | (values: InputRenderProps) => string-Additional classes, or a function of the input's state

InputGroup.TextArea

Renders a <textarea> and accepts its attributes, such as rows, placeholder, value, defaultValue and onChange.

PropTypeDefaultDescription
classNamestring | (values: InputRenderProps) => string-Additional classes, or a function of the text area's state

InputGroup.Prefix

PropTypeDefaultDescription
childrenReact.ReactNode-Content shown before the control
classNamestring-Additional classes

InputGroup.Suffix

PropTypeDefaultDescription
childrenReact.ReactNode-Content shown after the control
classNamestring-Additional classes

On this page