Back to Fluentui

Label

packages/web-components/src/label/README.md

4.40.2-hotfix23.6 KB
Original Source

Label

A label represents a caption for an item in a user interface.

Design Spec

Link to Label Design Spec in Figma

Engineering Spec

The fluent-label has several visual font size (small, medium, large) and font weight(regular, semibold) options. The fluent-label also provides appearances for required and disabled states.

Note about form association

In web components, when using the shadow DOM, it's not feasible to associate elements across the shadow DOM boundary using the traditional for attribute, since the shadow DOM creates a boundary that prevents the label element from accessing the input element's id attribute. Instead, the WC3 Label component uses the aria-labelledby attribute to associate the label element with the input element. This attribute has a value that matches the id of another element on the page, which serves as a label for the input element.

Use Case

Creating a simple label element with an optional info icon and optional required state

Class: Label

Variables

Fields

NamePrivacyTypeDefaultDescription
requiredpublicbooleanfalseSpecifies required styling for label
disabledpublicbooleanfalseSets disabled state for label
sizepublic"small" "medium" "large""medium"Specifies font size for label
weightpublic"regular" "semibold""regular"Specifies font weight for label

Methods

Events

Attributes

NameField
requiredrequired
disableddisabled
sizesize
weightweight

Slots

NameDescription
Default slotted content for label text

Template

html
<slot></slot> <span part="asterisk" class="asterisk" ?hidden="${x => !x.required}">*</span>

Accessibility

W3 Label Spec

WAI-ARIA Roles, States, and Properties

<hr />

Preparation

Fluent Web Component v3 v.s Fluent React 9

Component and Slot Mapping

Fluent UI React 9Fluent Web Components 3
<Label><fluent-label>

Additional Deltas

Fluent UI React 9Fluent Web Components 3
RendersHTMLLabelElementHTMLElement
APIHTMLLabelElement SpecHTMLElement Spec
Shadow DOMn/auses Shadow DOM
AccessibilityUses for attribute to associate with form elementsUses aria-labelledby to associate with form elements, does not have a for attribute