# Input group

Joins an input with addons (text, icons) and actions (buttons) into one bordered control.

- Family: form
- Import: `import { InputGroup, InputAddon, InputAction, InputGroupInput } from "@senvenli/react/form";`
- Page: https://design.senvenli.com/docs/components/input-group
- JSON: https://design.senvenli.com/docs/components/input-group.json

## Example: Addons around an input

The frame around your own input; a press on an addon focuses it.

```tsx
import { InputAddon, InputGroup, InputGroupInput } from "@senvenli/react/form";

export default function Example() {
  return (
    <InputGroup dir="ltr">
      <InputAddon>https://</InputAddon>
      <InputGroupInput aria-label="Workspace URL" defaultValue="acme" />
      <InputAddon position="end">.example.com</InputAddon>
    </InputGroup>
  );
}
```

## Examples

### With an action

An icon button inside the frame; its `aria-label` names it.

```tsx
import { InputAction, InputGroup, InputGroupInput } from "@senvenli/react/form";
import { useState } from "react";

const API_KEY = "key_live_3f9a7c21";

export default function Example() {
  const [copied, setCopied] = useState(false);
  return (
    <InputGroup>
      <InputGroupInput aria-label="API key" readOnly value={API_KEY} />
      <InputAction
        icon={copied ? "check" : "copy"}
        aria-label={copied ? "Copied" : "Copy API key"}
        onPress={() => navigator.clipboard.writeText(API_KEY).then(() => setCopied(true))}
      />
    </InputGroup>
  );
}
```

### Invalid and disabled

The frame draws the state; the input still carries it for assistive tech.

```tsx
import { InputAddon, InputGroup, InputGroupInput } from "@senvenli/react/form";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Stack space="space-200">
      <InputGroup isInvalid>
        <InputGroupInput aria-label="Discount" defaultValue="140" inputMode="numeric" />
        <InputAddon position="end">%</InputAddon>
      </InputGroup>
      <InputGroup size="small" isDisabled>
        <InputGroupInput aria-label="Tax rate" defaultValue="20" />
        <InputAddon position="end">%</InputAddon>
      </InputGroup>
    </Stack>
  );
}
```

## Guidelines

### When to use it

- A custom input needs prefix or suffix text, icons or buttons.

### Use something else when

