Rendered by GPUI’s web backend from the real component. Requires a browser with WebGPU.
Label::new(id, &focus_handle, text) renders plain text with native Label
semantics and an accessible name matching that text. Clicking it focuses the
supplied existing control. The Label has no focus handle or Tab stop of its own,
so ordinary keyboard traversal remains with the control. Its Styled interface
supplies application-owned text style and layout; it accepts text rather than
interactive child content.
let preview = self.preview.read(cx);
let label = Label::new(
"preview-percentage-label",
preview.thumb_focus_handle(0),
"Preview percentage",
)
.disabled(preview.is_disabled())
.text_color(muted);
let slider = Slider::new("preview-percentage", &self.preview)
.accessibility_label("Preview percentage")
.child(SliderThumb::new(&self.preview, 0).accessibility_label("Preview percentage"));
div().flex().flex_col().gap_1().child(label).child(slider)Keep the referenced target mounted in the same window, and mirror its disabled
state with .disabled(bool) on every render. A disabled Label does not move
focus. The supplied FocusHandle identifies the target but does not tell Label
whether the control is enabled; the application owns that policy and redraws
when it changes. Label retains no second control state.
The focus action does not activate the target: it does not open Select, adjust Slider, or toggle Checkbox/Switch. The native example uses it above Drawing tool and Preview percentage; clicking either label leaves the selection or value unchanged before the control receives ordinary keyboard input.
Set the target's accessibility_label(...) independently. The pinned GPUI API
does not expose a public labelled-by relationship for these sibling elements,
so Label does not automatically name the target. Its native Label role and text
name describe the label itself. For Input/Textarea label, help, and validation
association, use Field, which projects metadata onto its retained input and
checks the input's live disabled state when its label is clicked.