Form component is used to ask people for information, such as their contact details or a delivery address.
import { Button, Form, Input, Textarea } from "@kesko/components";
export default () => (
<>
<h2>Contact us</h2>
<Form onSubmit={event => event.preventDefault()}>
<Input label="Name" name="name" autoComplete="name" required hideRequired />
<Input label="Email" name="email" type="email" autoComplete="email" required hideRequired />
<Textarea label="Message" name="message" required hideRequired />
<Button type="submit">Send</Button>
</Form>
</>
);<h2>Contact us</h2>
<form class="k-form" onsubmit="event.preventDefault()">
<k-input>
<label class="k-label" for="name">Name</label>
<div class="k-field">
<input id="name" name="name" autocomplete="name" required />
</div>
</k-input>
<k-input>
<label class="k-label" for="email">Email</label>
<div class="k-field">
<input id="email" name="email" type="email" autocomplete="email" required />
</div>
</k-input>
<k-textarea>
<label class="k-label" for="message">Message</label>
<div class="k-field">
<textarea id="message" name="message" required></textarea>
</div>
</k-textarea>
<button class="k-button" type="submit">Send</button>
</form>import { Button, Form, Input, Stack } from "@kesko/components";
export default () => (
<>
<h2>Store details</h2>
<Form onSubmit={event => event.preventDefault()}>
<Input label="Store name" name="store" required hideRequired />
<Input label="Phone number" name="phone" type="tel" autoComplete="tel" />
<Stack direction="row" gap="xs">
<Button type="submit">Save</Button>
<Button type="reset" appearance="outline">Reset</Button>
</Stack>
</Form>
</>
);<h2>Store details</h2>
<form class="k-form" onsubmit="event.preventDefault()">
<k-input>
<label class="k-label" for="store">Store name</label>
<div class="k-field">
<input id="store" name="store" required />
</div>
</k-input>
<k-input>
<label class="k-label" for="phone">Phone number</label>
<div class="k-field">
<input id="phone" name="phone" type="tel" autocomplete="tel" />
</div>
</k-input>
<k-stack direction="row" gap="xs">
<button class="k-button" type="submit">Save</button>
<button class="k-button" type="reset" appearance="outline">Reset</button>
</k-stack>
</form>import { Button, Checkbox, Fieldset, Form, Grid, Input, Select, Textarea } from "@kesko/components";
export default () => (
<>
<h2>Contact us</h2>
<Form gap="xl" onSubmit={event => event.preventDefault()}>
<Fieldset label="How can we help?">
<Grid style={{ "--k-grid-min": "max(16rem, 34%)" }}>
<Checkbox label="I want a test drive" name="interest" value="test-drive" defaultChecked />
<Checkbox label="I want an offer" name="interest" value="offer" />
<Checkbox label="I want more information" name="interest" value="information" />
<Checkbox label="I want a price for private leasing" name="interest" value="leasing" />
</Grid>
</Fieldset>
<Fieldset label="My details">
<Grid style={{ "--k-grid-min": "max(16rem, 34%)" }}>
<Input label="First name" name="first-name" autoComplete="given-name" required />
<Input label="Last name" name="last-name" autoComplete="family-name" required />
<Input label="Phone number" name="phone" type="tel" autoComplete="tel" />
<Input label="Email" name="email" type="email" autoComplete="email" required />
</Grid>
</Fieldset>
<Fieldset label="More information">
<Select label="Location" name="location" placeholder="Choose a location" required>
<option value="helsinki">Helsinki</option>
<option value="tampere">Tampere</option>
<option value="turku">Turku</option>
</Select>
<Textarea label="Anything else we should know?" name="message" />
</Fieldset>
<Button type="submit">Send contact request</Button>
</Form>
</>
);<h2>Contact us</h2>
<form class="k-form" gap="xl" onsubmit="event.preventDefault()">
<fieldset class="k-fieldset">
<legend class="k-fieldset-legend">How can we help?</legend>
<k-grid style="--k-grid-min: max(16rem, 34%)">
<k-checkbox>
<input type="checkbox" id="test-drive" name="interest" value="test-drive" checked />
<label for="test-drive">I want a test drive</label>
</k-checkbox>
<k-checkbox>
<input type="checkbox" id="offer" name="interest" value="offer" />
<label for="offer">I want an offer</label>
</k-checkbox>
<k-checkbox>
<input type="checkbox" id="information" name="interest" value="information" />
<label for="information">I want more information</label>
</k-checkbox>
<k-checkbox>
<input type="checkbox" id="leasing" name="interest" value="leasing" />
<label for="leasing">I want a price for private leasing</label>
</k-checkbox>
</k-grid>
</fieldset>
<fieldset class="k-fieldset">
<legend class="k-fieldset-legend">My details</legend>
<k-grid style="--k-grid-min: max(16rem, 34%)">
<k-input>
<label class="k-label" for="first-name">First name<span class="k-label-required" aria-hidden="true">*</span></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<span class="k-label-required" aria-hidden="true">*</span></label>
<div class="k-field">
<input id="last-name" name="last-name" autocomplete="family-name" required />
</div>
</k-input>
<k-input>
<label class="k-label" for="phone">Phone number</label>
<div class="k-field">
<input id="phone" name="phone" type="tel" autocomplete="tel" />
</div>
</k-input>
<k-input>
<label class="k-label" for="email">Email<span class="k-label-required" aria-hidden="true">*</span></label>
<div class="k-field">
<input id="email" name="email" type="email" autocomplete="email" required />
</div>
</k-input>
</k-grid>
</fieldset>
<fieldset class="k-fieldset">
<legend class="k-fieldset-legend">More information</legend>
<k-select>
<label class="k-label" for="location">Location<span class="k-label-required" aria-hidden="true">*</span></label>
<div class="k-field">
<select id="location" name="location" required>
<option value="">Choose a location</option>
<option value="helsinki">Helsinki</option>
<option value="tampere">Tampere</option>
<option value="turku">Turku</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-textarea>
<label class="k-label" for="message">Anything else we should know?</label>
<div class="k-field">
<textarea id="message" name="message"></textarea>
</div>
</k-textarea>
</fieldset>
<button class="k-button" type="submit">Send contact request</button>
</form>import { Button, Form, Input } from "@kesko/components";
export default () => (
<>
<h2>Your name</h2>
<Form gap="sm" onSubmit={event => event.preventDefault()}>
<Input label="First name" name="first-name" autoComplete="given-name" required hideRequired />
<Input label="Last name" name="last-name" autoComplete="family-name" required hideRequired />
<Button type="submit">Save</Button>
</Form>
</>
);<h2>Your name</h2>
<form class="k-form" gap="sm" onsubmit="event.preventDefault()">
<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>
<button class="k-button" type="submit">Save</button>
</form>import { Button, Fieldset, Form, Input, Radio } from "@kesko/components";
export default () => (
<>
<h2>Delivery</h2>
<Form gap="xl" onSubmit={event => event.preventDefault()}>
<Fieldset label="Delivery address">
<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>
<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>
<Button type="submit">Continue</Button>
</Form>
</>
);<h2>Delivery</h2>
<form class="k-form" gap="xl" onsubmit="event.preventDefault()">
<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" 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>
<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>
<button class="k-button" type="submit">Continue</button>
</form>import { Button, Form, Input, VisuallyHidden } from "@kesko/components";
import { IconShow } from "@kesko/iconography/react";
export default () => (
<>
<h2>Log in</h2>
<Form onSubmit={event => event.preventDefault()}>
<Input label="Email" name="email" type="email" defaultValue="matti.meikalainen@example.com" disabled />
<Input label="Password" name="password" type="password" defaultValue="password" disabled>
<Button slot="end" appearance="text" square size="sm" disabled>
<IconShow />
<VisuallyHidden>Show password</VisuallyHidden>
</Button>
</Input>
<Button type="submit" loading style={{ inlineSize: "8rem" }}>
Continue
</Button>
</Form>
</>
);<h2>Log in</h2>
<form class="k-form" onsubmit="event.preventDefault()">
<k-input>
<label class="k-label" for="email">Email</label>
<div class="k-field">
<input id="email" name="email" type="email" value="matti.meikalainen@example.com" disabled />
</div>
</k-input>
<k-input>
<label class="k-label" for="password">Password</label>
<div class="k-field">
<input id="password" name="password" type="password" value="password" disabled />
<button slot="end" class="k-button k-button-sm" appearance="text" square type="button" disabled>
<svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M12 7c-2.757 0-5 2.243-5 5s2.243 5 5 5 5-2.243 5-5-2.243-5-5-5zm0 8.5c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5 3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5zm10.697-3.268A11.223 11.223 0 0 1 12 20a11.223 11.223 0 0 1-10.697-7.768.74.74 0 0 1 0-.464A11.223 11.223 0 0 1 12 4c1.047 0 2.07.145 3.04.415.235.065.362.32.268.545l-.278.652a.403.403 0 0 1-.477.228A9.82 9.82 0 0 0 12 5.502a9.726 9.726 0 0 0-9.192 6.5 9.726 9.726 0 0 0 9.192 6.5 9.726 9.726 0 0 0 9.193-6.5A9.718 9.718 0 0 0 17.038 6.9a.403.403 0 0 1-.168-.503l.278-.65a.402.402 0 0 1 .577-.185 11.222 11.222 0 0 1 4.973 6.208.74.74 0 0 1 0 .465z" fill="currentColor" /></svg>
<k-visually-hidden>Show password</k-visually-hidden>
</button>
</div>
</k-input>
<button class="k-button" type="submit" loading aria-disabled="true" onclick="event.preventDefault()" style="inline-size: 8rem">
<k-spinner aria-hidden="true"></k-spinner>
Continue
</button>
</form>import { useState } from "react";
import { Button, Form, Input, Stack, Tooltip, VisuallyHidden } from "@kesko/components";
import { IconHide, IconShow } from "@kesko/iconography/react";
export default () => {
const [shown, setShown] = useState(false);
const toggleLabel = shown ? "Hide password" : "Show password";
return (
<>
<h2 id="login">Log in</h2>
<Form aria-labelledby="login" onSubmit={event => event.preventDefault()}>
<Input label="Email" name="email" type="email" autoComplete="username" required hideRequired />
<Input
label="Password"
name="password"
type={shown ? "text" : "password"}
autoComplete="current-password"
required
hideRequired
>
<Button
slot="end"
appearance="text"
square
size="sm"
aria-describedby="password-toggle"
onClick={() => setShown(!shown)}
>
{shown ? <IconHide /> : <IconShow />}
<VisuallyHidden>{toggleLabel}</VisuallyHidden>
</Button>
</Input>
<Stack direction="row" gap="xs" alignment="center">
<Button type="submit" style={{ inlineSize: "8rem" }}>
Continue
</Button>
<Button appearance="plain" href="#forgot-password">
Forgot password?
</Button>
</Stack>
</Form>
<Tooltip id="password-toggle">{toggleLabel}</Tooltip>
</>
);
};<h2 id="login">Log in</h2>
<form class="k-form" aria-labelledby="login" onsubmit="event.preventDefault()">
<k-input>
<label class="k-label" for="email">Email</label>
<div class="k-field">
<input id="email" name="email" type="email" autocomplete="username" required />
</div>
</k-input>
<k-input>
<label class="k-label" for="password">Password</label>
<div class="k-field">
<input id="password" name="password" type="password" autocomplete="current-password" required />
<button slot="end" class="k-button k-button-sm" appearance="text" square type="button" aria-describedby="password-toggle" id="toggle-password">
<svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M12 7c-2.757 0-5 2.243-5 5s2.243 5 5 5 5-2.243 5-5-2.243-5-5-5zm0 8.5c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5 3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5zm10.697-3.268A11.223 11.223 0 0 1 12 20a11.223 11.223 0 0 1-10.697-7.768.74.74 0 0 1 0-.464A11.223 11.223 0 0 1 12 4c1.047 0 2.07.145 3.04.415.235.065.362.32.268.545l-.278.652a.403.403 0 0 1-.477.228A9.82 9.82 0 0 0 12 5.502a9.726 9.726 0 0 0-9.192 6.5 9.726 9.726 0 0 0 9.192 6.5 9.726 9.726 0 0 0 9.193-6.5A9.718 9.718 0 0 0 17.038 6.9a.403.403 0 0 1-.168-.503l.278-.65a.402.402 0 0 1 .577-.185 11.222 11.222 0 0 1 4.973 6.208.74.74 0 0 1 0 .465z" fill="currentColor" /></svg>
<k-visually-hidden>Show password</k-visually-hidden>
</button>
</div>
</k-input>
<k-stack direction="row" gap="xs" alignment="center">
<button class="k-button" type="submit" style="inline-size: 8rem">Continue</button>
<a class="k-button" href="#forgot-password" appearance="plain">Forgot password?</a>
</k-stack>
</form>
<k-tooltip id="password-toggle" role="tooltip" popover="manual">Show password</k-tooltip>
<script type="module">
import "@kesko/components/vanilla";
const password = document.getElementById("password");
const toggle = document.getElementById("toggle-password");
const icon = toggle.querySelector("path");
const name = toggle.querySelector("k-visually-hidden");
const tooltip = document.getElementById("password-toggle");
const icons = {
show: icon.getAttribute("d"),
hide: "M22.698 11.768a11.271 11.271 0 0 0-5.193-6.326l1.76-2.515a.4.4 0 0 0-.097-.557l-.573-.403a.4.4 0 0 0-.557.098L7.353 17.323a9.733 9.733 0 0 1-4.548-5.328 9.726 9.726 0 0 1 9.193-6.5c.412 0 .827.027 1.237.077a.403.403 0 0 0 .453-.33l.115-.69a.403.403 0 0 0-.348-.465 11.384 11.384 0 0 0-1.457-.095A11.22 11.22 0 0 0 1.3 11.76a.74.74 0 0 0 0 .465 11.225 11.225 0 0 0 5.185 6.332L4.73 21.065a.4.4 0 0 0 .098.557l.572.403a.4.4 0 0 0 .558-.098l1.902-2.715c1.29.508 2.688.785 4.138.785 4.887 0 9.185-3.122 10.697-7.767a.74.74 0 0 0 0-.465zM12 18.5a9.77 9.77 0 0 1-3.247-.555l1.03-1.47a5.01 5.01 0 0 0 2.87.482c2.36-.3 4.2-2.287 4.34-4.66a5.02 5.02 0 0 0-.178-1.65.403.403 0 0 0-.53-.264l-.657.247a.398.398 0 0 0-.243.478c.11.417.142.852.092 1.29a3.518 3.518 0 0 1-3 3.07c-.632.085-1.257 0-1.825-.24l5.988-8.55a9.77 9.77 0 0 1 4.553 5.32 9.726 9.726 0 0 1-9.193 6.5z",
};
toggle.addEventListener("click", () => {
const shown = password.type === "text";
password.type = shown ? "password" : "text";
name.textContent = tooltip.textContent = shown ? "Show password" : "Hide password";
icon.setAttribute("d", shown ? icons.show : icons.hide);
});
</script>import { Button, Fieldset, Form, Grid, Input, Radio, Select, Stack, Switch, Textarea } from "@kesko/components";
export default () => (
<>
<h2>Request an offer</h2>
<Form gap="xl" onSubmit={event => event.preventDefault()}>
<Switch label="I want to trade in my car" name="trade-in" />
<Fieldset label="My details">
<Grid style={{ "--k-grid-min": "max(16rem, 34%)" }}>
<Input label="First name" name="first-name" autoComplete="given-name" required hideRequired />
<Input label="Last name" name="last-name" autoComplete="family-name" required hideRequired />
<Input label="Phone number" name="phone" type="tel" autoComplete="tel" required hideRequired />
<Input label="Email" name="email" type="email" autoComplete="email" required hideRequired />
</Grid>
</Fieldset>
<Fieldset label="Contact me primarily by">
<Fieldset label="Contact method" hideLabel>
<Stack direction="row" gap="lg">
<Radio label="Phone" name="contact" value="by-phone" required hideRequired />
<Radio label="Email" name="contact" value="by-email" required hideRequired />
</Stack>
</Fieldset>
<Select label="Location" name="location" placeholder="Choose a location" required hideRequired>
<option value="helsinki">Helsinki</option>
<option value="tampere">Tampere</option>
<option value="turku">Turku</option>
</Select>
</Fieldset>
<Fieldset label="More information">
<Textarea label="Anything else we should know?" name="message" />
</Fieldset>
<Button type="submit">Send request</Button>
</Form>
</>
);<h2>Request an offer</h2>
<form class="k-form" gap="xl" onsubmit="event.preventDefault()">
<k-switch>
<label class="k-label" for="trade-in">I want to trade in my car</label>
<input type="checkbox" role="switch" id="trade-in" name="trade-in" />
</k-switch>
<fieldset class="k-fieldset">
<legend class="k-fieldset-legend">My details</legend>
<k-grid style="--k-grid-min: max(16rem, 34%)">
<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>
<k-input>
<label class="k-label" for="phone">Phone number</label>
<div class="k-field">
<input id="phone" name="phone" type="tel" autocomplete="tel" required />
</div>
</k-input>
<k-input>
<label class="k-label" for="email">Email</label>
<div class="k-field">
<input id="email" name="email" type="email" autocomplete="email" required />
</div>
</k-input>
</k-grid>
</fieldset>
<fieldset class="k-fieldset">
<legend class="k-fieldset-legend">Contact me primarily by</legend>
<fieldset class="k-fieldset">
<legend class="k-fieldset-legend k-visually-hidden">Contact method</legend>
<k-stack direction="row" gap="lg">
<k-radio>
<input type="radio" id="by-phone" name="contact" value="by-phone" required />
<label for="by-phone">Phone</label>
</k-radio>
<k-radio>
<input type="radio" id="by-email" name="contact" value="by-email" required />
<label for="by-email">Email</label>
</k-radio>
</k-stack>
</fieldset>
<k-select>
<label class="k-label" for="location">Location</label>
<div class="k-field">
<select id="location" name="location" required>
<option value="">Choose a location</option>
<option value="helsinki">Helsinki</option>
<option value="tampere">Tampere</option>
<option value="turku">Turku</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>
</fieldset>
<fieldset class="k-fieldset">
<legend class="k-fieldset-legend">More information</legend>
<k-textarea>
<label class="k-label" for="message">Anything else we should know?</label>
<div class="k-field">
<textarea id="message" name="message"></textarea>
</div>
</k-textarea>
</fieldset>
<button class="k-button" type="submit">Send request</button>
</form>import { Button, Form, Input } from "@kesko/components";
export default () => (
<>
<h2>Create account</h2>
<Form onSubmit={event => event.preventDefault()}>
<Input label="Work email" name="email" type="email" required hideRequired />
<Input label="Username" name="username" defaultValue="matti.meikalainen" error="That username is already taken." />
<Button type="submit">Create account</Button>
</Form>
</>
);<h2>Create account</h2>
<form class="k-form" onsubmit="event.preventDefault()">
<k-input>
<label class="k-label" for="email">Work email</label>
<div class="k-field">
<input id="email" name="email" type="email" required />
</div>
</k-input>
<k-input>
<label class="k-label" for="username">Username</label>
<div class="k-field">
<input id="username" name="username" value="matti.meikalainen" aria-describedby="username-message" aria-invalid="true" />
</div>
<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="username-message">That username is already taken.</span></k-field-message>
</k-input>
<button class="k-button" type="submit">Create account</button>
</form>Properties #
| Name | Description | Type | Default |
|---|---|---|---|
gap | Gap between the fields, mapped to the | "3xs" | "2xs" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "md" |
layout | How the form adapts to its width. | "responsive" | "fixed" | "responsive" |
noValidate | Switches off the browser's own validation, so the form submits without checking | boolean | — |
action | Where the form sends its data. Leave it out when | FormHTMLAttributes<HTMLFormElement>["action"] | — |
method | The HTTP method used with | "get" | "post" | "dialog" | — |
encType | How the data is encoded when it is sent to | "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain" | — |
target | Where the response to | "_self" | "_blank" | "_parent" | "_top" | string | — |
autoComplete | Set to "off" to stop the browser from offering saved values for the fields. Each field can still set its own | "on" | "off" | — |
name | The name of the form, for finding it through | string | — |
role | Set to "search" when the form searches the site or the page, so assistive technology lists it as the search landmark. | FormHTMLAttributes<HTMLFormElement>["role"] | — |
aria-labelledby |
| string | — |
aria-label | Accessible name for the form. Use it only when there is no visible heading to point | string | — |
Events #
| Name | Description | Type |
|---|---|---|
onSubmit | Called when the form is submitted. Unless | (event: SyntheticEvent<HTMLFormElement>) => void |
onReset | Called when the form is reset, for example by a button with | (event: SyntheticEvent<HTMLFormElement>) => void |
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-form-gap | Overrides the space between the fields. | var(--k-space-md) |
--k-form-breakpoint | Overrides the form width below which the buttons fill the width. | 30rem |
Accessibility #
Form is built on a native <form> element, so people can send it with Enter, and the browser validates the fields and offers to fill them in.
- Give the form a heading. Put one above it, or rely on the title of the dialog it sits in, so people know what they are filling in. When the form is a part of a longer page, use
aria-labelledbyso screen reader users can find it among the page’s landmarks. - Group related fields with Fieldset. Form holds everything people fill in and send together. Fieldset names the parts inside it that share one meaning, such as an address or one choice.
- Keep messages on the fields. Form has no errors of its own. An error about one field goes in that field’s
error, and an error about a group goes on its Fieldset, so each one is read with the thing it is about. - Let the browser validate. Fields marked
requiredor given atypeare checked on submit, and the first one that fails gets focus and shows its message in the page’s language. A standard form needs no form library and no wrapper components, see Forms. PassnoValidateonly when you check the values yourself. - Always include a submit button. A Button with
type="submit"lets people send the form with Enter from a text field.
See the accessibility guidelines and the A11Y checklist for more details.
Usage #
There are two necessary parts to using the Form 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 Form:
import { Form } 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.