组件

Label

The words that go with a field, in the bold hand font, with an optional red pencil star for required fields. It fades with a disabled control and hands its click to it.

安装

terminal
npx shadcn@latest add @wobko/label

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Default

Click the words and the field takes focus.

Required

The star is drawn, not typed, and it is decorative: required on the control is what a screen reader hears.

Dimmed with a disabled control

A label after a peer control fades to graphite when the control is disabled: checkbox as a peer, a drawn Input marked peer, or a group with data-disabled.

Accept terms

shadcn's `label-demo`: a Label next to a Checkbox, joined by `htmlFor` and `id`. Click the words and the box ticks itself; the row is the hit area.

API 参考

Label

Radix Label.Root (a real <label>). htmlFor or nesting associate it with a control; double-clicking its text does not select it. required draws a star after the text.

属性类型默认值说明
requiredbooleanfalseA red-pencil star after the text: three crossing strokes, drawn once per label. It is decorative (aria-hidden) and adds nothing to the accessible name: put required on the control so it is announced.
seedstring | number-Pins the hand of the star. Default: derived from useId().
htmlForstring-The id of the control.

无障碍

  • A native <label>: clicking it focuses or toggles its control; the control's accessible name is the label's text (the star is aria-hidden).
  • Bold Kevin Sans at 15 px in ink on paper (14:1). Disabled controls dim their label: put peer on the control before the label (peer-disabled), on a drawn Input / Textarea frame (peer-has-[>input:disabled]), or wrap both in a group with data-disabled="true".
  • The star is intrinsic art: it stays visible in Windows high contrast and never takes focus.

源码

CLI 会复制进你项目的文件。

正在加载源码