Components
Input group
Joined input wrapper for addons, icons, and a shared focus indicator.
Composition
Input with addons
- <InputGroup>
- <InputGroupAddon>
- addon content
- <Input />
- <InputGroupAddon>
Installation
The Control UI source installs this component from src/registry/sources/control-ui/ui/input-group.tsx.
npx shadcn@latest add https://control-ui.dev/r/input-group.jsonDependencies
Press focus
src/registry/lib/press-focus.ts
Util
Control variants
src/registry/sources/control-ui/control-variants.ts
Support
Raw code
Primary installed source
"use client";
import { useRender } from "@base-ui/react/use-render";import type { ComponentProps, CSSProperties, MouseEvent, Ref, RefCallback, RefObject } from "react";import { createContext, use, useRef } from "react";import type { RenderProp } from "@/components/control-ui/control-props";import type { ControlSize } from "@/components/control-ui/control-variants";import type { FieldKnobStyle } from "@/components/control-ui/knob-contracts/field-knobs";import { cn } from "@/components/control-ui/lib/cn";import { focusTextControlOnPress } from "@/components/control-ui/lib/press-focus";
export type InputGroupProps = Omit<ComponentProps<"div">, "style"> & { style?: CSSProperties & FieldKnobStyle } & { render?: RenderProp<ComponentProps<"div">>; size?: ControlSize;};
export type InputGroupAddonProps = ComponentProps<"span"> & { style?: CSSProperties & FieldKnobStyle };
const InputGroupSurfaceContext = createContext(false);const InputGroupControlContext = createContext<RefObject<HTMLElement | null> | null>(null);
export function useIsInsideInputGroup() { return use(InputGroupSurfaceContext);}
// In-group text controls pass their ref through this, so the group can focus them from its addons and padding.export function useInputGroupControlRef<Control extends HTMLElement>(ref?: Ref<Control>): RefCallback<Control> { const groupControlRef = use(InputGroupControlContext); return (node) => { if (groupControlRef) groupControlRef.current = node; if (typeof ref === "function") return ref(node); if (ref) ref.current = node; return undefined; };}
export function InputGroup({ size = "md", className, render, children, onMouseDown, ...props }: InputGroupProps) { const controlRef = useRef<HTMLElement | null>(null); const classes = cn("flex min-w-0 w-full items-center overflow-hidden", className);
const group = useRender({ defaultTagName: "div", render, props: { ...props, "data-control-ui": "input-group", "data-slot": "root", "data-control-family": "field", "data-field-kind": "input-group", "data-control": "true", "data-size": size, className: classes, onMouseDown(event: MouseEvent<HTMLDivElement>) { onMouseDown?.(event); focusTextControlOnPress(event, controlRef.current); }, children, }, }); return ( <InputGroupSurfaceContext value={true}> <InputGroupControlContext value={controlRef}>{group}</InputGroupControlContext> </InputGroupSurfaceContext> );}
export function InputGroupAddon({ className, ...props }: InputGroupAddonProps) { return ( <span {...props} data-control-ui="input-group" data-control-family="field" data-field-kind="input-group" data-slot="addon" className={cn("inline-flex shrink-0 items-center", className)} /> );}
Knobs
Typed custom properties the recipe paints with. Set one on the root — style, a utility class, or a skin — and every slot inherits it.
| Knob | Syntax | Default |
|---|---|---|
--cui-field-label-radius | <length-percentage> | var(--radius-control) |
--cui-field-label-background | <color> | transparent |
--cui-field-label-hover-background | <color> | var(--hover-fill) |
--cui-field-label-checked-background | <color> | oklch(from var(--primary) l c h / 0.06) |
--cui-field-label-border-color | <color> | var(--border) |
--cui-field-label-checked-border-color | <color> | var(--primary) |
--cui-field-label-border-width | <length> | var(--control-rim-width) |
--cui-field-label-padding-block | <length-percentage> | calc(var(--spacing) * 3) |
--cui-field-label-padding-inline | <length-percentage> | calc(var(--spacing) * 3) |
--cui-field-legend-foreground | <color> | var(--foreground) |
--cui-field-legend-font-size | <length-percentage> | var(--text-label) |
--cui-field-legend-font-weight | <number> | var(--font-weight-semibold) |
--cui-field-radius | <length-percentage> | var(--nest-radius, var(--radius-control)) |
--cui-field-background | <color> | var(--control-fill) |
--cui-field-hover-background | <color> | var(--hover-fill) |
--cui-field-affordance-background | <color> | transparent |
--cui-field-affordance-shadow | * | 0 0 transparent |
--cui-field-affordance-foreground | <color> | var(--muted-foreground) |
--cui-field-affordance-hover-background | <color> | var(--hover-fill) |
--cui-field-foreground | <color> | var(--foreground) |
--cui-field-border-color | <color> | var(--control-rim) |
--cui-field-focus-border-color | <color> | var(--focus-rim) |
--cui-field-border-width | <length> | var(--control-rim-width) |
--cui-field-shadow | * | var(--shadow-inset) |
--cui-field-backdrop-filter | * | blur(0px) |
--cui-field-height | <length-percentage> | var(--control-h-md) |
--cui-field-padding-inline | <length-percentage> | var(--padding-x) |
--cui-field-font-size | <length-percentage> | var(--text-body) |
--cui-field-font-weight | <number> | var(--font-weight-normal) |
--cui-field-font-family | * | var(--font-body) |
--cui-field-group-radius | <length-percentage> | var(--radius-panel) |
--cui-field-group-background | <color> | var(--card) |
--cui-field-group-border-color | <color> | var(--border) |
--cui-field-group-border-width | <length> | 1px |
--cui-field-group-shadow | * | 0 0 transparent |
--cui-field-group-padding-block | <length-percentage> | calc(var(--spacing) * 3) |
--cui-field-group-padding-inline | <length-percentage> | calc(var(--spacing) * 4) |
--cui-field-group-separator-color | <color> | var(--border) |
--cui-field-group-separator-inset | <length-percentage> | 0px |
--cui-field-label-font-size | <length-percentage> | var(--text-label) |
--cui-field-label-font-weight | <number> | var(--font-weight-medium) |
--cui-field-description-font-size | <length-percentage> | var(--text-caption) |