Synertech Web/ui v0.57.5 Site Storybook

Documentation / Forms

Select

Client@synertech/uiOpen in Storybook

The standalone select: a trigger button and a list of options rendered in a portal, placed above or below depending on the space available in the window. With searchable, it becomes a combobox filtered on each option’s label, value and keywords.

It works uncontrolled (defaultValue) or controlled (value + onValueChange); the value is a string, "" when nothing is selected. With multiple, it is an array: the list stays open while options are checked, the values are written as tags in the field and Backspace removes the last one; creatable adds what is typed as a value. With name, hidden fields carry the value in a native form, one entry per value like a <select multiple>. Full keyboard support (arrows, Home / End, Enter, Escape) and ARIA combobox / listbox roles.

A client component ("use client"). Its texts are select… labels: English by default, French under <UILabelsProvider labels={frenchUILabels}>. For one instance, placeholder, noOptionsText, clearLabel, searchLabel and searchPlaceholder win over the provider.

Examples

Basic usage

Uncontrolled: defaultValue sets the initial value, the component handles the rest.

Open in a tab
import { Select, type SelectOption } from "@synertech/ui";

const countries: SelectOption[] = [
  { value: "fr", label: "France" },
  { value: "be", label: "Belgique" },
  { value: "ch", label: "Suisse" },
  { value: "ca", label: "Canada", keywords: ["québec"] },
  { value: "lu", label: "Luxembourg" },
];

export function Basic() {
  return (
    <Select label="Pays" placeholder="Choisir un pays…" options={countries} defaultValue="fr" />
  );
}

Search and clearing

searchable adds a filter field in the list; clearable a cross to clear the value.

Open in a tab
import { useState } from "react";
import { Select, type SelectOption } from "@synertech/ui";

const countries: SelectOption[] = [
  { value: "fr", label: "France" },
  { value: "be", label: "Belgique" },
  { value: "ch", label: "Suisse" },
  { value: "ca", label: "Canada", keywords: ["québec"] },
  { value: "lu", label: "Luxembourg" },
];

export function Searchable() {
  const [country, setCountry] = useState("");

  return (
    <Select
      label="Pays de livraison"
      placeholder="Rechercher un pays…"
      noOptionsText="Aucun pays ne correspond"
      options={countries}
      value={country}
      onValueChange={setCountry}
      searchable
      clearable
      helperText={
        country
          ? `Code pays : ${country.toUpperCase()}`
          : "Tapez « québec » pour trouver le Canada."
      }
    />
  );
}

Rich options

Each option can carry a description, an icon or be disabled.

Open in a tab
import { Select, type SelectOption } from "@synertech/ui";

export function RichOptions() {
  const plans: SelectOption[] = [
    { value: "starter", label: "Starter", description: "1 utilisateur, 5 projets" },
    { value: "team", label: "Équipe", description: "10 utilisateurs, projets illimités" },
    {
      value: "enterprise",
      label: "Entreprise",
      description: "Sur devis — contactez-nous",
      disabled: true,
    },
  ];

  return (
    <Select
      label="Formule"
      placeholder="Choisir une formule…"
      options={plans}
      defaultValue="team"
    />
  );
}

Several values

multiple: the value is an array, each choice a tag that a cross removes. maxTagCount limits the tags written, the others are counted.

Open in a tab
import { useState } from "react";
import { Select, type SelectOption } from "@synertech/ui";

export function Multiple() {
  const skills: SelectOption[] = [
    { value: "design", label: "Design" },
    { value: "front", label: "Front-end" },
    { value: "back", label: "Back-end" },
    { value: "a11y", label: "Accessibilité" },
    { value: "devops", label: "DevOps" },
    { value: "data", label: "Données" },
  ];
  const [value, setValue] = useState(["design", "front", "a11y", "data"]);

  return (
    <Select
      multiple
      searchable
      clearable
      label="Compétences"
      placeholder="Choisir des compétences…"
      options={skills}
      value={value}
      onValueChange={setValue}
      maxTagCount={3}
      helperText={`${value.length} sélectionnée${value.length > 1 ? "s" : ""}`}
    />
  );
}

