Label component is used as a text label for items in an interface. Most often used inside other form components.
import { Label } from "@kesko/components";
export default () => (
<Label>Default label</Label>
);<label class="k-label">Default label</label>import { Label } from "@kesko/components";
const subtle = {
"--k-label-text": "var(--k-color-text-dim)",
"--k-label-weight": "var(--k-font-weight-medium)",
"--k-label-required": "var(--k-color-status-error)",
};
export default () => (
<Label required style={subtle}>
Custom label
</Label>
);<label
class="k-label"
style="
--k-label-text: var(--k-color-text-dim);
--k-label-weight: var(--k-font-weight-medium);
--k-label-required: var(--k-color-status-error);"
>Custom label<span class="k-label-required" aria-hidden="true">*</span></label>import { Label } from "@kesko/components";
export default () => (
<Label required>Required label</Label>
);<label class="k-label">Required label<span class="k-label-required" aria-hidden="true">*</span></label>Properties #
| Name | Description | Type | Default |
|---|---|---|---|
htmlFor | The | string | — |
required | Shows a required marker after the text. The marker is decorative, set | boolean | false |
Styles #
CSS custom properties provide finer-grained control than properties. See Styling API for more details. Prefer the Properties API when it suits your need.
| Name | Description | Default |
|---|---|---|
--k-label-text | Overrides the text color. | var(--k-color-text-base) |
--k-label-weight | Overrides the font weight. | var(--k-font-weight-bold) |
--k-label-size | Overrides the font size. | var(--k-font-size-md) |
--k-label-required | Overrides the required indicator color. Defaults to the label text color. | currentColor |
Accessibility #
Label is built on a native <label>, so it behaves as expected with assistive technologies.
- Point it at the control. Set
htmlForto the control'sid. That is what makes a screen reader read the label as the control's name and what makes a click on the label focus the control. Wrapping the control inside the label works too. - Keep it visible. Placeholder text disappears as soon as someone types. If a label really has no room, wrap it in Visually Hidden rather than leaving it out.
requiredonly draws the marker. It is hidden from assistive technology. Setrequiredon the control as well, which is what gets announced and what blocks the form from submitting.- Check contrast if you override the color.
--k-label-textneeds 4.5:1 against the surface the label sits on. Verify with the WebAIM contrast checker.
See the accessibility guidelines and the A11Y checklist for more details.
Usage #
There are two necessary parts to using the Label component. The @kesko/components package and the CSS Framework are required. Everything else is optional:
npm install @kesko/components @kesko/csspnpm add @kesko/components @kesko/cssyarn add @kesko/components @kesko/cssbun add @kesko/components @kesko/cssOnce installed, load the CSS Framework in your app’s entry point or root layout:
import "@kesko/css";Then, you can import the Label:
import { Label } from "@kesko/components";Projects without React can get the same styles from @kesko/css by importing the components stylesheet as well:
@import "@kesko/css";
@import "@kesko/css/components";Resources #
Usage guidelines
Learn how to use the component library with React, Next.js, or basic HTML.
Localization
How to translate the components for multiple languages.
CSS Framework
Utilities and tokens for everything the components don’t cover.
Themes
How to customize the component library theme.
Accessibility checklist
Interactive, browser-based Kesko accessibility checklist.