Fieldset component is used to group together several related form controls. This helps to make these groups accessible for assistive technologies.
import { Fieldset, Input, Select } from "@kesko/components";
export default () => (
<Fieldset label="Delivery address">
<Input label="Street address" name="street" autoComplete="street-address" />
<Select label="City" name="city" placeholder="Choose a city">
<option value="helsinki">Helsinki</option>
<option value="espoo">Espoo</option>
<option value="vantaa">Vantaa</option>
</Select>
<Input label="Postal code" name="postal" inputMode="numeric" autoComplete="postal-code" />
</Fieldset>
);<fieldset class="k-fieldset">
<legend class="k-fieldset-legend">Delivery address</legend>
<k-input>
<label class="k-label" for="street">Street address</label>
<div class="k-field">
<input id="street" name="street" autocomplete="street-address" />
</div>
</k-input>
<k-select>
<label class="k-label" for="city">City</label>
<div class="k-field">
<select id="city" name="city">
<option value="">Choose a city</option>
<option value="helsinki">Helsinki</option>
<option value="espoo">Espoo</option>
<option value="vantaa">Vantaa</option>
</select>
<svg slot="end" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M18.747 10.313l-6.465 6.464a.401.401 0 0 1-.565 0l-6.464-6.465a.401.401 0 0 1 0-.564l.495-.495a.401.401 0 0 1 .565 0L12 14.94l5.688-5.687a.401.401 0 0 1 .565 0l.495.495a.401.401 0 0 1 0 .565z" fill="currentColor" /></svg>
</div>
</k-select>
<k-input>
<label class="k-label" for="postal">Postal code</label>
<div class="k-field">
<input id="postal" name="postal" inputmode="numeric" autocomplete="postal-code" />
</div>
</k-input>
</fieldset>import { Fieldset, Input, Textarea } from "@kesko/components";
export default () => (
<Fieldset label="Contact person" description="Who the driver calls if nobody answers the door.">
<Input label="Name" name="contact-name" autoComplete="name" />
<Input label="Phone" name="contact-phone" type="tel" autoComplete="tel" />
<Textarea label="Delivery instructions" name="instructions" placeholder="Door code, floor, where to leave the order" />
</Fieldset>
);<fieldset class="k-fieldset" aria-describedby="contact-description">
<legend class="k-fieldset-legend">Contact person</legend>
<p class="k-field-description" id="contact-description">Who the driver calls if nobody answers the door.</p>
<k-input>
<label class="k-label" for="contact-name">Name</label>
<div class="k-field">
<input id="contact-name" name="contact-name" autocomplete="name" />
</div>
</k-input>
<k-input>
<label class="k-label" for="contact-phone">Phone</label>
<div class="k-field">
<input id="contact-phone" name="contact-phone" type="tel" autocomplete="tel" />
</div>
</k-input>
<k-textarea>
<label class="k-label" for="instructions">Delivery instructions</label>
<div class="k-field">
<textarea id="instructions" name="instructions" placeholder="Door code, floor, where to leave the order"></textarea>
</div>
</k-textarea>
</fieldset>import { Checkbox, Fieldset } from "@kesko/components";
export default () => (
<Fieldset label="Order updates">
<Checkbox label="Email" name="updates" value="email" defaultChecked />
<Checkbox label="Text message" name="updates" value="text" />
<Checkbox label="Push notification" name="updates" value="push" />
</Fieldset>
);<fieldset class="k-fieldset">
<legend class="k-fieldset-legend">Order updates</legend>
<k-checkbox>
<input type="checkbox" id="email" name="updates" value="email" checked />
<label for="email">Email</label>
</k-checkbox>
<k-checkbox>
<input type="checkbox" id="text" name="updates" value="text" />
<label for="text">Text message</label>
</k-checkbox>
<k-checkbox>
<input type="checkbox" id="push" name="updates" value="push" />
<label for="push">Push notification</label>
</k-checkbox>
</fieldset>import { Fieldset, Input } from "@kesko/components";
const compact = {
"--k-fieldset-gap": "var(--k-space-2xs)",
"--k-fieldset-border": "var(--k-color-border-primary)",
"--k-fieldset-radius": "var(--k-radius-md)",
"--k-fieldset-legend-size": "var(--k-font-size-md)",
"--k-fieldset-legend-text": "var(--k-color-text-primary)",
};
export default () => (
<Fieldset label="Card holder" variant="outline" style={compact}>
<Input label="First name" name="first-name" autoComplete="given-name" />
<Input label="Last name" name="last-name" autoComplete="family-name" />
</Fieldset>
);<fieldset
class="k-fieldset"
variant="outline"
style="
--k-fieldset-gap: var(--k-space-2xs);
--k-fieldset-border: var(--k-color-border-primary);
--k-fieldset-radius: var(--k-radius-md);
--k-fieldset-legend-size: var(--k-font-size-md);
--k-fieldset-legend-text: var(--k-color-text-primary);"
>
<legend class="k-fieldset-legend">Card holder</legend>
<k-input>
<label class="k-label" for="first-name">First name</label>
<div class="k-field">
<input id="first-name" name="first-name" autocomplete="given-name" />
</div>
</k-input>
<k-input>
<label class="k-label" for="last-name">Last name</label>
<div class="k-field">
<input id="last-name" name="last-name" autocomplete="family-name" />
</div>
</k-input>
</fieldset>import { Fieldset, Input, Select } from "@kesko/components";
export default () => (
<Fieldset label="Delivery address" disabled>
<Input label="Street address" name="street" autoComplete="street-address" />
<Select label="City" name="city" placeholder="Choose a city">
<option value="helsinki">Helsinki</option>
<option value="espoo">Espoo</option>
<option value="vantaa">Vantaa</option>
</Select>
<Input label="Postal code" name="postal" inputMode="numeric" autoComplete="postal-code" />
</Fieldset>
);<fieldset class="k-fieldset" disabled>
<legend class="k-fieldset-legend">Delivery address</legend>
<k-input>
<label class="k-label" for="street">Street address</label>
<div class="k-field">
<input id="street" name="street" autocomplete="street-address" />
</div>
</k-input>
<k-select>
<label class="k-label" for="city">City</label>
<div class="k-field">
<select id="city" name="city">
<option value="">Choose a city</option>
<option value="helsinki">Helsinki</option>
<option value="espoo">Espoo</option>
<option value="vantaa">Vantaa</option>
</select>
<svg slot="end" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M18.747 10.313l-6.465 6.464a.401.401 0 0 1-.565 0l-6.464-6.465a.401.401 0 0 1 0-.564l.495-.495a.401.401 0 0 1 .565 0L12 14.94l5.688-5.687a.401.401 0 0 1 .565 0l.495.495a.401.401 0 0 1 0 .565z" fill="currentColor" /></svg>
</div>
</k-select>
<k-input>
<label class="k-label" for="postal">Postal code</label>
<div class="k-field">
<input id="postal" name="postal" inputmode="numeric" autocomplete="postal-code" />
</div>
</k-input>
</fieldset>import { Fieldset, Input, Radio } from "@kesko/components";
export default () => (
<Fieldset label="Delivery address">
<Input label="Street address" name="street" autoComplete="street-address" />
<Input label="Postal code" name="postal" inputMode="numeric" autoComplete="postal-code" />
<Fieldset label="If nobody is home">
<Radio label="Leave the order at the door" name="absent" value="door" defaultChecked />
<Radio label="Take the order back to the store" name="absent" value="store" />
</Fieldset>
</Fieldset>
);<fieldset class="k-fieldset">
<legend class="k-fieldset-legend">Delivery address</legend>
<k-input>
<label class="k-label" for="street">Street address</label>
<div class="k-field">
<input id="street" name="street" autocomplete="street-address" />
</div>
</k-input>
<k-input>
<label class="k-label" for="postal">Postal code</label>
<div class="k-field">
<input id="postal" name="postal" inputmode="numeric" autocomplete="postal-code" />
</div>
</k-input>
<fieldset class="k-fieldset">
<legend class="k-fieldset-legend">If nobody is home</legend>
<k-radio>
<input type="radio" id="door" name="absent" value="door" checked />
<label for="door">Leave the order at the door</label>
</k-radio>
<k-radio>
<input type="radio" id="store" name="absent" value="store" />
<label for="store">Take the order back to the store</label>
</k-radio>
</fieldset>
</fieldset>import { Fieldset, Input, Select } from "@kesko/components";
export default () => (
<Fieldset label="Delivery address" variant="outline">
<Input label="Street address" name="street" autoComplete="street-address" />
<Select label="City" name="city" placeholder="Choose a city">
<option value="helsinki">Helsinki</option>
<option value="espoo">Espoo</option>
<option value="vantaa">Vantaa</option>
</Select>
<Input label="Postal code" name="postal" inputMode="numeric" autoComplete="postal-code" />
</Fieldset>
);<fieldset class="k-fieldset" variant="outline">
<legend class="k-fieldset-legend">Delivery address</legend>
<k-input>
<label class="k-label" for="street">Street address</label>
<div class="k-field">
<input id="street" name="street" autocomplete="street-address" />
</div>
</k-input>
<k-select>
<label class="k-label" for="city">City</label>
<div class="k-field">
<select id="city" name="city">
<option value="">Choose a city</option>
<option value="helsinki">Helsinki</option>
<option value="espoo">Espoo</option>
<option value="vantaa">Vantaa</option>
</select>
<svg slot="end" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M18.747 10.313l-6.465 6.464a.401.401 0 0 1-.565 0l-6.464-6.465a.401.401 0 0 1 0-.564l.495-.495a.401.401 0 0 1 .565 0L12 14.94l5.688-5.687a.401.401 0 0 1 .565 0l.495.495a.401.401 0 0 1 0 .565z" fill="currentColor" /></svg>
</div>
</k-select>
<k-input>
<label class="k-label" for="postal">Postal code</label>
<div class="k-field">
<input id="postal" name="postal" inputmode="numeric" autocomplete="postal-code" />
</div>
</k-input>
</fieldset>import { Fieldset, Radio } from "@kesko/components";
export default () => (
<Fieldset label="Payment method">
<Radio label="Card" name="payment" value="card" defaultChecked />
<Radio label="Invoice" name="payment" value="invoice" />
<Radio label="Pay at pickup" name="payment" value="pickup" />
</Fieldset>
);<fieldset class="k-fieldset">
<legend class="k-fieldset-legend">Payment method</legend>
<k-radio>
<input type="radio" id="card" name="payment" value="card" checked />
<label for="card">Card</label>
</k-radio>
<k-radio>
<input type="radio" id="invoice" name="payment" value="invoice" />
<label for="invoice">Invoice</label>
</k-radio>
<k-radio>
<input type="radio" id="pickup" name="payment" value="pickup" />
<label for="pickup">Pay at pickup</label>
</k-radio>
</fieldset>import { Fieldset, Input, Stack } from "@kesko/components";
export default () => (
<Stack gap="xl" alignment="stretch">
<Fieldset label="Card holder" required>
<Input label="First name" name="first-name" autoComplete="given-name" required hideRequired />
<Input label="Last name" name="last-name" autoComplete="family-name" required hideRequired />
</Fieldset>
<Fieldset label="Billing address" required hideRequired>
<Input label="Street address" name="street" autoComplete="street-address" required hideRequired />
<Input label="Postal code" name="postal" inputMode="numeric" autoComplete="postal-code" required hideRequired />
</Fieldset>
</Stack>
);<k-stack gap="xl" alignment="stretch">
<fieldset class="k-fieldset">
<legend class="k-fieldset-legend">Card holder<span class="k-label-required" aria-hidden="true">*</span></legend>
<k-input>
<label class="k-label" for="first-name">First name</label>
<div class="k-field">
<input id="first-name" name="first-name" autocomplete="given-name" required />
</div>
</k-input>
<k-input>
<label class="k-label" for="last-name">Last name</label>
<div class="k-field">
<input id="last-name" name="last-name" autocomplete="family-name" required />
</div>
</k-input>
</fieldset>
<fieldset class="k-fieldset">
<legend class="k-fieldset-legend">Billing address</legend>
<k-input>
<label class="k-label" for="street">Street address</label>
<div class="k-field">
<input id="street" name="street" autocomplete="street-address" required />
</div>
</k-input>
<k-input>
<label class="k-label" for="postal">Postal code</label>
<div class="k-field">
<input id="postal" name="postal" inputmode="numeric" autocomplete="postal-code" required />
</div>
</k-input>
</fieldset>
</k-stack>import { Fieldset, Input, Select, Stack } from "@kesko/components";
export default () => (
<Fieldset label="Amount">
<Stack direction="row">
<Input label="Quantity" name="quantity" inputMode="numeric" defaultValue="2" style={{ "--k-input-inline-size": "8rem" }} />
<Select label="Unit" name="unit" defaultValue="kg" style={{ "--k-select-inline-size": "8rem" }}>
<option value="kg">kg</option>
<option value="g">g</option>
<option value="pcs">pcs</option>
</Select>
</Stack>
<Input label="Note to the picker" name="note" placeholder="Ripe ones, please" />
</Fieldset>
);<fieldset class="k-fieldset">
<legend class="k-fieldset-legend">Amount</legend>
<k-stack direction="row">
<k-input style="--k-input-inline-size: 8rem;">
<label class="k-label" for="quantity">Quantity</label>
<div class="k-field">
<input id="quantity" name="quantity" inputmode="numeric" value="2" />
</div>
</k-input>
<k-select style="--k-select-inline-size: 8rem;">
<label class="k-label" for="unit">Unit</label>
<div class="k-field">
<select id="unit" name="unit">
<option value="kg" selected>kg</option>
<option value="g">g</option>
<option value="pcs">pcs</option>
</select>
<svg slot="end" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M18.747 10.313l-6.465 6.464a.401.401 0 0 1-.565 0l-6.464-6.465a.401.401 0 0 1 0-.564l.495-.495a.401.401 0 0 1 .565 0L12 14.94l5.688-5.687a.401.401 0 0 1 .565 0l.495.495a.401.401 0 0 1 0 .565z" fill="currentColor" /></svg>
</div>
</k-select>
</k-stack>
<k-input>
<label class="k-label" for="note">Note to the picker</label>
<div class="k-field">
<input id="note" name="note" placeholder="Ripe ones, please" />
</div>
</k-input>
</fieldset>import { Fieldset, Input } from "@kesko/components";
export default () => (
<Fieldset label="Delivery address" error="We don't deliver to this address yet.">
<Input label="Street address" name="street" defaultValue="Satamakatu 3" autoComplete="street-address" />
<Input label="Postal code" name="postal" defaultValue="48100" inputMode="numeric" autoComplete="postal-code" />
</Fieldset>
);<fieldset class="k-fieldset" aria-describedby="address-message">
<legend class="k-fieldset-legend">Delivery address</legend>
<k-input>
<label class="k-label" for="street">Street address</label>
<div class="k-field">
<input id="street" name="street" value="Satamakatu 3" autocomplete="street-address" />
</div>
</k-input>
<k-input>
<label class="k-label" for="postal">Postal code</label>
<div class="k-field">
<input id="postal" name="postal" value="48100" inputmode="numeric" autocomplete="postal-code" />
</div>
</k-input>
<k-field-message variant="error" role="alert"><svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M22.113 18.023L13.745 3.08c-.75-1.343-2.738-1.338-3.49 0L1.888 18.023C1.153 19.332 2.13 21 3.633 21h16.735c1.503 0 2.476-1.666 1.745-2.978zM20.367 19.5H3.633a.504.504 0 0 1-.435-.745l8.364-14.94a.506.506 0 0 1 .875 0l8.368 14.942a.501.501 0 0 1-.438.743zm-8.885-5.66l-.31-4.785c0-.115.08-.195.194-.195h1.265c.116 0 .196.08.196.195l-.3 4.613c0 .127-.058.217-.208.242l-.61.102c-.128.023-.217-.035-.23-.172zM13 16.14c0 .552-.403.978-1 .978s-1-.425-1-.978.403-.965 1-.965 1 .425 1 .965z" fill="currentColor" /></svg><span id="address-message">We don't deliver to this address yet.</span></k-field-message>
</fieldset>Properties #
| Name | Description | Type | Default |
|---|---|---|---|
label | Label for the group, rendered as the | ReactNode | — |
hideLabel | Hides the legend visually while keeping it available to assistive technology. | boolean | false |
variant | The style of the group. | "plain" | "outline" | "plain" |
description | Assistive text for the whole group, shown under the legend. | ReactNode | — |
error | Optional error message for the whole group, shown after the fields. Use it for an error no single field owns, such as a choice missing from a group of radio buttons. When a required group of radio buttons has nothing selected on submit, a built-in message shows here on its own; | ReactNode | — |
required | Draws the required marker on the legend. The controls inside decide what is actually required. | boolean | false |
hideRequired | Hides the required marker on the legend. Use it when the form says once that every field is required. | boolean | false |
disabled | Disables every control inside the group and drops their values from the submitted data. | boolean | — |
name | The name of the group. | string | — |
form | The | string | — |
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-fieldset-gap | Overrides the space between the legend, the fields and the messages. | var(--k-space-md) |
--k-fieldset-border | Overrides the border color of the outline variant. | var(--k-color-text-base) |
--k-fieldset-radius | Overrides the border radius of the outline variant. | var(--k-radius-lg) |
--k-fieldset-legend-size | Overrides the font size of the legend. | var(--k-font-size-lg) |
--k-fieldset-legend-text | Overrides the text color of the legend. | var(--k-color-text-base) |
Accessibility #
Fieldset is built on a native <fieldset> with a <legend>, so assistive technology reads the label as the name of the group and announces it with the controls inside.
- Always pass a
label. The label is what names the group. If there is no room for it, passhideLabelrather than leaving it out. - Keep the label short. Some screen readers read it before every control's own label, so a long one is repeated many times. Put detail in
descriptioninstead. - Group only what belongs together. A fieldset earns its place when the fields share one meaning, such as the lines of an address or the options of one choice. A group that already has a name, such as a form under its own heading or inside a dialog, does not need a second one from a Fieldset.
- Fieldset is not a form. Put everything people fill in and send together inside a Form. Fieldset names the parts inside it that share one meaning.
- Put a group's error on the group. An error no single field owns, such as nothing chosen in a group of radio buttons, goes in
errorso it is read with the group. An error about one field stays on that field. The message shows after everything in the group, so when radio buttons share a group with other fields, give the radio buttons a Fieldset of their own. A required Radio group that is left empty shows the browser's own message here without any extra code. disabledswitches off every control inside. Reach for it only when the whole group does not apply right now, and say why nearby. Disabled controls leave the tab order and cannot explain themselves.- Check contrast if you override colors. The label needs 4.5:1 against the surface, and
--k-fieldset-borderneeds 3:1 against it in the outline variant. 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 Fieldset 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 Fieldset:
import { Fieldset } 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.