Input component allows users to enter text that fits on a single line. For longer text, use the Textarea component. When placed next to a Button, give both the same size so their heights match.
import { Input } from "@kesko/components";
export default () => <Input label="Label" name="input" placeholder="Placeholder" />;<k-input>
<label class="k-label" for="input">Label</label>
<div class="k-field">
<input id="input" name="input" placeholder="Placeholder" />
</div>
</k-input>import { Input } from "@kesko/components";
export default () => (
<Input
label="K-Plussa card number"
name="card"
inputMode="numeric"
autoComplete="off"
description="The 16 digits printed on the front of the card."
/>
);<k-input>
<label class="k-label" for="card">K-Plussa card number</label>
<div class="k-field">
<input id="card" name="card" inputmode="numeric" autocomplete="off" aria-describedby="card-description" />
</div>
<p class="k-field-description" id="card-description">The 16 digits printed on the front of the card.</p>
</k-input>import { Input } from "@kesko/components";
export default () => <Input label="Email" type="email" name="email" autoComplete="email" />;<k-input>
<label class="k-label" for="email">Email</label>
<div class="k-field">
<input id="email" type="email" name="email" autocomplete="email" />
</div>
</k-input>import { Input } 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 () => <Input label="Custom label" name="custom" required style={subtle} />;<k-input
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);"
>
<label class="k-label" for="custom">Custom label<span class="k-label-required" aria-hidden="true">*</span></label>
<div class="k-field">
<input id="custom" name="custom" required />
</div>
</k-input>import { Input, Stack } from "@kesko/components";
export default () => (
<Stack direction="row">
<Input
label="Postal code"
inputMode="numeric"
autoComplete="postal-code"
style={{ "--k-input-inline-size": "9rem" }}
/>
<Input label="Year" inputMode="numeric" style={{ "--k-input-inline-size": "6rem" }} />
<Input label="City" autoComplete="address-level2" style={{ "--k-input-inline-size": "16rem" }} />
</Stack>
);<k-stack direction="row">
<k-input style="--k-input-inline-size: 9rem;">
<label class="k-label" for="postal-code">Postal code</label>
<div class="k-field">
<input id="postal-code" inputmode="numeric" autocomplete="postal-code" />
</div>
</k-input>
<k-input style="--k-input-inline-size: 6rem;">
<label class="k-label" for="year">Year</label>
<div class="k-field">
<input id="year" inputmode="numeric" />
</div>
</k-input>
<k-input style="--k-input-inline-size: 16rem;">
<label class="k-label" for="city">City</label>
<div class="k-field">
<input id="city" autocomplete="address-level2" />
</div>
</k-input>
</k-stack>import { Input, Stack } from "@kesko/components";
import { IconLockClosed, IconSearch } from "@kesko/iconography/react";
export default () => (
<Stack>
<Input label="Store" name="store" defaultValue="K-Citymarket Sello" disabled />
<Input label="Search products" type="search" placeholder="Search" disabled>
<IconSearch slot="start" />
</Input>
<Input label="Customer number" name="customer" defaultValue="1234567" disabled>
<IconLockClosed slot="start" />
</Input>
</Stack>
);<k-stack>
<k-input>
<label class="k-label" for="store">Store</label>
<div class="k-field">
<input id="store" name="store" value="K-Citymarket Sello" disabled />
</div>
</k-input>
<k-input>
<label class="k-label" for="search">Search products</label>
<div class="k-field">
<svg slot="start" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M10 3c-3.86 0-7 3.14-7 7s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm0 12.5c-3.033 0-5.5-2.467-5.5-5.5S6.967 4.5 10 4.5s5.5 2.467 5.5 5.5-2.467 5.5-5.5 5.5zm10.248 4.253l-.495.495a.401.401 0 0 1-.565 0l-3.435-3.435a.401.401 0 0 1 0-.565l.494-.495a.401.401 0 0 1 .565 0l3.435 3.435a.401.401 0 0 1 0 .565z" fill="currentColor" /></svg>
<input id="search" type="search" placeholder="Search" disabled />
</div>
</k-input>
<k-input>
<label class="k-label" for="customer">Customer number</label>
<div class="k-field">
<svg slot="start" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M17.25 9h-1.28V6.97a3.974 3.974 0 0 0-4.17-3.965c-2.132.105-3.77 1.945-3.77 4.08V9H6.75C5.783 9 5 9.782 5 10.75v6.5C5 19.32 6.68 21 8.75 21h6.5c2.07 0 3.75-1.68 3.75-3.75v-6.5C19 9.782 18.218 9 17.25 9zM9.53 6.97c0-1.362 1.108-2.47 2.47-2.47s2.47 1.107 2.47 2.47V9H9.53zm7.97 10.28a2.25 2.25 0 0 1-2.25 2.25h-6.5a2.25 2.25 0 0 1-2.25-2.25v-6.5a.25.25 0 0 1 .25-.25h10.5a.25.25 0 0 1 .25.25zm-4-3.25a1.5 1.5 0 0 1-.75 1.298V16.6c0 .22-.18.4-.4.4h-.7c-.22 0-.4-.18-.4-.4v-1.303c-.512-.297-.833-.885-.73-1.537s.645-1.173 1.3-1.25A1.502 1.502 0 0 1 13.503 14z" fill="currentColor" /></svg>
<input id="customer" name="customer" value="1234567" disabled />
</div>
</k-input>
</k-stack>import { Input, Stack } from "@kesko/components";
import { IconCalendar, IconLockClosed, IconMail, IconSearch } from "@kesko/iconography/react";
export default () => (
<Stack>
<Input label="Search products" type="search" placeholder="Search">
<IconSearch slot="start" />
</Input>
<Input label="Password" type="password" autoComplete="current-password">
<IconLockClosed slot="start" />
</Input>
<Input label="Email" type="email" autoComplete="email" placeholder="name@kesko.fi">
<IconMail slot="end" />
</Input>
<Input label="Delivery date" placeholder="DD.MM.YYYY" inputMode="numeric">
<IconCalendar slot="end" />
</Input>
</Stack>
);<k-stack>
<k-input>
<label class="k-label" for="search">Search products</label>
<div class="k-field">
<svg slot="start" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M10 3c-3.86 0-7 3.14-7 7s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm0 12.5c-3.033 0-5.5-2.467-5.5-5.5S6.967 4.5 10 4.5s5.5 2.467 5.5 5.5-2.467 5.5-5.5 5.5zm10.248 4.253l-.495.495a.401.401 0 0 1-.565 0l-3.435-3.435a.401.401 0 0 1 0-.565l.494-.495a.401.401 0 0 1 .565 0l3.435 3.435a.401.401 0 0 1 0 .565z" fill="currentColor" /></svg>
<input id="search" type="search" placeholder="Search" />
</div>
</k-input>
<k-input>
<label class="k-label" for="password">Password</label>
<div class="k-field">
<svg slot="start" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M17.25 9h-1.28V6.97a3.974 3.974 0 0 0-4.17-3.965c-2.132.105-3.77 1.945-3.77 4.08V9H6.75C5.783 9 5 9.782 5 10.75v6.5C5 19.32 6.68 21 8.75 21h6.5c2.07 0 3.75-1.68 3.75-3.75v-6.5C19 9.782 18.218 9 17.25 9zM9.53 6.97c0-1.362 1.108-2.47 2.47-2.47s2.47 1.107 2.47 2.47V9H9.53zm7.97 10.28a2.25 2.25 0 0 1-2.25 2.25h-6.5a2.25 2.25 0 0 1-2.25-2.25v-6.5a.25.25 0 0 1 .25-.25h10.5a.25.25 0 0 1 .25.25zm-4-3.25a1.5 1.5 0 0 1-.75 1.298V16.6c0 .22-.18.4-.4.4h-.7c-.22 0-.4-.18-.4-.4v-1.303c-.512-.297-.833-.885-.73-1.537s.645-1.173 1.3-1.25A1.502 1.502 0 0 1 13.503 14z" fill="currentColor" /></svg>
<input id="password" type="password" autocomplete="current-password" />
</div>
</k-input>
<k-input>
<label class="k-label" for="email">Email</label>
<div class="k-field">
<input id="email" type="email" autocomplete="email" placeholder="name@kesko.fi" />
<svg slot="end" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M22 6.75v10.5c0 .968-.782 1.75-1.75 1.75H3.75C2.782 19 2 18.218 2 17.25V11.4c0-.22.18-.4.4-.4h.7c.22 0 .4.18.4.4v5.85c0 .138.112.25.25.25h16.5a.25.25 0 0 0 .25-.25V6.75a.25.25 0 0 0-.25-.25H3.75a.25.25 0 0 0-.25.25V8.6c0 .22-.18.4-.4.4h-.7c-.22 0-.4-.18-.4-.4V6.75C2 5.782 2.783 5 3.75 5h16.5c.968 0 1.75.782 1.75 1.75zM4.767 15.738l.465.522a.4.4 0 0 0 .565.033L9.59 12.92l1.92 1.647a.75.75 0 0 0 .975 0l1.92-1.647 3.792 3.372a.4.4 0 0 0 .565-.032l.465-.523a.4.4 0 0 0-.032-.565l-3.64-3.235L19.18 8.83a.4.4 0 0 0 .043-.565l-.455-.533a.4.4 0 0 0-.565-.042l-5.965 5.112a.375.375 0 0 1-.488 0L5.785 7.69a.4.4 0 0 0-.565.042l-.455.533a.4.4 0 0 0 .043.565l3.625 3.107-3.64 3.235a.4.4 0 0 0-.033.565z" fill="currentColor" /></svg>
</div>
</k-input>
<k-input>
<label class="k-label" for="date">Delivery date</label>
<div class="k-field">
<input id="date" placeholder="DD.MM.YYYY" inputmode="numeric" />
<svg slot="end" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M22 4.75v14.5c0 .968-.782 1.75-1.75 1.75H3.75C2.782 21 2 20.218 2 19.25V10.4c0-.22.18-.4.4-.4h.7c.22 0 .4.18.4.4v8.85c0 .138.112.25.25.25h16.5a.25.25 0 0 0 .25-.25V4.75a.25.25 0 0 0-.25-.25H17v.6c0 .22-.18.4-.4.4h-.7c-.22 0-.4-.18-.4-.4v-.6h-7v.6c0 .22-.18.4-.4.4h-.7c-.22 0-.4-.18-.4-.4v-.6H3.75a.25.25 0 0 0-.25.25V7h15.35c.22 0 .4.18.4.4v.7c0 .22-.18.4-.4.4H2.75A.749.749 0 0 1 2 7.75v-3C2 3.782 2.782 3 3.75 3H7v-.6c0-.22.18-.4.4-.4h.7c.22 0 .4.18.4.4V3h7v-.6c0-.22.18-.4.4-.4h.7c.22 0 .4.18.4.4V3h3.25c.968 0 1.75.782 1.75 1.75zM11.4 11.5h1.2c.22 0 .4-.18.4-.4v-.7c0-.22-.18-.4-.4-.4h-1.2c-.22 0-.4.18-.4.4v.7c0 .22.18.4.4.4zm5 0h1.2c.22 0 .4-.18.4-.4v-.7c0-.22-.18-.4-.4-.4h-1.2c-.22 0-.4.18-.4.4v.7c0 .22.18.4.4.4zm-10 3h1.2c.22 0 .4-.18.4-.4v-.7c0-.22-.18-.4-.4-.4H6.4c-.22 0-.4.18-.4.4v.7c0 .22.18.4.4.4zm4.6-.4c0 .22.18.4.4.4h1.2c.22 0 .4-.18.4-.4v-.7c0-.22-.18-.4-.4-.4h-1.2c-.22 0-.4.18-.4.4zm5 0c0 .22.18.4.4.4h1.2c.22 0 .4-.18.4-.4v-.7c0-.22-.18-.4-.4-.4h-1.2c-.22 0-.4.18-.4.4zm-10 3c0 .22.18.4.4.4h1.2c.22 0 .4-.18.4-.4v-.7c0-.22-.18-.4-.4-.4H6.4c-.22 0-.4.18-.4.4zm5 0c0 .22.18.4.4.4h1.2c.22 0 .4-.18.4-.4v-.7c0-.22-.18-.4-.4-.4h-1.2c-.22 0-.4.18-.4.4z" fill="currentColor" /></svg>
</div>
</k-input>
</k-stack>import { useEffect, useRef } from "react";
import { Input } from "@kesko/components";
import { IconPaymentCreditCard } from "@kesko/iconography/react";
const cdn = "https://cdn.jsdelivr.net/npm";
const digit = /\d/;
const cardMask = [digit, digit, digit, digit, " ", digit, digit, digit, digit, " ", digit, digit, digit, digit, " ", digit, digit, digit, digit];
export default () => {
const input = useRef<HTMLInputElement>(null);
useEffect(() => {
let cancelled = false;
let mask: { destroy(): void } | undefined;
import(/* @vite-ignore */ `${cdn}/@maskito/core@5.5.0/+esm`)
.then(({ Maskito }) => {
if (!cancelled && input.current) {
mask = new Maskito(input.current, { mask: cardMask });
}
})
.catch(() => {});
return () => {
cancelled = true;
mask?.destroy();
};
}, []);
return (
<Input
ref={input}
label="K-Plussa card number"
name="plussa"
inputMode="numeric"
autoComplete="off"
placeholder="0000 0000 0000 0000"
description="The 16 digits printed on the front of the card."
>
<IconPaymentCreditCard slot="end" />
</Input>
);
};<k-input>
<label class="k-label" for="plussa">K-Plussa card number</label>
<div class="k-field">
<input id="plussa" name="plussa" inputmode="numeric" autocomplete="off" placeholder="0000 0000 0000 0000" aria-describedby="plussa-description" />
<svg slot="end" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M20.25 5H3.75C2.782 5 2 5.782 2 6.75v2.5c0 .415.335.75.75.75H20.5v7c0 .083-.013.5-.25.5H3.75a.25.25 0 0 1-.25-.25v-4.88c0-.22-.18-.4-.4-.4h-.7c-.22 0-.4.18-.4.4v4.88c0 .968.783 1.75 1.75 1.75h16.5c.87 0 1.75-.688 1.75-2V6.5c0-.77-.85-1.5-1.75-1.5zm.25 3.5h-17V6.75a.25.25 0 0 1 .25-.25h16.5c.107 0 .203.063.25.107zm-15.1 5c-.22 0-.4-.18-.4-.4v-.7c0-.22.18-.4.4-.4h1.2c.22 0 .4.18.4.4v.7c0 .22-.18.4-.4.4zm4 0c-.22 0-.4-.18-.4-.4v-.7c0-.22.18-.4.4-.4h1.2c.22 0 .4.18.4.4v.7c0 .22-.18.4-.4.4zm4 0c-.22 0-.4-.18-.4-.4v-.7c0-.22.18-.4.4-.4h1.2c.22 0 .4.18.4.4v.7c0 .22-.18.4-.4.4zm4 0c-.22 0-.4-.18-.4-.4v-.7c0-.22.18-.4.4-.4h1.2c.22 0 .4.18.4.4v.7c0 .22-.18.4-.4.4z" fill="currentColor" /></svg>
</div>
<p class="k-field-description" id="plussa-description">The 16 digits printed on the front of the card.</p>
</k-input>
<script type="module">
import { Maskito } from "https://cdn.jsdelivr.net/npm/@maskito/core@5.5.0/+esm";
const digit = /\d/;
const group = [digit, digit, digit, digit];
new Maskito(document.getElementById("plussa"), { mask: [...group, " ", ...group, " ", ...group, " ", ...group] });
</script>import { useState } from "react";
import { Button, Input, 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 (
<>
<Input
label="Password"
name="password"
type={shown ? "text" : "password"}
autoComplete="current-password"
defaultValue="password"
>
<Button
slot="end"
appearance="text"
square
size="sm"
aria-describedby="password-toggle"
onClick={() => setShown(!shown)}
>
{shown ? <IconHide /> : <IconShow />}
<VisuallyHidden>{toggleLabel}</VisuallyHidden>
</Button>
</Input>
<Tooltip id="password-toggle">{toggleLabel}</Tooltip>
</>
);
};<k-input>
<label class="k-label" for="password">Password</label>
<div class="k-field">
<input id="password" name="password" type="password" autocomplete="current-password" value="password" />
<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-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 { Input, Stack } from "@kesko/components";
import { IconSearch } from "@kesko/iconography/react";
export default () => (
<Stack>
<Input label="Search products" type="search" placeholder="Search">
<IconSearch slot="start" />
</Input>
<Input label="Weight (kg)" inputMode="decimal" placeholder="0">
<span slot="end">kg</span>
</Input>
<Input label="Price (€)" inputMode="decimal" placeholder="0,00">
<span slot="start">€</span>
</Input>
</Stack>
);<k-stack>
<k-input>
<label class="k-label" for="search">Search products</label>
<div class="k-field">
<svg slot="start" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M10 3c-3.86 0-7 3.14-7 7s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm0 12.5c-3.033 0-5.5-2.467-5.5-5.5S6.967 4.5 10 4.5s5.5 2.467 5.5 5.5-2.467 5.5-5.5 5.5zm10.248 4.253l-.495.495a.401.401 0 0 1-.565 0l-3.435-3.435a.401.401 0 0 1 0-.565l.494-.495a.401.401 0 0 1 .565 0l3.435 3.435a.401.401 0 0 1 0 .565z" fill="currentColor" /></svg>
<input id="search" type="search" placeholder="Search" />
</div>
</k-input>
<k-input>
<label class="k-label" for="weight">Weight (kg)</label>
<div class="k-field">
<input id="weight" inputmode="decimal" placeholder="0" />
<span slot="end">kg</span>
</div>
</k-input>
<k-input>
<label class="k-label" for="price">Price (€)</label>
<div class="k-field">
<span slot="start">€</span>
<input id="price" inputmode="decimal" placeholder="0,00" />
</div>
</k-input>
</k-stack>import { Input, Stack } from "@kesko/components";
export default () => (
<Stack>
<Input label="Customer number" name="customer" defaultValue="1234567" readOnly />
<Input label="Store" name="store" defaultValue="K-Citymarket Sello" readOnly />
</Stack>
);<k-stack>
<k-input>
<label class="k-label" for="customer">Customer number</label>
<div class="k-field">
<input id="customer" name="customer" value="1234567" readonly />
</div>
</k-input>
<k-input>
<label class="k-label" for="store">Store</label>
<div class="k-field">
<input id="store" name="store" value="K-Citymarket Sello" readonly />
</div>
</k-input>
</k-stack>import { Input, Stack } from "@kesko/components";
export default () => (
<Stack>
<Input label="First name" name="first-name" autoComplete="given-name" required />
<Input label="Last name" name="last-name" autoComplete="family-name" required hideRequired />
</Stack>
);<k-stack>
<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</label>
<div class="k-field">
<input id="last-name" name="last-name" autocomplete="family-name" required />
</div>
</k-input>
</k-stack>import { Input } from "@kesko/components";
import { IconSearch } from "@kesko/iconography/react";
export default () => (
<form role="search" onSubmit={event => event.preventDefault()}>
<Input label="Search products" name="q" type="search" placeholder="Search" enterKeyHint="search">
<IconSearch slot="start" />
</Input>
</form>
);<form role="search">
<k-input>
<label class="k-label" for="q">Search products</label>
<div class="k-field">
<svg slot="start" viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M10 3c-3.86 0-7 3.14-7 7s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm0 12.5c-3.033 0-5.5-2.467-5.5-5.5S6.967 4.5 10 4.5s5.5 2.467 5.5 5.5-2.467 5.5-5.5 5.5zm10.248 4.253l-.495.495a.401.401 0 0 1-.565 0l-3.435-3.435a.401.401 0 0 1 0-.565l.494-.495a.401.401 0 0 1 .565 0l3.435 3.435a.401.401 0 0 1 0 .565z" fill="currentColor" /></svg>
<input id="q" name="q" type="search" placeholder="Search" enterkeyhint="search" />
</div>
</k-input>
</form>import { Input, Stack } from "@kesko/components";
export default () => (
<Stack>
<Input label="Large" size="lg" placeholder="Placeholder" />
<Input label="Medium" placeholder="Placeholder" />
</Stack>
);<k-stack>
<k-input size="lg">
<label class="k-label" for="large">Large</label>
<div class="k-field">
<input id="large" placeholder="Placeholder" />
</div>
</k-input>
<k-input>
<label class="k-label" for="medium">Medium</label>
<div class="k-field">
<input id="medium" placeholder="Placeholder" />
</div>
</k-input>
</k-stack>import { useRef } from "react";
import { Button, Input, Stack } from "@kesko/components";
export default () => {
const input = useRef<HTMLInputElement>(null);
return (
<Stack>
<Input ref={input} label="Store" name="store" defaultValue="K-Citymarket Sello" />
<Button
size="sm"
appearance="outline"
onClick={() => {
input.current?.select();
input.current?.focus();
}}
>
Select all
</Button>
</Stack>
);
};<k-stack>
<k-input>
<label class="k-label" for="store">Store</label>
<div class="k-field">
<input id="store" name="store" value="K-Citymarket Sello" />
</div>
</k-input>
<button class="k-button k-button-sm" appearance="outline" type="button" id="select-all">Select all</button>
</k-stack>
<script>
const input = document.getElementById("store");
document.getElementById("select-all").addEventListener("click", () => {
input.select();
input.focus();
});
</script>import { Button, Input, Stack } from "@kesko/components";
export default () => (
<form onSubmit={event => event.preventDefault()}>
<Stack>
<Input label="Work email" name="email" type="email" required placeholder="name@kesko.fi" />
<Input label="Username" name="username" defaultValue="matti.meikalainen" error="That username is already taken." />
<Input label="Postal code" name="postal" defaultValue="00100" success="We deliver to this address." />
<Button type="submit">Submit</Button>
</Stack>
</form>
);<form>
<k-stack>
<k-input>
<label class="k-label" for="email">Work email<span class="k-label-required" aria-hidden="true">*</span></label>
<div class="k-field">
<input id="email" name="email" type="email" required placeholder="name@kesko.fi" />
</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>
<k-input success>
<label class="k-label" for="postal">Postal code</label>
<div class="k-field">
<input id="postal" name="postal" value="00100" aria-describedby="postal-message" />
</div>
<k-field-message variant="success" role="status"><svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M17.5 8.182a.4.4 0 0 1 .055.563l-5.728 6.98a.748.748 0 0 1-.554.275h-.025a.745.745 0 0 1-.545-.235l-3.725-3.958a.397.397 0 0 1 .017-.564l.51-.48a.397.397 0 0 1 .565.017l3.14 3.338 5.185-6.32a.4.4 0 0 1 .563-.055l.54.445zm2.525-2.14a.396.396 0 0 0-.603-.047l-.505.505a.399.399 0 0 0-.035.52 8.45 8.45 0 0 1 1.62 4.982c0 4.688-3.812 8.5-8.5 8.5S3.5 16.687 3.5 12 7.313 3.5 12 3.5c1.86 0 3.58.602 4.983 1.62.16.117.38.105.52-.035l.505-.505a.4.4 0 0 0-.048-.603A9.945 9.945 0 0 0 12 2.002c-5.515 0-10 4.485-10 10s4.485 10 10 10 10-4.485 10-10c0-2.23-.735-4.292-1.975-5.957z" fill="currentColor" /></svg><span id="postal-message">We deliver to this address.</span></k-field-message>
</k-input>
<button class="k-button" type="submit">Submit</button>
</k-stack>
</form>Properties #
| Name | Description | Type | Default |
|---|---|---|---|
label | Label for the input. Always provide one, even when it is hidden with | ReactNode | — |
hideLabel | Hides the label visually while keeping it available to assistive technology. | boolean | false |
description | Assistive text shown below the control, such as the expected format. | ReactNode | — |
error | Optional error message for the input, shown instead of the built-in validation message. Also marks the control invalid for assistive technology. | ReactNode | — |
success | Optional success message for the input. Shown only while there is no error. A plain string is also announced to screen readers when it appears. | ReactNode | — |
size | The size of the input. | "md" | "lg" | "md" |
type | The type of the input. | "text" | "email" | "password" | "tel" | "url" | "search" | "text" |
name | The name the value is submitted under. | string | — |
value | The value of the control. Pair with | string | — |
defaultValue | The starting value of an uncontrolled field. | string | — |
form | The | string | — |
placeholder | Short hint shown while the control is empty. Not a substitute for a label. | string | — |
inputMode | The on-screen keyboard to show on touch devices, such as | "none" | "text" | "decimal" | "numeric" | "tel" | "search" | "email" | "url" | — |
pattern | A regular expression the whole value must match before the form submits. | string | — |
minLength | The fewest characters the value may have before the form submits. | number | — |
maxLength | The most characters the control accepts. | number | — |
required | Requires a value before the form submits. Draws the marker on the label and is announced to assistive technology. | boolean | false |
hideRequired | Hides the required marker on the label while keeping | boolean | false |
readOnly | Stops the value being edited while keeping the control focusable and its value submitted. Reach for | boolean | — |
disabled | Disables the control. Blocks interaction and drops the value from the submitted data. | boolean | — |
autoComplete | Tells the browser what the value is for, so it can offer to fill it in. Worth setting on anything asking for personal or payment details. | string | — |
Events #
| Name | Description | Type |
|---|---|---|
onChange | Handler called as the value changes. Fires on every keystroke. | (event: ChangeEvent<HTMLInputElement>) => void |
onInput | Handler called on the native | (event: SyntheticEvent<HTMLInputElement>) => void |
onSelect | Handler called when the selected text changes. | (event: SyntheticEvent<HTMLInputElement>) => void |
onFocus | Handler called when the control receives focus. | (event: FocusEvent<HTMLInputElement>) => void |
onBlur | Handler called when the control loses focus. | (event: FocusEvent<HTMLInputElement>) => 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-input-bg | Overrides the background color. | var(--k-color-bg-base) |
--k-input-text | Overrides the text color. | var(--k-color-text-base) |
--k-input-border | Overrides the border color in every state. | var(--k-color-border-control) |
--k-input-radius | Overrides the border radius. | var(--k-radius-md) |
--k-input-inline-size | Overrides the width of the field. | 100% |
Accessibility #
Input is built on a native <input> and <label>, so it behaves as expected with assistive technologies.
- Always pass a
label. A screen reader reads it as the name, and clicking it focuses the control. If there is no room for it, passhideLabelrather than leaving it out. placeholderis a hint, not a description. Don’t put anything people need in order to fill in the field in the placeholder. It disappears as soon as they type. Usedescriptionfor that instead.- Say what the input accepts. Use
descriptionfor format hints such as the number of digits, andautoCompletefor anything the browser can fill in: names, addresses, emails, card numbers. Turn spelling suggestions off withspellCheck={false}only where they make no sense. startandendslots are decorative. A unit or icon in aslot="start"orslot="end"is not read as part of the control’s name, and an icon should carryaria-hidden. Put units in the label, for example “Weight (kg)”, or reference them witharia-describedby.- Interactive content needs a name and a target. A Button in a start or end slot, such as a password toggle, needs an accessible name and a target of at least 24×24 pixels. The Button sizes already meet that.
- Validation is built in. Set
required,type,patternorminLengthand the field checks itself on submit, with a message in the page’s language. No form library is needed, see Forms. - Avoid
disabledfor validation. A disabled control leaves the tab order and cannot explain itself. Keep it enabled and let the message say what is wrong. UsereadOnlyfor a value people need to see and copy but not edit. - Check contrast if you override colors. Text needs 4.5:1 against
--k-input-bg, and--k-input-borderneeds 3:1 against the surface the field 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 Input 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 Input:
import { Input } 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.