Tags typed freely

creatable: what is typed becomes a value with Enter, when no option bears that label. An existing option is chosen rather than created again.

Open in a tab
import { useState } from "react";
import { Select } from "@synertech/ui";

export function Creatable() {
  const [tags, setTags] = useState(["urgent"]);

  return (
    <Select
      multiple
      creatable
      label="Étiquettes"
      placeholder="Ajouter des étiquettes…"
      options={[
        { value: "urgent", label: "urgent" },
        { value: "client", label: "client" },
        { value: "interne", label: "interne" },
      ]}
      value={tags}
      onValueChange={setTags}
      helperText="Tapez une étiquette puis Entrée ; Retour arrière retire la dernière."
    />
  );
}

Sizes and variants

size sets the height, variant the trigger style: bordered, thick outline or filled.

Open in a tab
import { Select, type SelectOption } from "@synertech/ui";

const countries: SelectOption[] = [
  { value: "fr", label: "France" },
  { value: "be", label: "Belgique" },
  { value: "ch", label: "Suisse" },
  { value: "ca", label: "Canada", keywords: ["québec"] },
  { value: "lu", label: "Luxembourg" },
];

export function SizesAndVariants() {
  return (
    <div className="flex flex-col gap-4">
      <Select size="sm" variant="default" label="Petit" options={countries} defaultValue="fr" />
      <Select
        size="md"
        variant="outlined"
        label="Moyen, contour"
        options={countries}
        defaultValue="be"
      />
      <Select
        size="lg"
        variant="filled"
        label="Grand, rempli"
        options={countries}
        defaultValue="ch"
      />
    </div>
  );
}

Validation and states

required marks the label, error replaces the help text with a message read with the field; loading shows a spinner, disabled freezes the choice.

Open in a tab
import { useState } from "react";
import { Select, type SelectOption } from "@synertech/ui";

const countries: SelectOption[] = [
  { value: "fr", label: "France" },
  { value: "be", label: "Belgique" },
  { value: "ch", label: "Suisse" },
  { value: "ca", label: "Canada", keywords: ["québec"] },
  { value: "lu", label: "Luxembourg" },
];

export function States() {
  const [value, setValue] = useState("");

  return (
    <div className="flex flex-col gap-4">
      <Select
        label="Service"
        required
        placeholder="Choisir un service…"
        options={[
          { value: "rh", label: "Ressources humaines" },
          { value: "compta", label: "Comptabilité" },
        ]}
        value={value}
        onValueChange={setValue}
        error={value ? undefined : "Le service est obligatoire."}
      />
      <Select label="Agences" placeholder="Chargement…" options={[]} loading />
      <Select label="Pays" options={countries} defaultValue="fr" disabled />
    </div>
  );
}

In a form

name adds hidden fields: the value is submitted with the form like a native <select>'s, one entry per value with multiple.

Open in a tab
import { Button, Select, type SelectOption } from "@synertech/ui";

const countries: SelectOption[] = [
  { value: "fr", label: "France" },
  { value: "be", label: "Belgique" },
  { value: "ch", label: "Suisse" },
  { value: "ca", label: "Canada", keywords: ["québec"] },
  { value: "lu", label: "Luxembourg" },
];

export function InForm() {
  return (
    <form
      className="flex flex-col gap-4"
      onSubmit={(event) => {
        event.preventDefault();
        const data = new FormData(event.currentTarget);
        console.log({ country: data.get("country"), visited: data.getAll("visited") });
      }}
    >
      <Select name="country" label="Pays" placeholder="Choisir un pays…" options={countries} />
      <Select
        multiple
        name="visited"
        label="Pays visités"
        placeholder="Choisir des pays…"
        options={countries}
      />
      <Button type="submit" className="self-start">
        Valider
      </Button>
    </form>
  );
}

API reference

Components

Select

ComponentClient

