# 输入组合 · InputGroup

- 页面: https://jiguang132.com/zh/resources/astryx/docs/input-group
- 资源: Astryx (https://jiguang132.com/zh/resources/astryx.md)
- 全部指南: https://jiguang132.com/zh/resources/astryx/docs.md

输入组合用于表单输入场景。下面的官方示例展示原生用法与状态，属性名保持上游 API。

## 安装与前置条件

```bash
npm install @astryxdesign/core@0.7.1 @astryxdesign/theme-neutral@0.7.1 @stylexjs/stylex@0.19.0
```

需要 React 19+，按顺序导入基础 CSS 和主题，并设置 Theme Provider。参见[开始使用](/resources/astryx/docs/getting-started)。

## 示例与使用方式

- **输入组合 · 综合展示 / 分组 1**：首先体验这个示例，再查看代码理解组件的组合方式。
- **输入组合 · 基础用法 / 分组 2**：可交互查看这一用法的行为，复制代码时保留它实际使用的属性与导入。

## API 与上游详细参考

优先使用 0.7.1 官方中文说明；上游尚未提供中文的条目保留英文。属性名、类型及默认值保持原生 API，不把示例状态名称当成组件属性。

## Input Group

InputGroup connects an input with prefix/suffix addons in a single visual unit. Use it for URL fields, currency inputs, search fields with action buttons, or any input that needs contextual decorations.

| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| children * | ReactNode |  | InputGroupText, Button addons, and compatible input children: TextInput, NumberInput, TimeInput, DateInput, Typeahead, Selector, or MultiSelector. |
| label * | string |  | Accessible label for the group. |
| isLabelHidden | boolean | false | Visually hide the label. |
| description | string |  | Helper text between label and input group. |
| isDisabled | boolean | false | Disable the entire group. |
| isOptional | boolean | false | Show "(optional)" indicator. |
| isRequired | boolean | false | Mark the field as required. |
| size | 'sm' \| 'md' \| 'lg' | 'md' | Default size for inputs in the group. |
| status | {type: 'warning' \| 'error' \| 'success', message?: string} |  | Status indicator applied to the group border. |
| labelTooltip | string |  | Tooltip text at the end of the label. |
| xstyle | StyleXStyles |  | StyleX styles for layout customization. |
| data-testid | string |  | Test selector. |

### 使用建议

- Use text addons to show units, prefixes, or suffixes that clarify the input format (e.g., "$", "kg", "https://").
- Use InputGroupText for static prefixes/suffixes like "$", "kg", or "https://".
- Use Button for an action attached to the input; InputGroup connects its corners automatically.
- Use InputGroup with compatible single-line inputs: TextInput, NumberInput, TimeInput, DateInput, Typeahead, Selector, and MultiSelector.
- Keep each inner input's label specific; grouped inputs automatically combine the group label with their own label and inherit the group description/status context.
- 避免：Don't put multiple text inputs in one group; use separate fields instead.
- 避免：Don't use InputGroup for unrelated inputs; it's for a single input with decorations.
- 避免：Don't use InputGroup with TextArea, Slider, Switch, CheckboxInput, or RadioList.

### 主题 API

```json
{
  "targets": [
    {
      "className": "astryx-input-group",
      "visualProps": [
        "size",
        "status"
      ]
    },
    {
      "className": "astryx-input-group-text"
    }
  ]
}
```

## InputGroupText



### 组件结构

- **Label**: Text above the group.
- **Prefix addon**: Content before the input (text, icon, or button).
- **Input**: The main input element (TextInput, NumberInput, TimeInput, DateInput, Typeahead, Selector, or MultiSelector).
- **Suffix addon**: Content after the input (text, icon, or button).
- **Status message**: An error, warning, or success message below the group.

## Input Group Text

A prefix or suffix text element rendered inside InputGroup. Displays text or icons.

| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| children * | ReactNode |  | Text or icon content. |
| xstyle | StyleXStyles |  | StyleX styles for customization. |
| className | string |  | CSS class name(s). |
| style | React.CSSProperties |  | Inline styles. |

---

JGuang 全部资源索引: https://jiguang132.com/llms.txt
