suiss/ui · Component
Label
An accessible text label that names a form control.
Label is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
Label renders a native label element with the library's form typography. Associate it with a control through htmlFor, or nest the control inside it, so clicking the label focuses or toggles the control.
Use Label for standalone controls. Inside a Field layout, prefer the field's own label part when one is provided.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
-
Add the
cnhelper. -
Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Examples
With input
Give the input an id and pass the same value to the label's htmlFor. Clicking the label focuses the input.
With checkbox
A label placed after a checkbox; clicking the label toggles it. Next to a checkbox, radio item or switch, the label switches to regular weight.
Disabled
A label shown in its dimmed style inside a disabled group, above a disabled input.
Accessibility
- The label text becomes the control's accessible name when linked with
htmlForor by nesting. - Clicking the label focuses a text input or toggles a checkbox, matching native
labelbehavior.
API Reference
Label
Renders a label element that names and activates its associated control.
Also accepts the props of React.ComponentProps<"label">.
Associate it with a control through htmlFor, or nest the control inside it. The label dims to opacity-50 when it follows a disabled peer control, or when an ancestor with the group class has data-disabled="true". Font weight drops to normal when the label contains, or follows, a checkbox, radio-group-item or switch slot. Style it through data-slot="label".
Web preview
Label renders a Text inside a Pressable row. The pressable accepts onPress, onLongPress, onPressIn and onPressOut, so pressing the label can toggle or focus the control next to it. A disabled label is dimmed to 50% opacity.
Installation
- Install the following dependencies:
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/label.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/label.tsx:
- Update the import paths to match your project setup.
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/label.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
With input
Set a nativeID on the label and point the input's accessibilityLabelledBy at it, so screen readers read the label with the input.
Web preview
With checkbox
A label next to a checkbox that toggles it when pressed.
Pass an onPress that toggles the control, which gives a larger touch target.
Web preview
Disabled
A disabled label.
Web preview
Accessibility
- The label text reports its
disabledstate inaccessibilityState. - Link it to its control with
nativeIDon the label andaccessibilityLabelledByon the control.
API Reference
Label
Also accepts the props of React.ComponentProps<typeof LabelPrimitive.Text>.
Text uses the text-foreground token, and opacity-50 when disabled. Inside a Field, use FieldLabel instead.
FieldLabel
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
_ title | LocalizedStringKey | - |
Overloads: init(content:), init(_:), init(_:).
Label
Renders a label element that names and activates its associated control.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
enabled | Boolean | true |
content | @Composable RowScope.() -> Unit | - |
text | String | - |
Overloads: Label(content), Label(text).