Label
A Duostrap label providing independent accessible naming and click activation via explicit control associations.
Duostrap Label preserves classic 14px / 20px Helvetica Neue regular typography while pairing accessible naming (naming) and pointer activation (activation) with target controls through an explicit reference.
For form fields, use the Field component for automatic
FieldLabel,FieldDescription, andFieldErrorassociations 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-duostrap-checkbox-root data-pair="updates">
<wc-duostrap-checkbox-indicator></wc-duostrap-checkbox-indicator>
</wc-duostrap-checkbox-root>
<wc-duostrap-label-root data-pair="updates">
Community updates
</wc-duostrap-label-root>
</div>
<div class="flex items-center gap-2">
<wc-duostrap-switch-root data-pair="notify">
<wc-duostrap-switch-thumb></wc-duostrap-switch-thumb>
</wc-duostrap-switch-root>
<wc-duostrap-label-root data-pair="notify">
Enable notifications
</wc-duostrap-label-root>
</div>
<div class="flex flex-col gap-2">
<wc-duostrap-label-root data-pair="project">
Project name
</wc-duostrap-label-root>
<wc-duostrap-input-root
data-pair="project"
default-value="Proto UI"
></wc-duostrap-input-root>
</div>
<div class="flex flex-col gap-2">
<wc-duostrap-label-root data-pair="notes">
Project notes
</wc-duostrap-label-root>
<wc-duostrap-textarea-root
data-pair="notes"
default-value="Share a brief summary of your project."
rows="3"
></wc-duostrap-textarea-root>
</div>
<div class="flex items-center gap-2">
<wc-duostrap-checkbox-root data-pair="passive">
<wc-duostrap-checkbox-indicator></wc-duostrap-checkbox-indicator>
</wc-duostrap-checkbox-root>
<wc-duostrap-label-root data-pair="passive" activation="false">
Naming-only label (selectable text)
</wc-duostrap-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”Currently available from workspace source. Import directly from the workspace package:
import { labelRoot } from '@proto.ui/prototypes-duostrap/label';Create one stable reference per pair with createControlLabelRef() from @proto.ui/core and pass it through the adapter association channel:
import { useMemo } from 'react';import { createControlLabelRef } from '@proto.ui/core';import { BootstrapCheckboxIndicator, BootstrapCheckboxRoot, BootstrapLabelRoot,} from '../proto-ui/components/react';
export function TermsCheckbox() { const termsRef = useMemo(() => createControlLabelRef(), []);
return ( <div className="flex items-center gap-2"> <BootstrapCheckboxRoot instanceAssociations={{ controlLabel: termsRef }}> <BootstrapCheckboxIndicator /> </BootstrapCheckboxRoot> <BootstrapLabelRoot instanceAssociations={{ controlLabel: termsRef }}> Accept terms and conditions </BootstrapLabelRoot> </div> );}In Web Components, bind both elements 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 layout
Section titled “Naming, activation, and layout”naming(defaulttrue): Links the target control to the renderedLabelas its accessible name. If the control already sets a non-emptyariaLabelorlabelledBy, setnaming={false}for activation-only pairing.activation(defaulttrue): Clicking a pairedLabelinvokes the target’s existing operation (togglingCheckbox/Switch, selecting aRadio Group Item, or focusingInput/Textarea). Setactivation={false}for a passive naming-only label.selection(default'policy'): Prevents accidental text selection on actionable labels by default; use'text','auto', or'none'to override explicitly.- Alignment and safety: Uses
inline-flexwithout an unconditional bottom margin so inline choice rows stay vertically centered while stacked layouts remain controlled by their container. Adds no extraTabstop and ignores nested links/buttons, modified clicks, and drags.
Examples
Section titled “Examples”<div class="flex items-center gap-2">
<wc-duostrap-checkbox-root id="terms-checkbox">
<wc-duostrap-checkbox-indicator></wc-duostrap-checkbox-indicator>
</wc-duostrap-checkbox-root>
<wc-duostrap-label-root id="terms-label">
Accept terms and conditions
</wc-duostrap-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”<div class="flex w-full max-w-md flex-col gap-5">
<wc-duostrap-field-root required validation-mode="onBlur">
<wc-duostrap-field-label>Email address</wc-duostrap-field-label>
<wc-duostrap-field-control
placeholder="name@example.com"
></wc-duostrap-field-control>
<wc-duostrap-field-description>
We will use this address for account security notices.
</wc-duostrap-field-description>
<wc-duostrap-field-error></wc-duostrap-field-error>
</wc-duostrap-field-root>
<wc-duostrap-field-root>
<wc-duostrap-field-label>Display name</wc-duostrap-field-label>
<wc-duostrap-field-control
default-value="Alex Chen"
></wc-duostrap-field-control>
<wc-duostrap-field-description>
Shown alongside your comments and reviews.
</wc-duostrap-field-description>
</wc-duostrap-field-root>
<div class="flex items-center gap-2">
<wc-duostrap-checkbox-root
id="field-updates-checkbox"
default-checked
>
<wc-duostrap-checkbox-indicator></wc-duostrap-checkbox-indicator>
</wc-duostrap-checkbox-root>
<wc-duostrap-label-root id="field-updates-label">
Send me product release notes
</wc-duostrap-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”<div id="label-modes" class="flex w-full max-w-md flex-col gap-4">
<div class="flex items-center gap-2">
<wc-duostrap-checkbox-root data-pair="copyable">
<wc-duostrap-checkbox-indicator></wc-duostrap-checkbox-indicator>
</wc-duostrap-checkbox-root>
<wc-duostrap-label-root data-pair="copyable" selection="text">
Weekly digest (clickable and selectable)
</wc-duostrap-label-root>
</div>
<div class="flex items-center gap-2">
<wc-duostrap-checkbox-root data-pair="naming-only">
<wc-duostrap-checkbox-indicator></wc-duostrap-checkbox-indicator>
</wc-duostrap-checkbox-root>
<wc-duostrap-label-root
data-pair="naming-only"
activation="false"
>
Release policy notice (naming only)
</wc-duostrap-label-root>
</div>
<div class="flex flex-col gap-2">
<wc-duostrap-label-root
data-pair="activation-only"
naming="false"
>
Quick filter (activation only)
</wc-duostrap-label-root>
<wc-duostrap-input-root
data-pair="activation-only"
aria-label="Filter workspace items"
placeholder="Filter workspace items..."
></wc-duostrap-input-root>
</div>
<div class="flex items-center gap-2">
<wc-duostrap-checkbox-root data-pair="unavailable" disabled>
<wc-duostrap-checkbox-indicator></wc-duostrap-checkbox-indicator>
</wc-duostrap-checkbox-root>
<wc-duostrap-label-root data-pair="unavailable">
Unavailable option
</wc-duostrap-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><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-duostrap-checkbox-root data-pair="rtl-terms">
<wc-duostrap-checkbox-indicator></wc-duostrap-checkbox-indicator>
</wc-duostrap-checkbox-root>
<wc-duostrap-label-root data-pair="rtl-terms">
قبول الشروط والأحكام
</wc-duostrap-label-root>
</div>
<div class="flex flex-col gap-2">
<wc-duostrap-label-root data-pair="rtl-email">
البريد الإلكتروني
</wc-duostrap-label-root>
<wc-duostrap-input-root
data-pair="rtl-email"
placeholder="name@example.com"
></wc-duostrap-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 | Supplies the paired control accessible name |
activation | boolean | true | Forwards eligible clicks to the paired control default action |
selection | 'policy' 'auto' 'text' 'none' | 'policy' | Text-selection policy; default suppresses selection only while actionable |
Association helpers
Section titled “Association helpers”createControlLabelRef(): Imported from@proto.ui/coreto create a stable one-to-one pair 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.