A field whose value is chosen in a list: one value, or several with multiple, written as tags in the field. The list is searchable, keeps to the viewport, and stays live in a dialog.

import { Select } from "@synertech/ui";

Props — SelectProps

PropTypeDefaultDescription
options• SelectOption[] []
className string —
clearable boolean false

A button that empties the field once it holds a value. From the keyboard, Delete or Backspace on the field does the same.

clearLabel string —

Accessible name of the button clearing the value. Defaults to the selectClear label.

contentClassName string —
creatable boolean false

What is typed in the search field can be added as a value of its own, when no option bears that label — tags typed freely. Turns the search field on. The value is the text typed, written under its own text, and listed with the options while it is chosen.

defaultValue string | string[] —

One value: the one the field starts with, when it holds its value itself.

With multiple: the values the field starts with, when it holds them itself.

description string —

Written under the label, above the field.

disabled boolean false
error boolean | string —

true marks the field invalid; a message also does, and is written under the field in place of helperText. The field is then aria-invalid and described by the message. false and "" are no error.

helperText string —

Written under the field; a message passed as error takes its place.

label string —
labels UILabelsOf<"select"> —

The labels of this instance, under the keys of UILabelsProvider. The props that name one label (placeholder, noOptionsText, clearLabel, searchLabel, searchPlaceholder) win over it.

loading boolean false
maxHeight number 256
maxTagCount number —

The most tags written in the field; the others are counted in one more, "+2". Every value has its tag by default.

multiple boolean false

Several values, written as tags in the field, instead of one.

name string —

Submitted with a form: the value, or one entry per value with multiple — what a native <select multiple> sends.

noOptionsText string —
onSearchChange (query: string) => void —
onValueChange ((value: string) => void) | ((value: string[]) => void) —

One value: called with the value chosen, or "" when it is cleared.

With multiple: called with every value chosen, in the order they were, each time one is added or removed. The list stays open meanwhile.

placeholder string —
readOnly boolean false
required boolean false
searchable boolean false
searchLabel string —

Accessible name of the search field. Defaults to the selectSearch label.

searchPlaceholder string —

Placeholder of the search field. Defaults to the selectSearchPlaceholder label.

size "sm" | "md" | "lg" "md"
triggerClassName string —

Classes of the field: the button, or the frame holding the tags with multiple.

value string | string[] —

One value: the one chosen, when the application holds it; "" is none.

With multiple: the values chosen, in the order they were, when the application holds them.

variant "default" | "outlined" | "filled" "default"

Types

The props a Select has in both modes.

interface SelectBaseProps
FieldTypeDefaultDescription
options• SelectOption[] —
className string —
clearable boolean —

A button that empties the field once it holds a value. From the keyboard, Delete or Backspace on the field does the same.

clearLabel string —

Accessible name of the button clearing the value. Defaults to the selectClear label.

contentClassName string —
description string —

Written under the label, above the field.

disabled boolean —
error boolean | string —

true marks the field invalid; a message also does, and is written under the field in place of helperText. The field is then aria-invalid and described by the message. false and "" are no error.

helperText string —

Written under the field; a message passed as error takes its place.

label string —
labels UILabelsOf<"select"> —

The labels of this instance, under the keys of UILabelsProvider. The props that name one label (placeholder, noOptionsText, clearLabel, searchLabel, searchPlaceholder) win over it.

loading boolean —
maxHeight number —
name string —

Submitted with a form: the value, or one entry per value with multiple — what a native <select multiple> sends.

noOptionsText string —
onSearchChange (query: string) => void —
placeholder string —
readOnly boolean —
required boolean —
searchable boolean —
searchLabel string —

Accessible name of the search field. Defaults to the selectSearch label.

searchPlaceholder string —

Placeholder of the search field. Defaults to the selectSearchPlaceholder label.

size "sm" | "md" | "lg" —
triggerClassName string —

Classes of the field: the button, or the frame holding the tags with multiple.

variant "default" | "outlined" | "filled" —

The props of a Select that holds several values (multiple), written as tags in the field.

