Skip to content

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.

MethodTypeDefaultDescription
.id(id)impl Into<SharedString>textOverride the element id
.associated_focus(&handle)&FocusHandleClicking 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.

Released under the MIT License.