# Select

> A real select, dressed up: the list unrolls from the field, a highlight slides between options and the value rolls to your choice. A pill for toolbars too.

Forms · select, listbox, form, keyboard · HTML, CSS, vanilla JS · no dependencies · updated 2026-10-21
Demo: https://kodza.dev/components/custom-select/

## Files

The code below, served as files: byte for byte what the Kodza site copies (the CSS includes its theme guard).

- [`kodza-custom-select.css`](https://kodza.dev/registry/custom-select/kodza-custom-select.css) · 20.2 KB
- [`kodza-custom-select.js`](https://kodza.dev/registry/custom-select/kodza-custom-select.js) · 14.2 KB
- [`kodza-custom-select.html`](https://kodza.dev/registry/custom-select/kodza-custom-select.html) · 1.6 KB · the markup, to adapt and paste into your page

**Can you run shell commands? Download the CSS and the JS, don't retype them.** Retyping costs thousands of tokens and can drop or change lines of the CSS. Put the files where your stack expects them (Use it says where: change the `-o` paths):

```bash
curl -fsSL --create-dirs -o kodza/kodza-custom-select.css https://kodza.dev/registry/custom-select/kodza-custom-select.css
curl -fsSL --create-dirs -o kodza/kodza-custom-select.js https://kodza.dev/registry/custom-select/kodza-custom-select.js
```

Then load the files from your page as Use it shows, instead of pasting the content. The HTML is the part you adapt (text, links, modifiers): paste it from the Code section. Copy the CSS and the JS from the Code section only if you can't run commands, exactly as they are. (Windows PowerShell: `curl.exe`.)

## API

- Root: `.kodza-select`
- Variables (set them on the root element itself: it declares its own defaults):
  - `--kz-select-bg: #ffffff`
  - `--kz-select-fg: #0a0a0a`
  - `--kz-select-muted: rgba(10, 10, 10, 0.6)`
  - `--kz-select-line: rgba(10, 10, 10, 0.14)`
  - `--kz-select-line-hover: rgba(10, 10, 10, 0.3)`
  - `--kz-select-soft: rgba(10, 10, 10, 0.06)`
  - `--kz-select-shadow: 0 18px 40px -16px rgba(10, 10, 10, 0.3)`
  - `--kz-select-height: 56px`
  - `--kz-select-radius: 12px`
  - `--kz-select-pad: 16px`
  - `--kz-select-duration: 0.35s`
  - `--kz-select-ease: cubic-bezier(0.22, 1, 0.36, 1)`
- Modifiers: `.kodza-select--inline`
- Lifecycle: `kodza:init` / `kodza:destroy` on `document`, with `{ detail: { root } }` to target a container.

## Keyboard

What each key does, by where the focus is. Keep it working when you adapt the HTML: same elements, same classes.

- On the field, while it's open (focus in `.kodza-select__trigger`, while `.kodza-select.is-open` is on the page):
  - `ArrowDown` / `ArrowUp`: Next or previous option, no looping
  - `Home` / `End`: First or last option
  - `PageDown` / `PageUp`: Five options down or up
  - a letter: Jumps to the option starting with that letter
  - `Enter` / `Space`: Picks the highlighted option and closes
  - `Tab`: Picks the highlighted option and moves on
- On the field (focus in `.kodza-select__trigger`):
  - `Enter` / `Space` / `ArrowDown` / `ArrowUp`: Opens it on the current choice
  - a letter: Picks the option starting with that letter, no opening
- Anywhere, while it's open (while `.kodza-select.is-open` is on the page):
  - `Escape`: Closes it, focus back on the field

## Dark mode

The values Kodza uses on a dark background (`#0a0a0a`). For a page that follows the system theme, add them after the component's CSS:

```css
@media (prefers-color-scheme: dark) {
  .kodza-select {
    --kz-select-bg: #161616;
    --kz-select-fg: #f2f2f0;
    --kz-select-muted: rgba(242, 242, 240, 0.62);
    --kz-select-line: rgba(255, 255, 255, 0.14);
    --kz-select-line-hover: rgba(255, 255, 255, 0.3);
    --kz-select-soft: rgba(255, 255, 255, 0.08);
    --kz-select-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.8);
  }
}
```

A site with its own theme switch puts the same rules under its dark selector instead (`[data-theme="dark"] .kodza-select { … }`); a single dark section, under that section's class.

## Use it

### Plain HTML page

- CSS: `kodza/kodza-custom-select.css` next to the page (the Files commands as they are), linked in `<head>`: `<link rel="stylesheet" href="kodza/kodza-custom-select.css">`. Without a shell, paste it in a `<style>` in `<head>` instead. It only touches `kodza-` classes.
- HTML: where the component goes. Paste it as many times as you need: instances never interfere.
- JS: `kodza/kodza-custom-select.js`, loaded with `<script src="kodza/kodza-custom-select.js" defer></script>` in `<head>`. Without a shell, paste it in a `<script>` before `</body>` (or in `<head>`: it waits for the page). One copy per page, whatever the number of instances.
- Restyle with the `--kz-…` variables, set on the component's root element itself (the root declares its own defaults, so a value on an ancestor is ignored), and with the modifiers / attributes listed under API.
- Font: it takes the page's own. The Kodza look is Geist: `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap">`.
- Content added later (AJAX navigation, a SPA route, a builder preview): start it with `document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: container } }))`; before removing it, the same call with `'kodza:destroy'` stops it and puts the original markup back.

### Claude artifact (claude.ai)

- Paste the CSS in a `<style>` and the JS in a `<script>` at the end, in the artifact itself: it loads stylesheets only from Google Fonts and scripts only from a few CDNs, so no `<link>` or `<script src>` to Kodza.
- Writing the artifact file with a shell? Insert the downloaded files (Files) with a command instead of retyping them: a line `KODZA-CSS` alone inside the `<style>`, `KODZA-JS` inside the `<script>`, then `sed -e '/^KODZA-CSS$/{r kodza/kodza-custom-select.css' -e 'd' -e '}' -e '/^KODZA-JS$/{r kodza/kodza-custom-select.js' -e 'd' -e '}' page.html > artifact.html`.
- Font: load Geist from Google Fonts (allowed): `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap">`.
- Dark mode: the viewer sets `data-theme="dark"` or `"light"` on `<html>`, or nothing when it follows the system. Write the Dark mode rules twice: inside `@media (prefers-color-scheme: dark)` with `:root:not([data-theme="light"])` in front of each selector, and with `:root[data-theme="dark"]` in front of each selector.
- Forms: there is nowhere to send them. Handle `submit` in your script with `event.preventDefault()` and show the result in the page.

### WordPress

- HTML: a **Custom HTML** block (or a pattern / template part). WordPress keeps this markup as it is only for users allowed to post unfiltered HTML (Administrators; Super Admins on multisite): for anyone else it strips tags such as `<svg>`, `<input>` or `<dialog>`, so add it from the theme (a pattern or template part) instead.
- This one is inline (it flows like a word): pasted alone, many themes leave it at the edge of the page (block themes, and classic ones like Twenty Twenty-One or Blocksy), so put the Custom HTML block inside a **Group** block to line it up with the text.
- CSS and JS: the downloaded files go in the theme, under `wp-content/themes/<your-theme>/kodza/` (the child theme if there is one), enqueued from its functions.php (or a code-snippets plugin):
  ```php
  add_action('wp_enqueue_scripts', function () {
    $dir = get_stylesheet_directory() . '/kodza/';
    $uri = get_stylesheet_directory_uri() . '/kodza/';
    wp_enqueue_style('kodza-custom-select', $uri . 'kodza-custom-select.css', [], filemtime($dir . 'kodza-custom-select.css'));
    wp_enqueue_script('kodza-custom-select', $uri . 'kodza-custom-select.js', [], filemtime($dir . 'kodza-custom-select.js'), true);
  });
  ```
  Scoped to `kodza-` classes, the CSS never touches the theme. One copy of the JS, whatever the number of blocks.
- No access to the theme files? The CSS can also go, as it is, in **Appearance → Customize → Additional CSS** (classic theme) or **Styles → Additional CSS** in the Site Editor (block theme).
- Theme with AJAX page transitions: fire `kodza:init` on the new content after each swap (and `kodza:destroy` on the old one).
- Performance plugin (WP Rocket, LiteSpeed Cache, Perfmatters…) with **Delay JavaScript execution** turned on: add `kodza` to the scripts it must not delay. Otherwise the component waits for the visitor's first scroll, tap or mouse move, and that first click can be lost.
- Colours: by default, match the theme's palette. After the component's CSS, point these variables at the theme's colours, on the component root, Kodza's value as the fallback:
  `.kodza-select { --kz-select-fg: var(TEXT, #0a0a0a); --kz-select-bg: var(BACKGROUND, #ffffff); }`
  TEXT, BACKGROUND and ACCENT (the colour the theme fills its own buttons with) are the theme's own colour variables — block themes (theme.json, like Twenty Twenty-Five): `--wp--preset--color--contrast`, `--wp--preset--color--base`, `--wp--preset--color--contrast` (they fill their buttons with it; their accent-1… colours are decorative); Astra: `--ast-global-color-2`, `--ast-global-color-4`, `--ast-global-color-0`; Kadence: `--global-palette3`, `--global-palette9`, `--global-palette1`; GeneratePress: `--contrast`, `--base-3`, `--accent`; Blocksy: `--theme-palette-color-4`, `--theme-palette-color-8`, `--theme-palette-color-1`. Use only these names, and only if the site really has them (the theme's CSS, or Styles → Colors): the `--wp--preset--color--black`, `--white`, `--vivid-…` that WordPress adds everywhere are not the theme's palette. Another theme, or one without these variables (Hello Elementor, OceanWP): leave the variables alone, it keeps Kodza's monochrome; same when the developer asks for monochrome or the Kodza look. Leave the translucent greys (`rgba(10, 10, 10, …)`) as they are: they suit any light background. On a dark palette, set the other variables from Dark mode too.
- WordPress turns straight quotes and `--` into typographic ones in the text of a Custom HTML block (not inside `<code>` or `<pre>`).

#### With Elementor

- HTML: an **HTML** widget (Elementor shows it to administrators only). It keeps the code exactly as pasted, straight quotes included.
- CSS and JS: as above. Elementor's Site Settings → Theme Style styles every button, field, link and image of the page, components included; the theme guard at the end of the CSS keeps the component's buttons, fields and link colours as they are.
- The Elementor editor redraws each widget after the page has loaded: without the script below, the component stays still in the editor preview (the published page works). Add it once per site, in the footer like the component's script (`kodza/elementor-editor.js`, or a code-snippets plugin):

```js
// Kodza in the Elementor editor: the editor redraws each HTML widget after the page has loaded.
// Start Kodza in what it draws, stop it in what it replaces or removes. Once per site.
window.addEventListener('elementor/frontend/init', () => {
  if (!elementorFrontend.isEditMode()) return;
  class KodzaWidget extends elementorModules.frontend.handlers.Base {
    onInit() {
      super.onInit();
      this.kodza = [...this.$element[0].children];
      document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: this.$element[0] } }));
    }
    onDestroy() {
      super.onDestroy();
      this.kodza.forEach((root) => document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } })));
    }
  }
  elementorFrontend.elementsHandler.attachHandler('html', KodzaWidget);
});
```

- No child theme: everything can go in the HTML widget instead, `<style>` with the CSS, the HTML, then `<script>` with the JS. It works on the page and in the editor without the script above.

### Shopify

- Files: `assets/kodza-custom-select.css` and `assets/kodza-custom-select.js` (the Files commands with `-o assets/…`).
- In the section: `{{ 'kodza-custom-select.css' | asset_url | stylesheet_tag }}` and `<script src="{{ 'kodza-custom-select.js' | asset_url }}" defer></script>`, then the HTML.
- The theme editor re-renders sections: restart them with
  `document.addEventListener('shopify:section:load', (e) => document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root: e.target } })));`
  and the same with `shopify:section:unload` → `kodza:destroy`.

### React / Next.js

- Files, side by side (e.g. in `components/kodza/`): `Select.tsx` (below), the CSS block under Code saved as `custom-select.css` and the JS block as `custom-select.js`, both as they are. The HTML block is already inside the component: skip it.
- Use it: `import { Select } from '@/components/kodza/Select';` then `<Select />`. Props: `variant` ("inline", or several in an array), `vars` (the `--kz-…` variables listed under API, e.g. `vars={{ '--kz-select-bg': … }}`), `className`, `style` and the other props of its `<label>` (`onClick`, `aria-…`).
- Next.js App Router: it is a Client Component already (`'use client'`). Pages Router: Next.js takes global CSS only in `pages/_app`, so move the `import './custom-select.css'` line there.
- Safe under StrictMode, client-side navigation and prop changes: when a prop changes, the `key` gives React a fresh element, `kodza:destroy` stops the script on the old one and `kodza:init` starts it on the new one.

```tsx
'use client';
// Kodza — Select, for React. From https://kodza.dev/components/custom-select/
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Next to this file: custom-select.css and custom-select.js, the component's CSS and JS from Kodza, as they are.
// Yours to edit: the markup is plain JSX below.
// The script changes this markup once React has rendered it (it adds layers, splits text, moves
// nodes), so React must not patch it afterwards. When a prop changes, the key gives React a fresh
// element: kodza:destroy stops the script on the old one, kodza:init starts it on the new one.
import { useRef, useEffect, type ComponentPropsWithoutRef, type ComponentRef, type CSSProperties } from 'react';
import './custom-select.css';

type Variant = "inline";

export type SelectProps = Omit<ComponentPropsWithoutRef<'label'>, "children" | "variant" | "vars"> & {
  /** Modifier class(es): .kodza-select--inline */
  variant?: Variant | Variant[];
  /** Settings, as CSS variables on the root */
  vars?: {
    /** default: #ffffff */
    "--kz-select-bg"?: string | number;
    /** default: #0a0a0a */
    "--kz-select-fg"?: string | number;
    /** default: rgba(10, 10, 10, 0.6) */
    "--kz-select-muted"?: string | number;
    /** default: rgba(10, 10, 10, 0.14) */
    "--kz-select-line"?: string | number;
    /** default: rgba(10, 10, 10, 0.3) */
    "--kz-select-line-hover"?: string | number;
    /** default: rgba(10, 10, 10, 0.06) */
    "--kz-select-soft"?: string | number;
    /** default: 0 18px 40px -16px rgba(10, 10, 10, 0.3) */
    "--kz-select-shadow"?: string | number;
    /** default: 56px */
    "--kz-select-height"?: string | number;
    /** default: 12px */
    "--kz-select-radius"?: string | number;
    /** default: 16px */
    "--kz-select-pad"?: string | number;
    /** default: 0.35s */
    "--kz-select-duration"?: string | number;
    /** default: cubic-bezier(0.22, 1, 0.36, 1) */
    "--kz-select-ease"?: string | number;
  };
  className?: string;
};

export function Select({ variant, vars, className, style, ...rest }: SelectProps) {
  const ref = useRef<ComponentRef<'label'>>(null);
  const classes = ["kodza-select", ...([] as string[]).concat(variant ?? []).map((v) => `kodza-select--${v}`), className].filter(Boolean).join(' ');
  // Everything the markup is made of: when it changes, React gets a fresh element (see the top)
  const key = JSON.stringify([classes, vars, style, rest]);

  // Starts the script on this element once React has rendered it, stops it when it goes
  useEffect(() => {
    const root = ref.current;
    let live = true;
    // @ts-ignore: a plain script, no types to find
    import('./custom-select.js').then(() => {
      if (live) document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root } }));
    });
    return () => {
      live = false;
      document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } }));
    };
  }, [key]);

  return (
    <label key={key} {...rest} className={classes} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
      <span className="kodza-select__label">Deploy day</span>
      <select className="kodza-select__native" name="day" defaultValue="tue">
        <option value="mon">Monday</option>
        <option value="tue">Tuesday</option>
        <option value="wed">Wednesday</option>
        <option value="thu">Thursday</option>
        <option value="fri" disabled>Friday (not on our watch)</option>
      </select>
    </label>
  );
}
```

## Code

```html
<label class="kodza-select">
  <span class="kodza-select__label">Deploy day</span>
  <select class="kodza-select__native" name="day">
    <option value="mon">Monday</option>
    <option value="tue" selected>Tuesday</option>
    <option value="wed">Wednesday</option>
    <option value="thu">Thursday</option>
    <option value="fri" disabled>Friday (not on our watch)</option>
  </select>
</label>

<label class="kodza-select">
  <span class="kodza-select__label">Stack</span>
  <select class="kodza-select__native" name="stack">
    <option value="" selected disabled hidden></option>
    <option value="astro">Astro</option>
    <option value="vite">Vite</option>
    <option value="hugo">Hugo</option>
    <option value="html">Plain HTML, like a legend</option>
  </select>
</label>

<label class="kodza-select">
  <span class="kodza-select__label">Font</span>
  <select class="kodza-select__native" name="font">
    <optgroup label="Sans">
      <option value="geist" selected>Geist</option>
      <option value="inter">Inter</option>
      <option value="system">System UI</option>
    </optgroup>
    <optgroup label="Mono">
      <option value="geist-mono">Geist Mono</option>
      <option value="jetbrains">JetBrains Mono</option>
    </optgroup>
  </select>
</label>

<label class="kodza-select kodza-select--inline">
  <span class="kodza-select__label">Sort</span>
  <select class="kodza-select__native" name="sort">
    <option value="new" selected>Newest first</option>
    <option value="old">Oldest first</option>
    <option value="az">A to Z</option>
    <option value="stars">Most copied</option>
  </select>
</label>
```

```css
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Select
   A real select, dressed up: the script builds a listbox on top of it (and keeps the real one
   in step, so forms and WordPress get the value). The list unrolls from the field, a highlight
   slides from option to option, the chosen one gets a tick, and the field's value rolls to the
   new choice. Arrows, Home, End, typing a few letters, Enter, Escape. Without JS, the native
   select stays, styled. Same box as Text Field. To start empty, make the first option an empty
   one marked selected, disabled and hidden: the label then sits in the field until a choice.
   For a toolbar (sort, filters), --inline makes it a 40px pill with the label before the value.
   Everything is tuned with the --kz-select-* variables. */
.kodza-select {
  --kz-select-bg: #ffffff;
  --kz-select-fg: #0a0a0a;
  --kz-select-muted: rgba(10, 10, 10, 0.6);
  --kz-select-line: rgba(10, 10, 10, 0.14);
  --kz-select-line-hover: rgba(10, 10, 10, 0.3);
  --kz-select-soft: rgba(10, 10, 10, 0.06);
  --kz-select-shadow: 0 18px 40px -16px rgba(10, 10, 10, 0.3);
  --kz-select-height: 56px;
  --kz-select-radius: 12px;
  --kz-select-pad: 16px;
  --kz-select-duration: 0.35s;
  --kz-select-ease: cubic-bezier(0.22, 1, 0.36, 1);

  position: relative;
  display: block;
  width: 100%;
  max-width: 320px;
  /* The closed list keeps its size, ready to unroll, but never lengthens the page */
  contain: layout;
  /* A number, not auto, so it can wait for the list to roll up before dropping back */
  z-index: 0;
  transition: z-index 0s linear var(--kz-select-duration);
  color: var(--kz-select-fg);
}

/* Open, the field rises above what follows it (its list included) */
.kodza-select.is-open {
  z-index: 20;
  transition-delay: 0s;
}

/* The box: label on top, value below (the native select, or the button the script adds) */
.kodza-select__label {
  position: absolute;
  top: 10px;
  left: var(--kz-select-pad);
  z-index: 1;
  color: var(--kz-select-muted);
  font-size: 12px;
  line-height: 1;
  pointer-events: none;
  transform-origin: left top;
  transition: transform var(--kz-select-duration) var(--kz-select-ease);
}

/* Nothing chosen yet (an empty, hidden first option): the label sits in the field at the size
   of a value, as in Text Field, and rises when the field takes the focus or opens */
.kodza-select.is-empty:not(.is-open):not(:focus-within) .kodza-select__label {
  transform: translateY(calc(var(--kz-select-height) / 2 - 17.5px)) scale(1.25);
}

.kodza-select__native,
.kodza-select__trigger {
  display: flex;
  align-items: flex-end;
  width: 100%;
  height: var(--kz-select-height);
  margin: 0;
  padding: 0 44px 9px var(--kz-select-pad);
  border: 0;
  border-radius: var(--kz-select-radius);
  background: var(--kz-select-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6.5 8 10.5l4-4' fill='none' stroke='%23999' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") right 16px center / 16px no-repeat;
  box-shadow: inset 0 0 0 1px var(--kz-select-line);
  color: inherit;
  font: inherit;
  font-size: 15px;
  line-height: 22px;
  text-align: left;
  cursor: pointer;
  appearance: none;
  transition: box-shadow 0.25s ease;
}

.kodza-select__native:hover,
.kodza-select__trigger:hover {
  box-shadow: inset 0 0 0 1px var(--kz-select-line-hover);
}

.kodza-select__native:focus-visible,
.kodza-select__trigger:focus-visible,
.kodza-select.is-open .kodza-select__trigger {
  outline: none;
  box-shadow: inset 0 0 0 1.5px var(--kz-select-fg), 0 0 0 4px var(--kz-select-soft);
}

/* Enhanced: the native select steps back (still in the form), the button takes its place */
.kodza-select.is-ready .kodza-select__native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  clip-path: inset(50%);
}

.kodza-select__trigger {
  background-image: none;
}

.kodza-select__value {
  display: inline-grid;
  min-width: 0;
  overflow: hidden;
}

.kodza-select__value > span {
  grid-area: 1 / 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Every option, invisible, under the value: the field keeps the width of the longest one */
.kodza-select__sizes {
  display: grid;
  height: 0;
  visibility: hidden;
}

.kodza-select__sizes > span {
  grid-area: 1 / 1;
  white-space: nowrap;
}

.kodza-select__chevron {
  position: absolute;
  top: calc(var(--kz-select-height) / 2 - 8px);
  right: 16px;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--kz-select-muted);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
  transition: transform var(--kz-select-duration) var(--kz-select-ease);
}

.kodza-select.is-open .kodza-select__chevron {
  transform: rotate(180deg);
}

/* The list unrolls from the field */
.kodza-select__list {
  position: absolute;
  top: calc(var(--kz-select-height) + 8px);
  right: 0;
  left: 0;
  z-index: 20;
  max-height: 280px;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: 14px;
  background: var(--kz-select-bg);
  box-shadow: 0 0 0 1px var(--kz-select-line), var(--kz-select-shadow);
  list-style: none;
  visibility: hidden;
  opacity: 0;
  clip-path: inset(0 0 100% 0 round 14px);
  transform: translateY(-4px);
  transition:
    clip-path var(--kz-select-duration) var(--kz-select-ease),
    opacity 0.2s ease,
    transform var(--kz-select-duration) var(--kz-select-ease),
    visibility 0s linear var(--kz-select-duration);
}

.kodza-select.is-open .kodza-select__list {
  visibility: visible;
  opacity: 1;
  clip-path: inset(-40px -40px -60px -40px round 14px);
  transform: none;
  transition-delay: 0s;
}

.kodza-select.is-above .kodza-select__list {
  top: auto;
  bottom: calc(var(--kz-select-height) + 8px);
  clip-path: inset(100% 0 0 0 round 14px);
  transform: translateY(4px);
}

.kodza-select.is-above.is-open .kodza-select__list {
  clip-path: inset(-60px -40px -40px -40px round 14px);
  transform: none;
}

.kodza-select__highlight {
  position: absolute;
  top: 0;
  right: 6px;
  left: 6px;
  height: var(--kz-hl-h, 36px);
  border-radius: 8px;
  background: var(--kz-select-soft);
  opacity: var(--kz-hl-on, 0);
  transform: translateY(var(--kz-hl-y, 0));
  pointer-events: none;
}

.kodza-select.is-open .kodza-select__highlight {
  transition: transform 0.22s var(--kz-select-ease), opacity 0.15s ease;
}

.kodza-select__group {
  margin: 0;
  padding: 8px 10px 4px 32px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--kz-select-muted);
}

.kodza-select__option {
  position: relative;
  display: flex;
  align-items: center;
  height: 36px;
  padding: 0 10px 0 32px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.kodza-select__option[aria-disabled="true"] {
  color: var(--kz-select-muted);
  cursor: not-allowed;
}

/* The tick of the chosen option draws itself */
.kodza-select__option svg {
  position: absolute;
  left: 10px;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 0.15s ease-in;
}

.kodza-select__option[aria-selected="true"] svg {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.35s var(--kz-select-ease) 0.05s;
}

/* Inline: a 40px pill for a toolbar. The label sits before the value, on the same line (the
   script measures it), and the field is as wide as its longest option */
.kodza-select--inline {
  --kz-select-height: 40px;
  --kz-select-radius: 999px;
  --kz-select-pad: 14px;
  display: inline-block;
  width: auto;
  max-width: 100%;
  vertical-align: middle;
}

.kodza-select--inline .kodza-select__label,
.kodza-select--inline.is-empty:not(.is-open):not(:focus-within) .kodza-select__label {
  top: 50%;
  font-size: 13px;
  transform: translateY(-50%);
}

.kodza-select--inline .kodza-select__native,
.kodza-select--inline .kodza-select__trigger {
  align-items: center;
  padding: 0 38px 0 calc(var(--kz-select-pad) + var(--kz-select-inset, 3em) + 8px);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
}

.kodza-select--inline .kodza-select__native {
  width: auto;
  background-position: right 14px center;
}

.kodza-select--inline .kodza-select__chevron {
  right: 14px;
}

.kodza-select--inline .kodza-select__list {
  right: auto;
  width: max-content;
  min-width: 100%;
  max-width: min(320px, calc(100vw - 32px));
}

@media (prefers-reduced-motion: reduce) {
  .kodza-select__label,
  .kodza-select__native,
  .kodza-select__trigger,
  .kodza-select__chevron,
  .kodza-select__list,
  .kodza-select.is-open .kodza-select__highlight,
  .kodza-select__option svg {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}

/* Theming example — on a dark background:
.dark-section .kodza-select {
  --kz-select-bg: #161616;
  --kz-select-fg: #f2f2f0;
  --kz-select-muted: rgba(242, 242, 240, 0.62);
  --kz-select-line: rgba(255, 255, 255, 0.14);
  --kz-select-line-hover: rgba(255, 255, 255, 0.3);
  --kz-select-soft: rgba(255, 255, 255, 0.08);
  --kz-select-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.8);
}
*/

/* kodza-guard 963a4ed2fa1a — generated by Kodza, do not edit.
   Theme guard: keeps a site's own CSS (WordPress themes, Bootstrap, CSS resets…) off this
   component. :not(#_) is always true and weighs as much as an id, so these lines win over
   theme rules made of classes and tags. Customise the component through its --kz-* variables. */

/* What the browser gives, where the component sets it only in some states: at the lowest weight, so its own rules below put it back */

:where(.kodza-select):not(#_) {
  vertical-align: revert;
}

:where(.kodza-select__native):not(#_) {
  outline: revert;
  position: revert;
}

:where(.kodza-select__trigger):not(#_) {
  outline: revert;
}

:where(.kodza-select__list):not(#_) {
  max-width: revert;
}

:where(.kodza-select__highlight):not(#_) {
  transition: revert;
}

:where(.kodza-select__option):not(#_) {
  color: revert;
}

/* What the browser gives, on everything the component leaves to it */

.kodza-select:not(#_) {
  border: revert;
  padding: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-height: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
}

.kodza-select__label:not(#_),
.kodza-select__value:not(#_),
.kodza-select__sizes:not(#_),
.kodza-select__sizes span:where(:not([class*="kodza-"])):not(#_),
.kodza-select__value span:where(:not([class*="kodza-"])):not(#_) {
  box-sizing: revert;
}

.kodza-select__native:not(#_) {
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  outline-offset: revert;
  max-width: revert;
  max-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
  white-space: revert;
  min-height: revert;
}

.kodza-select__trigger:not(#_) {
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  outline-offset: revert;
  max-width: revert;
  max-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
  white-space: revert;
  min-height: revert;
}

.kodza-select__chevron:not(#_),
.kodza-select__option svg:where(:not([class*="kodza-"])):not(#_) {
  border: revert;
  margin: revert;
  padding: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  color: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

.kodza-select__list:not(#_) {
  border: revert;
  outline: revert;
  text-decoration: revert;
  box-sizing: revert;
  float: revert;
  outline-offset: revert;
  appearance: revert;
  color: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

.kodza-select__highlight:not(#_) {
  border: revert;
  margin: revert;
  padding: revert;
  outline: revert;
  text-decoration: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  color: revert;
  font-family: revert;
  font-size: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

.kodza-select__option:not(#_) {
  border: revert;
  margin: revert;
  outline: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  font-family: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

.kodza-select__group:not(#_) {
  border: revert;
  border-radius: revert;
  outline: revert;
  text-decoration: revert;
  transition: revert;
  list-style: revert;
  box-sizing: revert;
  float: revert;
  position: revert;
  background-color: revert;
  background-image: revert;
  box-shadow: revert;
  outline-offset: revert;
  appearance: revert;
  max-width: revert;
  max-height: revert;
  font-weight: revert;
  font-style: revert;
  line-height: revert;
  letter-spacing: revert;
  text-transform: revert;
  text-underline-offset: revert;
  text-align: revert;
  text-indent: revert;
  text-shadow: revert;
  vertical-align: revert;
}

.kodza-select__native option:where(:not([class*="kodza-"])):not(#_),
.kodza-select__native optgroup:where(:not([class*="kodza-"])):not(#_) {
  box-sizing: revert;
  color: revert;
}

.kodza-select__chevron:not(#_):where(:not([hidden])),
.kodza-select__list:not(#_):where(:not([hidden])),
.kodza-select__highlight:not(#_):where(:not([hidden])),
.kodza-select__group:not(#_):where(:not([hidden])),
.kodza-select__option svg:where(:not([class*="kodza-"])):not(#_):where(:not([hidden])) {
  display: revert;
}

.kodza-select__chevron:not(#_):where([hidden]),
.kodza-select__list:not(#_):where([hidden]),
.kodza-select__highlight:not(#_):where([hidden]),
.kodza-select__group:not(#_):where([hidden]),
.kodza-select__option svg:where(:not([class*="kodza-"])):not(#_):where([hidden]) {
  display: none;
}

/* The component's own rules, one step stronger: real buttons and fields, what it sets on tags themes style (links, lists, headings, images…), and the root width (a theme may narrow it, never widen it) */

.kodza-select:not(#_) {
  position: relative;
  display: block;
  transition: z-index 0s linear var(--kz-select-duration);
  color: var(--kz-select-fg);
}

.kodza-select:not(#_) {
  width: min(100%, 320px);
}

.kodza-select.is-open:not(#_) {
  transition-delay: 0s;
}

.kodza-select__native:not(#_),
.kodza-select__trigger:not(#_) {
  display: flex;
  align-items: flex-end;
  width: 100%;
  height: var(--kz-select-height);
  margin: 0;
  padding: 0 44px 9px var(--kz-select-pad);
  border: 0;
  border-radius: var(--kz-select-radius);
  background: var(--kz-select-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6.5 8 10.5l4-4' fill='none' stroke='%23999' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") right 16px center / 16px no-repeat;
  box-shadow: inset 0 0 0 1px var(--kz-select-line);
  color: inherit;
  font: inherit;
  font-size: 15px;
  line-height: 22px;
  text-align: left;
  cursor: pointer;
  appearance: none;
  transition: box-shadow 0.25s ease;
}

.kodza-select__native:hover:not(#_),
.kodza-select__trigger:hover:not(#_) {
  box-shadow: inset 0 0 0 1px var(--kz-select-line-hover);
}

.kodza-select__native:focus-visible:not(#_),
.kodza-select__trigger:focus-visible:not(#_),
.kodza-select.is-open .kodza-select__trigger:not(#_) {
  outline: none;
  box-shadow: inset 0 0 0 1.5px var(--kz-select-fg), 0 0 0 4px var(--kz-select-soft);
}

.kodza-select.is-ready .kodza-select__native:not(#_) {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  clip-path: inset(50%);
}

.kodza-select__trigger:not(#_) {
  background-image: none;
}

.kodza-select__chevron:not(#_) {
  position: absolute;
  transition: transform var(--kz-select-duration) var(--kz-select-ease);
}

.kodza-select__list:not(#_) {
  position: absolute;
  max-height: 280px;
  margin: 0;
  padding: 6px;
  border-radius: 14px;
  background: var(--kz-select-bg);
  box-shadow: 0 0 0 1px var(--kz-select-line), var(--kz-select-shadow);
  list-style: none;
  transition: clip-path var(--kz-select-duration) var(--kz-select-ease),
    opacity 0.2s ease,
    transform var(--kz-select-duration) var(--kz-select-ease),
    visibility 0s linear var(--kz-select-duration);
}

.kodza-select.is-open .kodza-select__list:not(#_) {
  transition-delay: 0s;
}

.kodza-select__highlight:not(#_) {
  position: absolute;
  border-radius: 8px;
  background: var(--kz-select-soft);
}

.kodza-select.is-open .kodza-select__highlight:not(#_) {
  transition: transform 0.22s var(--kz-select-ease), opacity 0.15s ease;
}

.kodza-select__group:not(#_) {
  margin: 0;
  padding: 8px 10px 4px 32px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--kz-select-muted);
}

.kodza-select__option:not(#_) {
  position: relative;
  display: flex;
  padding: 0 10px 0 32px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
}

.kodza-select__option[aria-disabled="true"]:not(#_) {
  color: var(--kz-select-muted);
}

.kodza-select__option svg:not(#_) {
  position: absolute;
  transition: stroke-dashoffset 0.15s ease-in;
}

.kodza-select__option[aria-selected="true"] svg:not(#_) {
  transition: stroke-dashoffset 0.35s var(--kz-select-ease) 0.05s;
}

.kodza-select--inline:not(#_) {
  display: inline-block;
  vertical-align: middle;
}

.kodza-select--inline:not(#_) {
  width: auto;
}

.kodza-select--inline .kodza-select__native:not(#_),
.kodza-select--inline .kodza-select__trigger:not(#_) {
  align-items: center;
  padding: 0 38px 0 calc(var(--kz-select-pad) + var(--kz-select-inset, 3em) + 8px);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
}

.kodza-select--inline .kodza-select__native:not(#_) {
  width: auto;
  background-position: right 14px center;
}

.kodza-select--inline .kodza-select__list:not(#_) {
  max-width: min(320px, calc(100vw - 32px));
}

@media (prefers-reduced-motion: reduce) {
  .kodza-select__native:not(#_),
  .kodza-select__trigger:not(#_) {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kodza-select__chevron:not(#_),
  .kodza-select__list:not(#_),
  .kodza-select.is-open .kodza-select__highlight:not(#_),
  .kodza-select__option svg:not(#_) {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}
```

```js
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Select
// Builds a listbox over the real <select> (options, groups, disabled ones), keeps both in step
// and fires "change" on the real one, so forms and frameworks see an ordinary select. Keyboard
// as in the ARIA "select-only combobox" pattern: the focus stays on the field, arrows move,
// letters jump, Enter picks, Escape closes. Options changed by the page (counts, disabled
// ones, a new list) are read again; after setting .value from a script, fire "change" on it.
(() => {
  const SELECTOR = '.kodza-select';
  const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  const tick = '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M3.5 8.5l3 3 6-7" pathLength="1"/></svg>';
  const chevron = '<svg class="kodza-select__chevron" viewBox="0 0 16 16" aria-hidden="true"><path d="M4 6.5 8 10.5l4-4"/></svg>';
  let uid = 0;

  // One instance. Everything it starts is tied to `signal`, so kodza:destroy stops it all
  function mount(root, signal) {
    const native = root.querySelector('.kodza-select__native');
    const label = root.querySelector('.kodza-select__label');
    if (!native) return;
    const id = `kodza-select-${++uid}`;

    // The field: a button that says the current value
    const trigger = document.createElement('button');
    trigger.type = 'button';
    trigger.className = 'kodza-select__trigger';
    trigger.setAttribute('role', 'combobox');
    trigger.setAttribute('aria-haspopup', 'listbox');
    trigger.setAttribute('aria-expanded', 'false');
    trigger.setAttribute('aria-controls', `${id}-list`);
    if (label) {
      label.id = `${id}-label`;
      trigger.setAttribute('aria-labelledby', `${id}-label`);
    }
    const value = document.createElement('span');
    value.className = 'kodza-select__value';
    // Every option, invisible, under the value: the field is as wide as the longest one, so it
    // never changes width when the value rolls (the inline version sizes itself on it)
    const sizes = document.createElement('span');
    sizes.className = 'kodza-select__sizes';
    sizes.setAttribute('aria-hidden', 'true');
    value.append(sizes);
    trigger.append(value);
    trigger.insertAdjacentHTML('beforeend', chevron);

    // The list, from the real options (built again whenever the page changes them)
    const list = document.createElement('ul');
    list.className = 'kodza-select__list';
    list.id = `${id}-list`;
    list.setAttribute('role', 'listbox');
    if (label) list.setAttribute('aria-labelledby', `${id}-label`);
    const highlight = document.createElement('li');
    highlight.className = 'kodza-select__highlight';
    highlight.setAttribute('role', 'presentation');
    list.append(highlight);
    let options = [];
    const entries = new Map();
    const build = () => {
      options = [];
      entries.clear();
      [...list.children].forEach((child) => child !== highlight && child.remove());
      sizes.replaceChildren();
      [...native.children].forEach((child) => {
        const group = child.tagName === 'OPTGROUP' ? child : null;
        if (group) {
          const head = document.createElement('li');
          head.className = 'kodza-select__group';
          head.setAttribute('role', 'presentation');
          head.textContent = group.label;
          list.append(head);
        }
        (group ? [...group.children] : [child]).forEach((option) => {
          if (option.hidden) return; // the placeholder: "nothing chosen yet" is not a choice
          const item = document.createElement('li');
          item.className = 'kodza-select__option';
          item.id = `${id}-option-${options.length}`;
          item.setAttribute('role', 'option');
          item.innerHTML = tick;
          item.append(option.textContent);
          if (option.disabled || group?.disabled) item.setAttribute('aria-disabled', 'true');
          list.append(item);
          const entry = { option, item };
          options.push(entry);
          entries.set(item, entry);
          sizes.append(Object.assign(document.createElement('span'), { textContent: option.textContent }));
        });
      });
    };
    build();
    native.after(trigger, list);
    native.tabIndex = -1;
    native.setAttribute('aria-hidden', 'true');

    const enabled = () => options.filter(({ item }) => item.getAttribute('aria-disabled') !== 'true');
    const isOpen = () => root.classList.contains('is-open');
    let active = null;

    // The value rolls to the new choice
    let shown = null;
    const show = (text, animate) => {
      const prev = shown;
      if (prev && prev.textContent === text) return;
      const span = Object.assign(document.createElement('span'), { textContent: text });
      value.append(span);
      shown = span;
      if (!prev) return;
      if (!animate || reduceMotion) return prev.remove();
      const timing = { duration: 420, easing: 'cubic-bezier(0.22, 1, 0.36, 1)' };
      prev.animate([{ transform: 'none' }, { transform: 'translateY(-110%)' }], { ...timing, fill: 'forwards' }).finished.then(() => prev.remove());
      span.animate([{ transform: 'translateY(110%)' }, { transform: 'none' }], timing);
    };

    const sync = (animate) => {
      options.forEach(({ option, item }) => item.setAttribute('aria-selected', String(option.selected)));
      // An empty, hidden first option leaves the field empty: the label sits inside, as in Text Field
      const chosen = native.selectedOptions[0];
      const empty = !chosen || chosen.hidden || !chosen.textContent.trim();
      root.classList.toggle('is-empty', empty);
      show(empty ? '' : chosen.textContent, animate);
    };

    const light = (entry, scroll = true) => {
      active = entry;
      if (!entry) {
        trigger.removeAttribute('aria-activedescendant');
        return list.style.setProperty('--kz-hl-on', 0);
      }
      trigger.setAttribute('aria-activedescendant', entry.item.id);
      list.style.setProperty('--kz-hl-y', `${entry.item.offsetTop}px`);
      list.style.setProperty('--kz-hl-h', `${entry.item.offsetHeight}px`);
      list.style.setProperty('--kz-hl-on', 1);
      // Scroll the list only (scrollIntoView would also nudge the page), with the option's group
      // heading when it opens the group, and the list's own padding above the very first row
      if (scroll) {
        const prev = entry.item.previousElementSibling;
        const first = prev?.classList.contains('kodza-select__group') ? prev : entry.item;
        const top = first.previousElementSibling === highlight ? 0 : first.offsetTop;
        const bottom = entry.item.offsetTop + entry.item.offsetHeight;
        if (top < list.scrollTop) list.scrollTop = top;
        else if (bottom > list.scrollTop + list.clientHeight) list.scrollTop = bottom - list.clientHeight;
      }
    };

    const open = () => {
      if (isOpen()) return;
      // Not enough room below and more above: the list opens upwards. A closed list that changes
      // side gets there at once, so it always unrolls from the field
      const box = trigger.getBoundingClientRect();
      const above = box.bottom + Math.min(280, list.scrollHeight) + 16 > innerHeight && box.top > innerHeight / 2;
      if (above !== root.classList.contains('is-above')) {
        list.style.transition = 'none';
        root.classList.toggle('is-above', above);
        void list.offsetWidth;
        list.style.transition = '';
      }
      root.classList.add('is-open');
      trigger.setAttribute('aria-expanded', 'true');
      light(options.find(({ option }) => option.selected) || enabled()[0]);
    };

    const close = () => {
      if (!isOpen()) return;
      root.classList.remove('is-open');
      trigger.setAttribute('aria-expanded', 'false');
      light(null);
    };

    const pick = (entry) => {
      if (!entry || entry.item.getAttribute('aria-disabled') === 'true') return;
      const changed = !entry.option.selected;
      entry.option.selected = true;
      sync(true);
      close();
      if (changed) native.dispatchEvent(new Event('change', { bubbles: true }));
    };

    // Typing a few letters jumps to the first matching option
    let typed = '';
    let typedTimer = 0;
    const typeAhead = (char) => {
      clearTimeout(typedTimer);
      typed += char.toLowerCase();
      typedTimer = setTimeout(() => (typed = ''), 600);
      const pool = enabled();
      const start = active ? pool.indexOf(active) + (typed.length === 1 ? 1 : 0) : 0;
      const order = [...pool.slice(start), ...pool.slice(0, start)];
      const match = order.find(({ item }) => item.textContent.trim().toLowerCase().startsWith(typed));
      if (!match) return;
      if (isOpen()) light(match);
      else pick(match);
    };

    trigger.addEventListener('click', () => (isOpen() ? close() : open()), { signal });
    trigger.addEventListener('keydown', (event) => {
      const pool = enabled();
      const index = pool.indexOf(active);
      if (!isOpen()) {
        if (['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(event.key)) {
          event.preventDefault();
          open();
        } else if (event.key.length === 1 && /\S/.test(event.key) && !event.ctrlKey && !event.metaKey && !event.altKey) {
          typeAhead(event.key);
        }
        return;
      }
      const moves = { ArrowDown: index + 1, ArrowUp: index - 1, Home: 0, End: pool.length - 1, PageDown: index + 5, PageUp: index - 5 };
      if (event.key in moves) {
        event.preventDefault();
        light(pool[Math.max(0, Math.min(pool.length - 1, moves[event.key]))]);
      } else if (event.key === 'Enter' || event.key === ' ') {
        event.preventDefault();
        pick(active);
      } else if (event.key === 'Tab') {
        pick(active);
      } else if (event.key.length === 1 && /\S/.test(event.key) && !event.ctrlKey && !event.metaKey && !event.altKey) {
        typeAhead(event.key);
      }
    }, { signal });

    const entryAt = (event) => entries.get(event.target.closest?.('.kodza-select__option'));
    list.addEventListener('pointermove', (event) => {
      const entry = entryAt(event);
      if (entry && active !== entry && entry.item.getAttribute('aria-disabled') !== 'true') light(entry, false);
    }, { signal });
    list.addEventListener('click', (event) => pick(entryAt(event)), { signal });
    // Keep the list from stealing the focus from the field, and the wrapping <label> from
    // sending clicks to the hidden select: a click on the label text focuses the field
    list.addEventListener('mousedown', (event) => event.preventDefault(), { signal });
    root.addEventListener('click', (event) => {
      if (trigger.contains(event.target)) return;
      event.preventDefault();
      if (!list.contains(event.target)) trigger.focus();
    }, { signal });
    document.addEventListener('pointerdown', (event) => !root.contains(event.target) && close(), { signal });
    // Escape closes it wherever the focus is: opened with a click, it stays on the field
    // (Chrome) or on the page (Safari)
    document.addEventListener('keydown', (event) => {
      if (event.key !== 'Escape' || !isOpen()) return;
      event.preventDefault();
      close();
      trigger.focus();
    }, { signal });
    // The real select changed from elsewhere (a form reset, a script): follow it
    native.addEventListener('change', () => sync(true), { signal });
    native.form?.addEventListener('reset', () => setTimeout(() => sync(true)), { signal });

    // The page changed the options (counts, disabled ones, a new list): build the list again,
    // keep the highlight on the same option, and show the value without a roll
    let queued = false;
    const observer = new MutationObserver(() => {
      if (queued) return;
      queued = true;
      queueMicrotask(() => {
        queued = false;
        if (signal.aborted) return;
        const was = active?.option;
        build();
        sync(false);
        if (isOpen()) light(options.find(({ option }) => option === was) || options.find(({ option }) => option.selected) || enabled()[0], false);
      });
    });
    observer.observe(native, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ['disabled', 'hidden', 'label'] });
    signal.addEventListener('abort', () => observer.disconnect());

    // Inline version: the value starts right after the label, whatever its length
    if (label && root.classList.contains('kodza-select--inline')) {
      const inset = () => root.style.setProperty('--kz-select-inset', `${Math.ceil(label.offsetWidth)}px`);
      inset();
      const sizer = new ResizeObserver(inset);
      sizer.observe(label);
      signal.addEventListener('abort', () => sizer.disconnect());
    }

    sync(false);
  }

  // Kodza lifecycle, the same in every component: `kodza:init` starts the instances inside
  // event.detail.root (the whole page by default), `kodza:destroy` stops them and puts their
  // markup back. For themes and apps that swap content without a page load.
  const instances = new WeakMap();
  const find = (scope = document) => [scope, ...scope.querySelectorAll(SELECTOR)].filter((el) => el.matches?.(SELECTOR));
  const init = (scope) => find(scope).forEach((root) => {
    if (root.classList.contains('is-ready')) return; // already running, maybe from another copy of this script
    const controller = new AbortController();
    instances.set(root, { controller, html: root.innerHTML, attrs: [...root.attributes].map((a) => [a.name, a.value]) });
    mount(root, controller.signal);
    root.classList.add('is-ready');
  });
  const destroy = (scope) => find(scope).forEach((root) => {
    const instance = instances.get(root);
    if (!instance) return;
    instances.delete(root);
    instance.controller.abort();
    [...root.attributes].forEach((a) => root.removeAttribute(a.name));
    instance.attrs.forEach(([name, value]) => root.setAttribute(name, value));
    root.innerHTML = instance.html;
  });
  document.addEventListener('kodza:init', (event) => init(event.detail?.root));
  document.addEventListener('kodza:destroy', (event) => destroy(event.detail?.root));
  init();
  // Loaded in <head>, the script runs before the markup exists: once more when it is parsed
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => init(), { once: true });
})();
```

Free to use, from Kodza (https://kodza.dev).
