Select component allows users to choose one option from a list of options. Consider using the Select component when you have 6 or more options.

Open in new tab
import { Select } from "@kesko/components";

export default () => (
  <Select label="Store" name="store" placeholder="Choose a store">
    <option value="sello">K-Citymarket Sello</option>
    <option value="kamppi">K-Supermarket Kamppi</option>
    <option value="toolo">K-Market Töölö</option>
  </Select>
);
import { Select } from "@kesko/components";

export default () => (
  <Select
    label="Receipt"
    name="receipt"
    defaultValue="email"
    description="Where we send the receipt after each purchase."
  >
    <option value="email">By email</option>
    <option value="app">In the K-Ruoka app</option>
    <option value="paper">Printed at the checkout</option>
  </Select>
);
import { Select } 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 () => (
  <Select label="Custom label" name="custom" placeholder="Choose an option" required style={subtle}>
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
  </Select>
);
import { Select, Stack } from "@kesko/components";

export default () => (
  <Stack direction="row">
    <Select label="Quantity" name="quantity" defaultValue="1" style={{ "--k-select-inline-size": "6rem" }}>
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </Select>
    <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>
    <Select label="Store" name="store" placeholder="Choose a store" style={{ "--k-select-inline-size": "16rem" }}>
      <option value="sello">K-Citymarket Sello</option>
      <option value="kamppi">K-Supermarket Kamppi</option>
    </Select>
  </Stack>
);
import { Select } from "@kesko/components";

export default () => (
  <Select label="Delivery method" name="delivery" defaultValue="pickup">
    <option value="home">Home delivery</option>
    <option value="pickup">Pickup from store</option>
    <option value="locker">Parcel locker</option>
  </Select>
);
import { Select, Stack } from "@kesko/components";

export default () => (
  <Stack>
    <Select label="Store" name="store" defaultValue="sello" disabled>
      <option value="sello">K-Citymarket Sello</option>
      <option value="kamppi">K-Supermarket Kamppi</option>
    </Select>
    <Select label="Delivery slot" name="slot" placeholder="Choose a time">
      <option value="morning">8–12</option>
      <option value="afternoon" disabled>
        12–16 (full)
      </option>
      <option value="evening">16–20</option>
    </Select>
  </Stack>
);
import { Select } from "@kesko/components";

export default () => (
  <Select label="Product" name="product" placeholder="Choose a product">
    <optgroup label="Fruit">
      <option value="apple">Apple</option>
      <option value="banana">Banana</option>
    </optgroup>
    <optgroup label="Vegetables">
      <option value="carrot">Carrot</option>
      <option value="cucumber">Cucumber</option>
    </optgroup>
  </Select>
);
import { Select } from "@kesko/components";

export default () => (
  <Select label="Sort by" hideLabel name="sort" defaultValue="relevance">
    <option value="relevance">Sort by relevance</option>
    <option value="price-asc">Sort by lowest price</option>
    <option value="price-desc">Sort by highest price</option>
  </Select>
);
import { Select, Stack } from "@kesko/components";
import { IconCalendar, IconLocation } from "@kesko/iconography/react";

export default () => (
  <Stack>
    <Select label="Pickup store" name="store" placeholder="Choose a store">
      <IconLocation slot="start" />
      <option value="sello">K-Citymarket Sello</option>
      <option value="kamppi">K-Supermarket Kamppi</option>
      <option value="toolo">K-Market Töölö</option>
    </Select>
    <Select label="Delivery day" name="day" defaultValue="tue">
      <IconCalendar slot="start" />
      <option value="mon">Monday</option>
      <option value="tue">Tuesday</option>
      <option value="wed">Wednesday</option>
    </Select>
  </Stack>
);
import { Select, Stack } from "@kesko/components";

export default () => (
  <Stack>
    <Select label="Country" name="country" autoComplete="country" placeholder="Choose a country" required>
      <option value="FI">Finland</option>
      <option value="SE">Sweden</option>
      <option value="NO">Norway</option>
    </Select>
    <Select label="Language" name="language" placeholder="Choose a language" required hideRequired>
      <option value="fi">Suomi</option>
      <option value="sv">Svenska</option>
      <option value="en">English</option>
    </Select>
  </Stack>
);
import { Select, Stack } from "@kesko/components";

