Label
A text label associated with a form control. Clicking the label focuses the associated control.
When to use
- Labeling inputs, checkboxes, and switches.
- Making form controls more accessible (click-to-focus).
API
Label::new(text)
Creates a label with the given text. The element id defaults to the text.
| Method | Type | Default | Description |
|---|---|---|---|
.id(id) | impl Into<SharedString> | text | Override the element id |
.associated_focus(&handle) | &FocusHandle | — | Clicking the label focuses the target |
Usage
rust
use gpui::{Component, div, prelude::*};
use components::Label;
div().child(Component::new(
Label::new("Email Address").associated_focus(&input_focus_handle),
))Copy the source
crates/components/src/label.rs — self-contained, stateless, and free to modify.