Label
Renders an accessible Shadcn label associated with controls through an explicit reference.
Label pairs accessible naming (naming) and pointer activation (activation) with a target control through an explicit reference, without manual DOM IDs or implicit ancestor lookups. The examples on this page use the Shadcn Rhea style preset.
For form fields, use the Field component, which includes built-in
FieldLabel,FieldDescription, andFieldErrorwiring and validation.
Preview
Section titled “Preview”<div
id="label-overview"
class="flex w-full max-w-xl flex-col gap-4"
>
<div class="flex items-center gap-2">
<wc-shadcn-checkbox-root
style-profile="rhea"
data-pair="updates"
>
<wc-shadcn-checkbox-indicator
style-profile="rhea"
></wc-shadcn-checkbox-indicator>
</wc-shadcn-checkbox-root>
<wc-shadcn-label-root style-profile="rhea" data-pair="updates">
Community updates
</wc-shadcn-label-root>
</div>
<div class="flex items-center gap-2">
<wc-shadcn-switch-root style-profile="rhea" data-pair="notify">
<wc-shadcn-switch-thumb
style-profile="rhea"
></wc-shadcn-switch-thumb>
</wc-shadcn-switch-root>
<wc-shadcn-label-root style-profile="rhea" data-pair="notify">
Enable notifications
</wc-shadcn-label-root>
</div>
<div class="flex flex-col gap-2">
<wc-shadcn-label-root style-profile="rhea" data-pair="project">
Project name
</wc-shadcn-label-root>
<wc-shadcn-input-root
style-profile="rhea"
data-pair="project"
default-value="Proto UI"
></wc-shadcn-input-root>
</div>
<div class="flex flex-col gap-2">
<wc-shadcn-label-root style-profile="rhea" data-pair="notes">
Project notes
</wc-shadcn-label-root>
<wc-shadcn-textarea-root
style-profile="rhea"
data-pair="notes"
default-value="Share a brief summary of your project."
rows="3"
></wc-shadcn-textarea-root>
</div>
<div class="flex items-center gap-2">
<wc-shadcn-checkbox-root
style-profile="rhea"
data-pair="passive"
>
<wc-shadcn-checkbox-indicator
style-profile="rhea"
></wc-shadcn-checkbox-indicator>
</wc-shadcn-checkbox-root>
<wc-shadcn-label-root
style-profile="rhea"
data-pair="passive"
activation="false"
>
Naming-only label (selectable text)
</wc-shadcn-label-root>
</div>
</div>
<script type="module">
import { createControlLabelRef } from '@proto.ui/core';
import { setElementAssociations } from '@proto.ui/adapter-web-component';
const refs = new Map();
document
.querySelectorAll('#label-overview [data-pair]')
.forEach((el) => {
const key = el.getAttribute('data-pair');
if (!key) return;
const ref = refs.get(key) ?? createControlLabelRef();
refs.set(key, ref);
setElementAssociations(el, { controlLabel: ref });
});
</script>Installation
Section titled “Installation”This component is available from workspace source. In your application, install the CLI, Shadcn prototypes and target adapter built from the same workspace revision, then initialize the project with that CLI. Run the locally installed CLI to generate the facade.
npm exec -- proto-ui add wc shadcn-label
pnpm exec proto-ui add wc shadcn-label
Replace wc with react, vue, or vue2 to generate the local facade for your framework. You can also import labelRoot directly from @proto.ui/prototypes-shadcn/label.
Create one stable reference per pair with createControlLabelRef() from @proto.ui/core and pass it through the adapter association channel (outside JSON props):
import { useMemo } from 'react';import { createControlLabelRef } from '@proto.ui/core';import { ShadcnCheckboxIndicator, ShadcnCheckboxRoot, ShadcnLabelRoot,} from '../proto-ui/components/react';
export function TermsCheckbox() { const termsRef = useMemo(() => createControlLabelRef(), []);
return ( <div className="flex items-center gap-2"> <ShadcnCheckboxRoot styleProfile="rhea" instanceAssociations={{ controlLabel: termsRef }}> <ShadcnCheckboxIndicator styleProfile="rhea" /> </ShadcnCheckboxRoot> <ShadcnLabelRoot styleProfile="rhea" instanceAssociations={{ controlLabel: termsRef }}> Accept terms and conditions </ShadcnLabelRoot> </div> );}In Web Components, bind the same reference with setElementAssociations() from @proto.ui/adapter-web-component:
import { createControlLabelRef } from '@proto.ui/core';import { setElementAssociations } from '@proto.ui/adapter-web-component';
const termsRef = createControlLabelRef();setElementAssociations(checkboxEl, { controlLabel: termsRef });setElementAssociations(labelEl, { controlLabel: termsRef });Naming, activation, and accessibility
Section titled “Naming, activation, and accessibility”naming(defaulttrue): Associates the rendered label with its paired control so assistive technology announces it automatically. If the target already sets a non-emptyariaLabelorlabelledBy, setnaming={false}for an activation-only label.activation(defaulttrue): Clicking the paired label invokes the control’s existing action in the same turn — togglingCheckbox/Switch, selecting aRadio Group Item, or focusingInput/Textareawithout altering text or selection. Setactivation={false}for a passive naming-only label.selection(default'policy'): Suppresses accidental text selection on actionable labels while keeping naming-only labels copyable. Setselection="text"if an actionable label should remain copyable.- Keyboard and pointer safety:
Labeladds no extraTabstop, and ignores clicks on nested links/buttons, modified clicks, cancelled pointers, and drag gestures. - Supported targets:
Checkbox,Switch,Radio Group Item,Input,Textarea,Button,Toggle,Toggle Group Item, standaloneSelect Trigger, andNumber Field Input. - Style presets (
styleProfile): Supportsvega,nova,maia,lyra,mira,luma,sera,rhea, andnew-york-v4; the default'inherit'reads the nearest Style Scope and falls back tonew-york-v4.
Examples
Section titled “Examples”Pair Label with Checkbox so clicking the label toggles the control.
<div class="flex items-center gap-2">
<wc-shadcn-checkbox-root style-profile="rhea" id="terms-checkbox">
<wc-shadcn-checkbox-indicator
style-profile="rhea"
></wc-shadcn-checkbox-indicator>
</wc-shadcn-checkbox-root>
<wc-shadcn-label-root style-profile="rhea" id="terms-label">
Accept terms and conditions
</wc-shadcn-label-root>
</div>
<script type="module">
import { createControlLabelRef } from '@proto.ui/core';
import { setElementAssociations } from '@proto.ui/adapter-web-component';
const termsRef = createControlLabelRef();
const checkbox = document.querySelector('#terms-checkbox');
const label = document.querySelector('#terms-label');
if (
checkbox instanceof HTMLElement &&
label instanceof HTMLElement
) {
setElementAssociations(checkbox, { controlLabel: termsRef });
setElementAssociations(label, { controlLabel: termsRef });
}
</script>Label in Field
Section titled “Label in Field”Use Field for structured form fields with automatic FieldLabel, FieldDescription, and FieldError associations alongside standalone Label controls.
<div class="flex w-full max-w-md flex-col gap-5">
<wc-shadcn-field-root
style-profile="rhea"
required
validation-mode="onBlur"
>
<wc-shadcn-field-label style-profile="rhea">
Email address
</wc-shadcn-field-label>
<wc-shadcn-field-control
style-profile="rhea"
placeholder="name@example.com"
></wc-shadcn-field-control>
<wc-shadcn-field-description style-profile="rhea">
We will use this address for account security notices.
</wc-shadcn-field-description>
<wc-shadcn-field-error
style-profile="rhea"
></wc-shadcn-field-error>
</wc-shadcn-field-root>
<wc-shadcn-field-root style-profile="rhea">
<wc-shadcn-field-label style-profile="rhea">
Display name
</wc-shadcn-field-label>
<wc-shadcn-field-control
style-profile="rhea"
default-value="Alex Chen"
></wc-shadcn-field-control>
<wc-shadcn-field-description style-profile="rhea">
Shown alongside your comments and reviews.
</wc-shadcn-field-description>
</wc-shadcn-field-root>
<div class="flex items-center gap-2">
<wc-shadcn-checkbox-root
style-profile="rhea"
id="field-updates-checkbox"
default-checked
>
<wc-shadcn-checkbox-indicator
style-profile="rhea"
></wc-shadcn-checkbox-indicator>
</wc-shadcn-checkbox-root>
<wc-shadcn-label-root
style-profile="rhea"
id="field-updates-label"
>
Send me product release notes
</wc-shadcn-label-root>
</div>
</div>
<script type="module">
import { createControlLabelRef } from '@proto.ui/core';
import { setElementAssociations } from '@proto.ui/adapter-web-component';
const updatesRef = createControlLabelRef();
const checkbox = document.querySelector(
'#field-updates-checkbox'
);
const label = document.querySelector('#field-updates-label');
if (
checkbox instanceof HTMLElement &&
label instanceof HTMLElement
) {
setElementAssociations(checkbox, { controlLabel: updatesRef });
setElementAssociations(label, { controlLabel: updatesRef });
}
</script>Naming, Activation, and Selection
Section titled “Naming, Activation, and Selection”Configure selection="text" (actionable and copyable), activation={false} (naming only), and naming={false} (activation only when the target declares its own ariaLabel).
<div id="label-modes" class="flex w-full max-w-md flex-col gap-4">
<div class="flex items-center gap-2">
<wc-shadcn-checkbox-root
style-profile="rhea"
data-pair="copyable"
>
<wc-shadcn-checkbox-indicator
style-profile="rhea"
></wc-shadcn-checkbox-indicator>
</wc-shadcn-checkbox-root>
<wc-shadcn-label-root
style-profile="rhea"
data-pair="copyable"
selection="text"
>
Weekly digest (clickable and selectable)
</wc-shadcn-label-root>
</div>
<div class="flex items-center gap-2">
<wc-shadcn-checkbox-root
style-profile="rhea"
data-pair="naming-only"
>
<wc-shadcn-checkbox-indicator
style-profile="rhea"
></wc-shadcn-checkbox-indicator>
</wc-shadcn-checkbox-root>
<wc-shadcn-label-root
style-profile="rhea"
data-pair="naming-only"
activation="false"
>
Release policy notice (naming only)
</wc-shadcn-label-root>
</div>
<div class="flex flex-col gap-2">
<wc-shadcn-label-root
style-profile="rhea"
data-pair="activation-only"
naming="false"
>
Quick filter (activation only)
</wc-shadcn-label-root>
<wc-shadcn-input-root
style-profile="rhea"
data-pair="activation-only"
aria-label="Filter workspace items"
placeholder="Filter workspace items..."
></wc-shadcn-input-root>
</div>
<div class="flex items-center gap-2">
<wc-shadcn-checkbox-root
style-profile="rhea"
data-pair="unavailable"
disabled
>
<wc-shadcn-checkbox-indicator
style-profile="rhea"
></wc-shadcn-checkbox-indicator>
</wc-shadcn-checkbox-root>
<wc-shadcn-label-root
style-profile="rhea"
data-pair="unavailable"
>
Unavailable option
</wc-shadcn-label-root>
</div>
</div>
<script type="module">
import { createControlLabelRef } from '@proto.ui/core';
import { setElementAssociations } from '@proto.ui/adapter-web-component';
const refs = new Map();
document
.querySelectorAll('#label-modes [data-pair]')
.forEach((el) => {
const key = el.getAttribute('data-pair');
if (!key) return;
const ref = refs.get(key) ?? createControlLabelRef();
refs.set(key, ref);
setElementAssociations(el, { controlLabel: ref });
});
</script>Inside a dir="rtl" container, Label uses logical start alignment (text-start) with Checkbox and Input.
<div
id="label-rtl"
dir="rtl"
class="flex w-full max-w-sm flex-col gap-4"
>
<div class="flex items-center gap-2">
<wc-shadcn-checkbox-root
style-profile="rhea"
data-pair="rtl-terms"
>
<wc-shadcn-checkbox-indicator
style-profile="rhea"
></wc-shadcn-checkbox-indicator>
</wc-shadcn-checkbox-root>
<wc-shadcn-label-root
style-profile="rhea"
data-pair="rtl-terms"
>
قبول الشروط والأحكام
</wc-shadcn-label-root>
</div>
<div class="flex flex-col gap-2">
<wc-shadcn-label-root
style-profile="rhea"
data-pair="rtl-email"
>
البريد الإلكتروني
</wc-shadcn-label-root>
<wc-shadcn-input-root
style-profile="rhea"
data-pair="rtl-email"
placeholder="name@example.com"
></wc-shadcn-input-root>
</div>
</div>
<script type="module">
import { createControlLabelRef } from '@proto.ui/core';
import { setElementAssociations } from '@proto.ui/adapter-web-component';
const refs = new Map();
document
.querySelectorAll('#label-rtl [data-pair]')
.forEach((el) => {
const key = el.getAttribute('data-pair');
if (!key) return;
const ref = refs.get(key) ?? createControlLabelRef();
refs.set(key, ref);
setElementAssociations(el, { controlLabel: ref });
});
</script>| Prop | Type | Default | Description |
|---|---|---|---|
naming | boolean | true | Associates this rendered label as the paired target accessible name |
activation | boolean | true | Requests the paired target default action when the label is clicked |
selection | 'policy' 'auto' 'text' 'none' | 'policy' | Text-selection policy; default suppresses selection only while actionable |
styleProfile | 'inherit' 'rhea' 'vega' 'nova' 'maia' 'lyra' 'mira' 'luma' 'sera' 'new-york-v4' | 'inherit' | Typography preset; inherits nearest Style Scope or falls back to new-york-v4 |
Association helpers
Section titled “Association helpers”createControlLabelRef(): Imported from@proto.ui/coreto create a stable one-to-one opaque reference.instanceAssociations: Adapter prop accepting{ controlLabel: ref }in React, Vue, and Vue 2.setElementAssociations(element, { controlLabel: ref }): Imported from@proto.ui/adapter-web-componentfor Web Components.