nativeLabel
nativeLabel creates a text caption associated with another component.
XML Element |
|
|---|---|
Java Class |
|
Basics
Use nativeLabel when a separate label component is needed instead of a component’s label attribute.
Set setFor to the ID of the component that the label describes. The following example associates a label with a checkbox:
<div>
<checkbox id ="checkbox"/>
<nativeLabel text="Enable Notifications" setFor="checkbox"/>
</div>
Having the label associated with a component makes the label text correctly interpreted by assistive technologies, such as screen readers.
To add text that is not associated with a component, use the span or div components.
Dynamic Label
Assign an ID to nativeLabel, inject it into the controller, and call setText() to update its text:
<nativeLabel id="dynamicLabel" setFor="button"/>
<button id="button" text="Click"/>
@ViewComponent
private NativeLabel dynamicLabel;
@Subscribe("button")
public void onButtonClick(final ClickEvent<JmixButton> event) {
dynamicLabel.setText("Button clicked " + event.getClickCount() + " times.");
}
Theme Variants
Use the themeNames attribute to style the label as a badge. Combine badge with color, emphasis, shape, or size variants.
| Variant | Description | Supported By |
|---|---|---|
|
Applies badge styling. |
Aura, Lumo |
|
Applies a semantic color. |
Aura, Lumo |
|
Adds stronger visual emphasis. |
Aura, Lumo |
|
Rounds the badge corners. |
Aura, Lumo |
|
Makes the badge smaller. |
Aura, Lumo |
|
Uses the regular badge size. |
Aura, Lumo |
Attributes
Common attributes serve the same purpose for all components.
The following attributes are specific to nativeLabel:
| Name | Description | Default |
|---|---|---|
Applies one or more variants listed in Theme Variants. |
— |
|
Associates the label with the component whose ID is specified, enabling assistive technologies to interpret the relationship. |
— |
Handlers
| Name | Description |
|---|---|
Fires when the label is attached to the UI. |
|
Fires when the label is detached from the UI. |