- [input](https://design.senvenli.com/docs/components/input.md): No addon or action is needed; `type` already covers search, password and phone.
- [combobox](https://design.senvenli.com/docs/components/combobox.md): The addon is a choice from a list.

## Accessibility

Built in:

- Pressing an addon focuses the input.

You provide:

- Labels for actions that show only an icon.

## API reference

### InputGroup

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| children | `React.ReactNode` |  | yes |  |
| size | `FieldSize` |  | no |  |
| isDisabled | `boolean` |  | no |  |
| isInvalid | `boolean` |  | no |  |
| multiline | `boolean` |  | no | Multi-line content (TextArea): items align to the top. |
| dir | `"ltr"` |  | no | `ltr` keeps the frame left to right on an RTL page (phone numbers, IBANs). |
| id | `string` |  | no | The control's id, description link and invalid state. A `Field` around the group sets them; the group hands them to its `InputGroupInput`, so the label and the error reach the input, not the frame. |
| aria-describedby | `string` |  | no |  |
| aria-invalid | `boolean \| "true" \| "false"` |  | no |  |

### InputAddon

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| children | `React.ReactNode` |  | yes |  |
| position | `"start" \| "end"` | `"start"` | no | Which side of the value it sits on. |
| flush | `boolean` | `true` | no | Flush with the frame edge (default). Off when another part, such as a stepper, follows an end addon. |
| onClick | `MouseEventHandler<HTMLSpanElement>` |  | no | Extra handler; focus forwarding to the control always runs as well. |

### InputAction

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| icon | `IconName` |  | yes | Lucide icon name ("copy", "circle-x"). |

Behavior props from React Aria:

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| autoFocus | `boolean` |  | no | Whether the element should receive focus on render. |
| onFocus | `(e: FocusEvent<Element, Element>) => void` |  | no | Handler that is called when the element receives focus. |
| onBlur | `(e: FocusEvent<Element, Element>) => void` |  | no | Handler that is called when the element loses focus. |
| onClick | `(e: MouseEvent<FocusableElement, MouseEvent>) => void` |  | no | **Not recommended – use `onPress` instead.** `onClick` is an alias for `onPress` provided for compatibility with other libraries. `onPress` provides additional event details for non-mouse interactions. |
| isDisabled | `boolean` |  | no | Whether the button is disabled. |
| onPress | `(e: PressEvent) => void` |  | no | Handler that is called when the press is released over the target. |
| onPressStart | `(e: PressEvent) => void` |  | no | Handler that is called when a press interaction starts. |
| onPressEnd | `(e: PressEvent) => void` |  | no | Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target. |
| onPressChange | `(isPressed: boolean) => void` |  | no | Handler that is called when the press state changes. |
| onPressUp | `(e: PressEvent) => void` |  | no | Handler that is called when a press is released over the target, regardless of whether it started on the target or not. |
| onFocusChange | `(isFocused: boolean) => void` |  | no | Handler that is called when the element's focus status changes. |
| type | `"button" \| "submit" \| "reset"` |  | no | The behavior of the button when used in an HTML form. |
| preventFocusOnPress | `boolean` |  | no | Whether to prevent focus from moving to the button when pressing it. Caution, this can make the button inaccessible and should only be used when alternative keyboard interaction is provided, such as ComboBox's MenuTrigger or a NumberField's increment/decrement control. |
| form | `string` |  | no | The `<form>` element to associate the button with. The value of this attribute must be the id of a `<form>` in the same document. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/button#form). |
| formAction | `string \| ((formData: FormData) => void \| Promise<void>)` |  | no | The URL that processes the information submitted by the button. Overrides the action attribute of the button's form owner. |
| formEncType | `string` |  | no | Indicates how to encode the form data that is submitted. |
| formMethod | `string` |  | no | Indicates the HTTP method used to submit the form. |
| formNoValidate | `boolean` |  | no | Indicates that the form is not to be validated when it is submitted. |
| formTarget | `string` |  | no | Overrides the target attribute of the button's form owner. |
| name | `string` |  | no | Submitted as a pair with the button's value as part of the form data. |
| value | `string` |  | no | The value associated with the button's name when it's submitted with the form data. |
| excludeFromTabOrder | `boolean` |  | no | Whether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available. |
| isPending | `boolean` |  | no | Whether the button is in a pending state. This disables press and hover events while retaining focusability, and announces the pending state to screen readers. |
| onHoverStart | `(e: HoverEvent) => void` |  | no | Handler that is called when a hover interaction starts. |
| onHoverEnd | `(e: HoverEvent) => void` |  | no | Handler that is called when a hover interaction ends. |
| onHoverChange | `(isHovering: boolean) => void` |  | no | Handler that is called when the hover state changes. |

Also takes 84 standard DOM and ARIA attributes (id, aria-label, event handlers…).

### InputGroupInput

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| ref | `React.Ref<HTMLInputElement>` |  | no |  |

Also takes 305 standard DOM and ARIA attributes (id, aria-label, event handlers…).

### Tokens it reads

`--ds-background-disabled`, `--ds-background-input`, `--ds-background-input-hovered`, `--ds-background-neutral-pressed`, `--ds-background-neutral-subtle-hovered`, `--ds-border`, `--ds-border-bold`, `--ds-border-danger`, `--ds-border-focused`, `--ds-easing-standard`, `--ds-icon-subtle`, `--ds-radius-control-medium`, `--ds-radius-medium`, `--ds-radius-small`, `--ds-size-control`, `--ds-size-control-compact`, `--ds-size-control-large`, `--ds-size-icon`, `--ds-space-050`, `--ds-space-075`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-surface-sunken`, `--ds-text`, `--ds-text-danger`, `--ds-text-disabled`, `--ds-text-subtle`, `--ds-text-subtlest`

## Related

- [input](https://design.senvenli.com/docs/components/input.md)