export default () => (
  <Stack>
    <Select label="Large" size="lg" placeholder="Placeholder">
      <option value="1">Option 1</option>
      <option value="2">Option 2</option>
    </Select>
    <Select label="Medium" placeholder="Placeholder">
      <option value="1">Option 1</option>
      <option value="2">Option 2</option>
    </Select>
  </Stack>
);
import { Button, Select, Stack } from "@kesko/components";

export default () => (
  <form onSubmit={event => event.preventDefault()}>
    <Stack>
      <Select label="Country" name="country" placeholder="Choose a country" required>
        <option value="FI">Finland</option>
        <option value="SE">Sweden</option>
      </Select>
      <Select label="Delivery slot" name="slot" defaultValue="afternoon" error="That slot is no longer available.">
        <option value="morning">8–12</option>
        <option value="afternoon">12–16</option>
        <option value="evening">16–20</option>
      </Select>
      <Select label="Store" name="store" defaultValue="sello" success="This store has every item in stock.">
        <option value="sello">K-Citymarket Sello</option>
        <option value="kamppi">K-Supermarket Kamppi</option>
      </Select>
      <Button type="submit">Submit</Button>
    </Stack>
  </form>
);

Properties #

NameDescriptionTypeDefault
label

Label for the select. Always provide one, even when it is hidden with hideLabel.

ReactNode—
hideLabel

Hides the label visually while keeping it available to assistive technology.

booleanfalse
description

Assistive text shown below the control, such as what the choice affects.

ReactNode—
error

Optional error message for the select, shown instead of the built-in validation message. Also marks the control invalid for assistive technology.

ReactNode—
success

Optional success message for the select. 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 select.

"md" | "lg""md"
name

The name the value is submitted under.

string—
value

The value of the selected option. Pair with onChange to control the field.

string—
defaultValue

The value of the option selected at first in an uncontrolled field.

string—
form

The id of the form the control submits with. Only needed when the control sits outside that form.

string—
placeholder

Text shown while nothing is chosen. Renders an option with an empty value first, so a required select stays invalid until a real option is picked. Not a substitute for a label.

string—
required

Requires a choice before the form submits. Draws the marker on the label and is announced to assistive technology.

booleanfalse
hideRequired

Hides the required marker on the label while keeping required on the control. Use it when the form says once that every field is required.

booleanfalse
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, such as country or bday-month.

string—

Events #

NameDescriptionType
onChange

Handler called when a different option is chosen.

(event: ChangeEvent<HTMLSelectElement>) => void
onFocus

Handler called when the control receives focus.

(event: FocusEvent<HTMLSelectElement>) => void
onBlur

Handler called when the control loses focus.

(event: FocusEvent<HTMLSelectElement>) => 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.

NameDescriptionDefault
--k-select-bg

Overrides the background color.

var(--k-color-bg-base)
--k-select-text

Overrides the text color.

var(--k-color-text-base)
--k-select-border

Overrides the border color in every state.

var(--k-color-border-control)
--k-select-radius

Overrides the border radius.

var(--k-radius-md)
--k-select-inline-size

Overrides the width of the field.

100%

Accessibility #

Select is built on a native <select> and <label>, so it opens the browser’s own picker on every device and 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, pass hideLabel rather than leaving it out.
  • Start from a real choice or a placeholder. Without either, the first option is selected and submitted silently. placeholder adds an empty option, so a required select stays invalid until a real option is picked. Don’t hide instructions in a preselected option.
  • Keep option text short and self-contained. The picker shows the text alone, without the label. Use optgroup to group a long list rather than repeating a prefix on every option.
  • The start slot is decorative. An icon in slot="start" is not read as part of the control’s name and should carry aria-hidden.
  • Avoid disabled for validation. A disabled control leaves the tab order and cannot explain itself. Keep it enabled and let the message say what is wrong. Disable single options that cannot be chosen right now, and say why in the option text.
  • Check contrast if you override colors. Text needs 4.5:1 against --k-select-bg, and --k-select-border needs 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 Select component. The @kesko/components package and the CSS Framework are required. Everything else is optional:

npm install @kesko/components @kesko/css

Once installed, load the CSS Framework in your app’s entry point or root layout:

import "@kesko/css";

Then, you can import the Select:

import { Select } 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 #