@gridui/radio-group

中文文档
2.0.1发布于 2026/11/01UNLICENSEDTypeScriptES Module

GridUI radio groups and rich single-choice cards

原始使用文档
文档目录4 节
  1. Selection and forms
  2. Rich choices
  3. Shared grid boundaries
  4. Migration

Radio group

@gridui/radio-group owns RadioGroup, Radio, and RadioCard as one single-selection family. Import from the package root and load @gridui/radio-group/styles.css after @gridui/theme/styles.css. React and React DOM 19.2 or later are required, matching the shared Form lifecycle contract. The package does not depend on application layout.

Selection and forms

RadioGroup retains string value / onValueChange for controlled state and defaultValue for local state. onValueChange(value, details) receives the native details.event; details.cancel() prevents an uncontrolled selection update. Controlled callers own their state and must not commit a canceled change. Activating an already selected item does not emit a value change. The shared event protocol comes from @gridui/interaction.

The group forwards name, form, required, disabled, orientation, loop, refs, and native accessibility props. readOnly permits focus without changing the selection. Items also respect disabled fieldsets. Native form reset restores the initial uncontrolled value unless the reset event is canceled; controlled callers reset their own state. Radix owns radio semantics, hidden form inputs, and keyboard navigation. Provide an accessible group name independently of item labels.

import { Radio, RadioGroup } from "@gridui/radio-group";

<RadioGroup name="delivery" defaultValue="standard" aria-label="Delivery service">
    <label><Radio value="standard" /> Standard delivery</label>
    <label><Radio value="express" /> Express delivery</label>
</RadioGroup>

Use comfortable visible label hit areas for compact Radio controls. Radio and RadioCard can coexist in one group and share the same selection context.

Rich choices

RadioCard adds a required label, optional description, optional decorative leading node, and variant="outlined" | "plain" to RadioProps, excluding asChild. The default is outlined. Cards remain native radio buttons, not links or independently managed toggles. Selection, form ownership, and callbacks stay on RadioGroup; cards do not own columns or a second selection model.

The label and description have separate generated associations. Explicit aria-label or aria-labelledby overrides the generated name. Supplied aria-describedby is combined with the description association. leading is hidden from assistive technology and must be decorative. Keep every slot free of nested links, buttons, and inputs; essential information belongs in the label or description. All slots accept phrasing content. Native refs point to the radio button, and caller click/focus handlers can prevent a selection request.

<RadioGroup defaultValue="standard" aria-label="Delivery service">
    <RadioCard value="standard" label="Standard delivery"
        description="Delivered in three to five working days." />
    <RadioCard value="express" label="Express delivery"
        description="Delivered on the next working day." />
</RadioGroup>

Shared grid boundaries

The outlined variant owns its functional border. The plain variant adds no outer border declarations, so GridItem asChild retains its structural seams. It does not apply border: 0, inspect Grid internals, or infer an enclosing layout. Both variants retain the themed background so a grid seam surface does not show through the card body. RadioGroup asChild delegates layout to its child without imposing the group's default vertical flex arrangement. Grid remains responsible for responsive tracks, shared boundaries, and optional cell padding.

Standalone cards default to spacing token 16. When composed with GridItem asChild, the GridItem's padding takes precedence, including zero and responsive values, regardless of the Grid and Radio-group stylesheet order. Caller spacing utilities can override either value. RadioCard does not depend on Grid to apply this default.

import { Grid, GridItem } from "@gridui/grid";
import { RadioCard, RadioGroup } from "@gridui/radio-group";

<RadioGroup asChild defaultValue="standard" aria-label="Delivery service">
    <Grid columns={{ base: 1, md: 2 }} frame="cells">
        <GridItem asChild padding={16}>
            <RadioCard value="standard" variant="plain" label="Standard"
                description="Three to five working days." />
        </GridItem>
        <GridItem asChild padding={16}>
            <RadioCard value="express" variant="plain" label="Express"
                description="Next working day." />
        </GridItem>
    </Grid>
</RadioGroup>

Migration

Import Radio, RadioGroup, and their prop types from @gridui/radio-group instead of @gridui/controls, and load the new stylesheet. Controls no longer contains or re-exports this family. Existing values, callbacks, refs, forms, read-only behavior, and keyboard contracts remain available.

版本与发布记录

@gridui/radio-group 共发布 6 个版本,首次发布于 2026/10/29;过去 12 个月发布了 6 个版本。

版本发布日期距今
2.0.1latest2026/11/012 天前
1.0.22026/10/313 天前
1.0.12026/10/294 天前
1.0.02026/10/295 天前
0.0.02026/10/295 天前
0.0.0-stage2026/10/295 天前

关于 @gridui/radio-group 的常见问题

@gridui/radio-group 是什么?

GridUI无线电组和丰富的单选择卡

如何安装 @gridui/radio-group?

在项目目录运行 npm install @gridui/radio-group,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.2.0)、react-dom(^19.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@gridui/radio-group 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gridui/radio-group 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@gridui/radio-group 可以商用吗?

@gridui/radio-group 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@gridui/radio-group 还在维护吗?

最新版本 2.0.1 发布于 2026/11/01(2 天前);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2026/10/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。