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>
);
}import {
InputGroup,
InputAddon,
InputAction,
InputGroupInput,
} from "@senvenli/react/form";Examples
With an action
An icon button inside the frame; its `aria-label` names it.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.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.
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 | Description |
|---|---|---|---|
childrenRequired | React.ReactNode | – | |
size | FieldSize | – | |
isDisabled | boolean | – | |
isInvalid | boolean | – | |
multiline | boolean | – | Multi-line content (TextArea): items align to the top. |
dir | "ltr" | – |
|
id | string | – | The control's id, description link and invalid state. A |
aria-describedby | string | – | |
aria-invalid | boolean | "true" | "false" | – |
childrenRequiredReact.ReactNodesizeFieldSizeisDisabledbooleanisInvalidbooleanmultilinebooleanMulti-line content (TextArea): items align to the top.
dir"ltr"ltrkeeps the frame left to right on an RTL page (phone numbers, IBANs).idstringThe control's id, description link and invalid state. A
Fieldaround the group sets them; the group hands them to itsInputGroupInput, so the label and the error reach the input, not the frame.aria-describedbystringaria-invalidboolean | "true" | "false"
InputAddon
| Prop | Type | Default | Description |
|---|---|---|---|
childrenRequired | React.ReactNode | – | |
position | "start" | "end" | "start" | Which side of the value it sits on. |
flush | boolean | true | Flush with the frame edge (default). Off when another part, such as a stepper, follows an end addon. |
onClick | MouseEventHandler<HTMLSpanElement> | – | Extra handler; focus forwarding to the control always runs as well. |
childrenRequiredReact.ReactNodeposition"start" | "end"Default"start"Which side of the value it sits on.
flushbooleanDefaulttrueFlush with the frame edge (default). Off when another part, such as a stepper, follows an end addon.
onClickMouseEventHandler<HTMLSpanElement>Extra handler; focus forwarding to the control always runs as well.
InputAction
| Prop | Type | Default | Description |
|---|---|---|---|
iconRequired | IconName | – | Lucide icon name ("copy", "circle-x"). |
iconRequiredIconNameLucide icon name ("copy", "circle-x").
InputGroupInput
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLInputElement> | – |
refReact.Ref<HTMLInputElement>