FieldTypeDefaultDescription
multiple• true —

Several values, written as tags in the field, instead of one.

options• SelectOption[] —
className string —
clearable boolean —

A button that empties the field once it holds a value. From the keyboard, Delete or Backspace on the field does the same.

clearLabel string —

Accessible name of the button clearing the value. Defaults to the selectClear label.

contentClassName string —
creatable boolean —

What is typed in the search field can be added as a value of its own, when no option bears that label — tags typed freely. Turns the search field on. The value is the text typed, written under its own text, and listed with the options while it is chosen.

defaultValue string[] —

With multiple: the values the field starts with, when it holds them itself.

description string —

Written under the label, above the field.

disabled boolean —
error boolean | string —

true marks the field invalid; a message also does, and is written under the field in place of helperText. The field is then aria-invalid and described by the message. false and "" are no error.

helperText string —

Written under the field; a message passed as error takes its place.

label string —
labels UILabelsOf<"select"> —

The labels of this instance, under the keys of UILabelsProvider. The props that name one label (placeholder, noOptionsText, clearLabel, searchLabel, searchPlaceholder) win over it.

loading boolean —
maxHeight number —
maxTagCount number —

The most tags written in the field; the others are counted in one more, "+2". Every value has its tag by default.

name string —

Submitted with a form: the value, or one entry per value with multiple — what a native <select multiple> sends.

noOptionsText string —
onSearchChange (query: string) => void —
onValueChange (value: string[]) => void —

With multiple: called with every value chosen, in the order they were, each time one is added or removed. The list stays open meanwhile.

placeholder string —
readOnly boolean —
required boolean —
searchable boolean —
searchLabel string —

Accessible name of the search field. Defaults to the selectSearch label.

searchPlaceholder string —

Placeholder of the search field. Defaults to the selectSearchPlaceholder label.

size "sm" | "md" | "lg" —
triggerClassName string —

Classes of the field: the button, or the frame holding the tags with multiple.

value string[] —

With multiple: the values chosen, in the order they were, when the application holds them.

variant "default" | "outlined" | "filled" —

SelectOption

Interface
interface SelectOption
FieldTypeDefaultDescription
label• string —
value• string —
description string —
disabled boolean —
icon ReactNode —
keywords string[] —

The props of a Select that holds one value.

FieldTypeDefaultDescription
options• SelectOption[] —
className string —
clearable boolean —

A button that empties the field once it holds a value. From the keyboard, Delete or Backspace on the field does the same.

clearLabel string —

Accessible name of the button clearing the value. Defaults to the selectClear label.

contentClassName string —
defaultValue string —

One value: the one the field starts with, when it holds its value itself.

description string —

Written under the label, above the field.

disabled boolean —
error boolean | string —

true marks the field invalid; a message also does, and is written under the field in place of helperText. The field is then aria-invalid and described by the message. false and "" are no error.

helperText string —

Written under the field; a message passed as error takes its place.

label string —
labels UILabelsOf<"select"> —

The labels of this instance, under the keys of UILabelsProvider. The props that name one label (placeholder, noOptionsText, clearLabel, searchLabel, searchPlaceholder) win over it.

loading boolean —
maxHeight number —
multiple false —

Several values, written as tags in the field, instead of one.

name string —

Submitted with a form: the value, or one entry per value with multiple — what a native <select multiple> sends.

noOptionsText string —
onSearchChange (query: string) => void —
onValueChange (value: string) => void —

One value: called with the value chosen, or "" when it is cleared.

placeholder string —
readOnly boolean —
required boolean —
searchable boolean —
searchLabel string —

Accessible name of the search field. Defaults to the selectSearch label.

searchPlaceholder string —

Placeholder of the search field. Defaults to the selectSearchPlaceholder label.

size "sm" | "md" | "lg" —
triggerClassName string —

Classes of the field: the button, or the frame holding the tags with multiple.

value string —

One value: the one chosen, when the application holds it; "" is none.

variant "default" | "outlined" | "filled" —