Skip to content

Type to search the docs, API, and blog.

↑↓ navigate↵ openesc close
  • Zazz 0.14 alpha

    API

    Autocomplete

    A text input with suggestions filtered as you type.

    Installation

    Source
    pnpm dlx zazz-ui add autocomplete
    npx zazz-ui add autocomplete
    yarn dlx zazz-ui add autocomplete
    bunx zazz-ui add autocomplete

    Also adds fields, kbd, button, popover, menu, input, select, which it depends on. Run zazz-ui init first if the project has no zazz/ folder yet.

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Paint the right theme (background, form controls, scrollbars) before CSS loads -->
    <meta name="color-scheme" content="light dark">
    <!-- Zazz styles: base layers, then fields, kbd, button, popover, menu, input, select, autocomplete in cascade order -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_layers.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_variables.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_shadows.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_breakpoints.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_reset.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_typography.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_view-transitions.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/primitives/fields/fields.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/primitives/kbd/kbd.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/primitives/button/button.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/primitives/popover/popover.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/primitives/menu/menu.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/primitives/input/input.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/primitives/select/select.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/primitives/autocomplete/autocomplete.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-sm.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-md.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-lg.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-2xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-disabled.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-active.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-focus-visible.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-focus-within.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-hover.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-checked.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-current.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-open.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-stuck.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-starting.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-sm.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-md.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-lg.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-2xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-disabled.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-active.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-focus-visible.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-focus-within.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-hover.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-checked.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-current.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-open.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-stuck.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-starting.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-flow.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-grid.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-spacing.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-margin.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-sizing.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-typography.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-color.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-effects.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-box.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-pseudo.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_defaults.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-sr.css">
    <!-- Import map: bare specifiers in Zazz scripts resolve to pinned, SRI-checked files -->
    <script type="importmap">
    {
      "imports": {
        "signal-polyfill": "https://cdn.jsdelivr.net/npm/signal-polyfill@0.2.2/dist/index.js"
      },
      "integrity": {
        "https://cdn.jsdelivr.net/npm/signal-polyfill@0.2.2/dist/index.js": "sha384-0OqM7OXGT6Oz1z98u/geiFn/FUyz4iWexkXHCvbIGXRRDXl6bp6IKc0j78AQ6DEK"
      }
    }
    </script>
    <!-- Polyfill: Interest Invokers (interestfor) — native in Chromium only -->
    <script type="module" src="https://cdn.jsdelivr.net/npm/invokers@2.2.2/dist/esm/production/interest.js" integrity="sha384-hR2BVNtsS7fIIMwOm+f7MY0JZfuByGhQQfevCBB6evFATKzBsTw0JzH/RxD94z2T" crossorigin="anonymous"></script>
    <!-- Zazz behavior: side-effect modules by tag; the rest via module imports -->
    <script type="module" src="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/dialog-lifecycle.js"></script>
    <script type="module" src="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/primitives/menu/menu.js"></script>
    <script type="module" src="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/primitives/select/multiselect.js"></script>
    <script type="module" src="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/command-score.js"></script>
    <script type="module" src="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/hotkeys.js"></script>
    <script type="module" src="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/typeahead.js"></script>
    <script type="module" src="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/primitives/autocomplete/autocomplete.js"></script>
    <!-- Theme: apply the persisted (or preferred) scheme before first paint -->
    <script>
      (() => {
        try {
          // A stored choice pins the scheme with data-theme; with no choice the
          // page follows the system scheme.
          const storedTheme = localStorage.getItem("theme");
          if (storedTheme === "dark" || storedTheme === "light") {
            document.documentElement.dataset.theme = storedTheme;
          }
        } catch {
          /* no storage access: follow the system scheme */
        }
      })();
    </script>

    A <head> that loads the base layers and autocomplete with its dependencies from jsDelivr, pinned to 0.14.2. To load the whole kit in two requests, see the CDN install.

    Examples

    Default

    • Apple
    • Banana
    • Blueberry
    • Cherry
    • Grape

    No results.

    <div data-ui="field" style="--max-w: 96">
      <label data-field-slot="label" for="ac-fruit">Fruit</label>
      <ui-autocomplete>
        <input
          data-ui="input"
          id="ac-fruit"
          name="fruit"
          type="text"
          placeholder="Search fruits..."
          role="combobox"
          aria-expanded="false"
          aria-autocomplete="list"
          autocomplete="off"
        />
        <div
          data-autocomplete-slot="panel"
          data-popover-side="bottom"
          data-popover-align="start"
          popover="manual"
        >
          <ul role="listbox" data-autocomplete-slot="list" aria-label="Fruit suggestions">
            <li
              role="option"
              data-autocomplete-slot="item"
              data-ui="button"
              data-button-variant="ghost"
              data-autocomplete-value="Apple"
              style="--justify: start"
            >
              Apple
            </li>
            <li
              role="option"
              data-autocomplete-slot="item"
              data-ui="button"
              data-button-variant="ghost"
              data-autocomplete-value="Banana"
              style="--justify: start"
            >
              Banana
            </li>
            <li
              role="option"
              data-autocomplete-slot="item"
              data-ui="button"
              data-button-variant="ghost"
              data-autocomplete-value="Blueberry"
              style="--justify: start"
            >
              Blueberry
            </li>
            <li
              role="option"
              data-autocomplete-slot="item"
              data-ui="button"
              data-button-variant="ghost"
              data-autocomplete-value="Cherry"
              style="--justify: start"
            >
              Cherry
            </li>
            <li
              role="option"
              data-autocomplete-slot="item"
              data-ui="button"
              data-button-variant="ghost"
              data-autocomplete-value="Grape"
              style="--justify: start"
            >
              Grape
            </li>
          </ul>
          <p data-autocomplete-slot="empty" style="--text: var(--color-muted-foreground)">
            No results.
          </p>
        </div>
      </ui-autocomplete>
    </div>
    /**
     * autocomplete.css — Autocomplete (ui-autocomplete | [data-ui~="autocomplete"], [data-autocomplete-slot~="panel"])
     *
     * @layer      variables, components
     * @requires   _layers.css, _variables.css, popover.css, button.css, fields.css,
     *             select.css (--ui-option-*), input.css, menu.css (--ui-menu-shadow)
     * @uses       [popover="manual"] — panel opened/closed by autocomplete.ts
     * @uses       anchor-name, anchor-scope, position-anchor — tether panel to the input
     * @uses       anchor-size(width) — match panel width to the input (Baseline 2026)
     * @uses       :has() — group + empty-state visibility without JavaScript
     * @uses       data-popover-side / data-popover-align — maps to --ui-popover-position-* in popover.css
     * @tokens     --ui-autocomplete-* (@layer variables); items alias --ui-option-*
     * @see        autocomplete.ts — filtering, ranking, and keyboard behavior
     */
    
    @layer variables {
      :root {
        --ui-autocomplete-panel-max-h: calc(var(--spacing) * 72);
        --ui-autocomplete-shadow: var(--ui-menu-shadow);
      }
    }
    
    @layer ui.components {
      /* ===========================================================================
      AUTOCOMPLETE — input + anchored suggestion panel
      - The input is a plain [data-ui~="input"] (the no-JS baseline); the panel is a
        manual popover the script owns, riding popover.css's surface + placement.
      - Items are ghost buttons (--ui-option-*), matching a select's options.
      =========================================================================== */
    
      :where(ui-autocomplete, [data-ui~="autocomplete"]) {
        anchor-scope: --ui-autocomplete-trigger;
        display: block;
        inline-size: 100%;
      }
    
      :where(ui-autocomplete, [data-ui~="autocomplete"]) input:where([role="combobox"]) {
        anchor-name: --ui-autocomplete-trigger;
      }
    
      :where(ui-autocomplete, [data-ui~="autocomplete"]) [data-autocomplete-slot~="panel"] {
        position-anchor: --ui-autocomplete-trigger;
        /* ungated so the close fade keeps the column layout */
        flex-direction: column;
        --_max-h-len: var(--_max-h-resolved, var(--ui-autocomplete-panel-max-h));
        --_max-h-num: var(--_max-h-resolved, var(--ui-autocomplete-panel-max-h));
        max-block-size: calc(var(--_max-h-len) + var(--_max-h-num) * var(--spacing));
        overflow: auto;
        box-shadow: var(--_shadow-resolved, var(--ui-autocomplete-shadow));
      }
    
      /* Only display is gated: closed popovers stay display: none */
      :where(ui-autocomplete, [data-ui~="autocomplete"])
        [data-autocomplete-slot~="panel"]:popover-open {
        display: flex;
      }
    
      /* Inline variant (no [popover]): the list renders in flow, always open,
         without the floating surface chrome */
      :where(ui-autocomplete, [data-ui~="autocomplete"])
        [data-autocomplete-slot~="panel"]:not([popover]) {
        display: flex;
        box-shadow: none;
      }
    
      :where(ui-autocomplete, [data-ui~="autocomplete"]) [data-autocomplete-slot~="panel"] {
        min-inline-size: anchor-size(width);
      }
    
      :where(ui-autocomplete, [data-ui~="autocomplete"]) [data-autocomplete-slot~="list"] {
        display: flex;
        flex-direction: column;
        gap: 1px;
        margin: 0;
        padding: 0;
        list-style: none;
      }
    
      :where(ui-autocomplete, [data-ui~="autocomplete"]) [data-autocomplete-slot~="group"] {
        display: flex;
        flex-direction: column;
        gap: 1px;
      }
    
      /* score ranking writes order -1000..0 on items: keep the label first */
      :where(ui-autocomplete, [data-ui~="autocomplete"]) [data-autocomplete-slot~="group-label"] {
        order: -1001;
      }
    
      :where(ui-autocomplete, [data-ui~="autocomplete"]) [data-autocomplete-slot~="item"] {
        cursor: pointer;
      }
    
      /* The ghost-button variant writes the --_button-* privates, so the
         highlight writes the same ones (a hook would lose to the variant). */
      :where(ui-autocomplete, [data-ui~="autocomplete"])
        [data-autocomplete-slot~="item"][data-autocomplete-state~="highlighted"] {
        --_button-bg: var(--ui-button-bg--hover);
        --_button-text: var(--ui-button-text--hover);
      }
    
      /* a group with no visible items disappears, label and all */
      :where(ui-autocomplete, [data-ui~="autocomplete"])
        [data-autocomplete-slot~="group"]:not(:has([data-autocomplete-slot~="item"]:not([hidden]))) {
        display: none;
      }
    
      :where(ui-autocomplete, [data-ui~="autocomplete"]) [data-autocomplete-slot~="empty"] {
        display: none;
        padding: calc(var(--spacing) * 2);
      }
    
      :where(ui-autocomplete, [data-ui~="autocomplete"])
        [data-autocomplete-slot~="panel"]:not(:has([data-autocomplete-slot~="item"]:not([hidden])))
        [data-autocomplete-slot~="empty"] {
        display: block;
      }
    }
    // primitives/menu/menu.js
    "use strict";
    /**
     * @fileoverview `<ui-menu>`: HTML web component for keyboard-enhanced menus.
     * @description Light-DOM custom element that augments the CSS-only menu
     * pattern (trigger + anchored `[data-menu-slot~="popover"]` panel) with
     * arrow-key navigation. The attribute form `[data-ui~="menu"]` stays fully functional
     * without JavaScript: the Popover API provides open/close, light dismiss,
     * and focus return on its own.
     *
     * Keyboard behavior:
     * - ArrowDown / ArrowUp on the closed trigger open the panel and focus the
     *   first / last item.
     * - ArrowDown / ArrowUp inside the open panel move focus between items,
     *   wrapping around and skipping disabled items.
     * - Home / End jump to the first / last item.
     * - Escape and light dismiss are native Popover API behavior (no code here).
     *
     * The menu keeps the honest disclosure posture: items are plain links and
     * buttons, and no `role="menu"` is claimed. Add the full ARIA menu contract
     * yourself only if every item is an action and you implement the rest of the
     * pattern (typeahead, close-on-activate).
     *
     * @example
     * <ui-menu>
     *   <button data-ui="button" type="button" popovertarget="m1">Open</button>
     *   <div id="m1" data-menu-slot="popover" popover="auto">
     *     <menu>
     *       <li><a href="/docs" data-ui="button" data-button-variant="ghost" style="--justify: start">Docs</a></li>
     *     </menu>
     *   </div>
     * </ui-menu>
     */
    import { ZazzElement, defineZazzElement } from "../../base/zazz-element.js";
    class UiMenu extends ZazzElement {
        setup(signal) {
            this.addEventListener("keydown", (event) => this.#onKeydown(event), { signal });
        }
        /**
         * @description The menu's own panel: a direct child so nested menus keep
         * their panels to themselves.
         *
         * @returns The panel element, or null when the markup is incomplete.
         */
        #panel() {
            const panel = this.querySelector(':scope > [data-menu-slot~="popover"]');
            return panel instanceof HTMLElement ? panel : null;
        }
        /**
         * @description Focusable items inside the panel, in DOM order.
         *
         * @param panel - The menu panel.
         * @returns Enabled links and buttons the arrow keys move between.
         */
        #items(panel) {
            return Array.from(panel.querySelectorAll("a[href], button"))
                .filter((node) => node instanceof HTMLElement)
                .filter((item) => !item.hasAttribute("disabled") &&
                item.getAttribute("aria-disabled") !== "true" &&
                item.closest('ui-menu, [data-ui~="menu"]') === this);
        }
        /**
         * @description Routes arrow-key, Home, and End presses: opens the panel from
         * the trigger, or moves focus between items inside the open panel.
         *
         * @param event - The keydown event.
         */
        #onKeydown(event) {
            if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key))
                return;
            const target = event.target;
            if (!(target instanceof HTMLElement))
                return;
            // Ignore keys that belong to a nested ui-menu
            if (target.closest('ui-menu, [data-ui~="menu"]') !== this)
                return;
            const panel = this.#panel();
            if (!panel)
                return;
            const isTrigger = target.parentElement === this &&
                (target.hasAttribute("popovertarget") || target.hasAttribute("interestfor"));
            const open = panel.matches(":popover-open");
            if (isTrigger && !open && (event.key === "ArrowDown" || event.key === "ArrowUp")) {
                event.preventDefault();
                panel.showPopover();
                const items = this.#items(panel);
                items[event.key === "ArrowDown" ? 0 : items.length - 1]?.focus();
                return;
            }
            if (!open || !panel.contains(target))
                return;
            const items = this.#items(panel);
            if (items.length === 0)
                return;
            const index = items.indexOf(target);
            let nextIndex;
            switch (event.key) {
                case "ArrowDown":
                    nextIndex = index === -1 ? 0 : (index + 1) % items.length;
                    break;
                case "ArrowUp":
                    nextIndex = index === -1 ? items.length - 1 : (index - 1 + items.length) % items.length;
                    break;
                case "Home":
                    nextIndex = 0;
                    break;
                case "End":
                    nextIndex = items.length - 1;
                    break;
                default:
                    return;
            }
            event.preventDefault();
            items[nextIndex].focus();
        }
    }
    defineZazzElement("ui-menu", UiMenu);
    export { UiMenu };
    
    // primitives/select/multiselect.js
    "use strict";
    /**
     * @fileoverview `<ui-multiselect>`: a multi-select styled as a dropdown.
     * @description Light-DOM custom element that progressively enhances a real
     * `<select multiple data-ui="select">`. `appearance: base-select` does not
     * apply to multi-selects in stable engines, so the script hides the
     * select (which remains the form value carrier and source of truth) and
     * stamps a `[data-ui~="select"]`-look trigger button plus an anchored popover of
     * checkbox rows projected from the options. Checkbox changes write back to
     * `option.selected` and re-dispatch `change` on the select; external writes
     * and form resets flow the other way. Without JavaScript the native
     * multi-select listbox renders: fully functional and accessible.
     *
     * The trigger reads `<first selection> (+N more)`.
     *
     * Attributes on `<ui-multiselect>`:
     * - `data-multiselect-placeholder`: trigger text when nothing is selected.
     * - `data-multiselect-label-more`: overflow template, default `"(+{n} more)"`.
     * - `data-multiselect-side` / `data-multiselect-align`: forwarded to the stamped panel as `data-popover-*` (popover
     *   placement matrix).
     *
     * Stamped parts: `multiselect-trigger` (a `[data-ui~="select"]`-identity button),
     * `multiselect-icon` (chevron), `multiselect-panel` (`[popover]`),
     * `multiselect-option` (label + checkbox per option).
     */
    import { ZazzElement, defineZazzElement } from "../../base/zazz-element.js";
    import { effect, state } from "../../base/signals.js";
    /**
     * @description Formats the trigger label from the selected option labels.
     *
     * @param labels - Labels of the selected options, in DOM order.
     * @param placeholder - Text for an empty selection.
     * @param moreTemplate - Overflow template; `{n}` is the remaining count.
     * @returns The trigger text.
     */
    function resolveTriggerLabel(labels, placeholder, moreTemplate) {
        if (labels.length === 0)
            return placeholder;
        if (labels.length === 1)
            return labels[0];
        return `${labels[0]} ${moreTemplate.replace("{n}", String(labels.length - 1))}`;
    }
    let multiselectIdCounter = 0;
    class UiMultiselect extends ZazzElement {
        #stamped = [];
        #select = null;
        setup(signal) {
            const select = this.querySelector("select[multiple]");
            if (!(select instanceof HTMLSelectElement))
                return;
            this.#select = select;
            const placeholder = this.getAttribute("data-multiselect-placeholder") ?? "Select…";
            const moreTemplate = this.getAttribute("data-multiselect-label-more") ?? "(+{n} more)";
            const { trigger, label, panel, checkboxes } = this.#stamp(select);
            select.setAttribute("data-multiselect-state", "enhanced");
            const selectedLabels = () => Array.from(select.selectedOptions).map((option) => option.label);
            const selection = state(selectedLabels());
            // Checkbox → option: the select stays the source of truth
            checkboxes.forEach((checkbox, index) => {
                checkbox.addEventListener("change", () => {
                    const option = select.options[index];
                    if (option)
                        option.selected = checkbox.checked;
                    selection.set(selectedLabels());
                    select.dispatchEvent(new Event("change", { bubbles: true }));
                }, { signal });
            });
            // External writes and form resets → re-read (reset applies after the event)
            select.addEventListener("change", () => selection.set(selectedLabels()), { signal });
            select.form?.addEventListener("reset", () => queueMicrotask(() => selection.set(selectedLabels())), { signal });
            // Mirror popover open state onto the trigger's aria-expanded
            panel.addEventListener("toggle", (event) => {
                trigger.setAttribute("aria-expanded", String(event.newState === "open"));
            }, { signal });
            // Output adapter: trigger label + row checked states together
            effect(() => {
                selection.get();
                label.textContent = resolveTriggerLabel(selectedLabels(), placeholder, moreTemplate);
                checkboxes.forEach((checkbox, index) => {
                    const option = select.options[index];
                    if (option && checkbox.checked !== option.selected)
                        checkbox.checked = option.selected;
                });
            }, { signal });
        }
        teardown() {
            for (const node of this.#stamped)
                node.remove();
            this.#stamped = [];
            this.#select?.removeAttribute("data-multiselect-state");
            this.#select = null;
        }
        /**
         * @description Builds the trigger button and checkbox panel from the
         * select's options and inserts them after it.
         *
         * @param select - The enhanced select.
         * @returns The stamped parts and the checkbox list (option order).
         * @private
         */
        #stamp(select) {
            const panelId = `ui-multiselect-panel-${++multiselectIdCounter}`;
            const trigger = document.createElement("button");
            trigger.type = "button";
            trigger.dataset.ui = "select";
            trigger.setAttribute("data-multiselect-slot", "trigger");
            trigger.setAttribute("popovertarget", panelId);
            trigger.setAttribute("aria-expanded", "false");
            const label = document.createElement("span");
            label.setAttribute("data-multiselect-slot", "label");
            const icon = document.createElement("span");
            icon.setAttribute("data-multiselect-slot", "icon");
            icon.setAttribute("aria-hidden", "true");
            trigger.append(label, icon);
            const panel = document.createElement("div");
            panel.id = panelId;
            panel.setAttribute("data-multiselect-slot", "panel");
            panel.setAttribute("popover", "auto");
            const side = this.getAttribute("data-multiselect-side");
            const align = this.getAttribute("data-multiselect-align");
            if (side)
                panel.setAttribute("data-popover-side", side);
            if (align)
                panel.setAttribute("data-popover-align", align);
            const checkboxes = [];
            for (const [index, option] of Array.from(select.options).entries()) {
                const row = document.createElement("label");
                row.setAttribute("data-multiselect-slot", "option");
                const checkbox = document.createElement("input");
                checkbox.type = "checkbox";
                // an id, not a name: the select submits, and Chrome flags a field with neither
                checkbox.id = `${panelId}-${index}`;
                checkbox.checked = option.selected;
                checkbox.disabled = option.disabled;
                row.append(checkbox, document.createTextNode(option.label));
                panel.append(row);
                checkboxes.push(checkbox);
            }
            select.after(trigger, panel);
            this.#stamped = [trigger, panel];
            return { trigger, label, panel, checkboxes };
        }
    }
    defineZazzElement("ui-multiselect", UiMultiselect);
    export { UiMultiselect, resolveTriggerLabel };
    
    // primitives/autocomplete/autocomplete.js
    "use strict";
    /**
     * @fileoverview `<ui-autocomplete>`: an input that suggests options as you type.
     * @description Light-DOM custom element on the shared typeahead engine
     * (`base/typeahead.ts`). The visible input is the form value (free text is
     * allowed) and the anchored `popover="manual"` panel suggests matches ranked
     * by the vendored cmdk scorer. Committing a suggestion (Enter or click) fills
     * the input; without JavaScript the markup degrades to a plain `[data-ui~="input"]`.
     *
     * Attributes on the root:
     * - `data-autocomplete-sort="score"`: re-rank visually by match score (default: DOM order).
     * - `data-autocomplete-filter="none"`: show every item; another source filters.
     * - `data-autocomplete-min-length="<n>"`: query length before the panel opens (default 0).
     *
     * Parts: `autocomplete-panel` (popover="manual"), `autocomplete-list`
     * ([role="listbox"]), `autocomplete-item` ([role="option"], `data-autocomplete-value`,
     * optional `data-autocomplete-keywords`), `autocomplete-group` / `autocomplete-group-label`,
     * `autocomplete-empty`.
     */
    import { TypeaheadElement } from "../../base/typeahead.js";
    import { defineZazzElement } from "../../base/zazz-element.js";
    class UiAutocomplete extends TypeaheadElement {
        slotPrefix = "autocomplete";
        /**
         * @description Committing a suggestion fills the visible input (which is
         * the form value), closes the panel, and returns to typing position.
         *
         * @param item - The committed option.
         */
        commit(item, _source) {
            const input = this.searchInput;
            if (!input)
                return;
            input.value = this.itemValue(item);
            this.query.set(input.value);
            this.open.set(false);
            input.focus();
            input.dispatchEvent(new Event("change", { bubbles: true }));
        }
    }
    defineZazzElement("ui-autocomplete", UiAutocomplete);
    export { UiAutocomplete };

    Groups

    • Fruit
      Apple
      Cherry
    • Vegetables
      Carrot
      Cauliflower

    No results.

    <div data-ui="field" style="--max-w: 96">
      <label data-field-slot="label" for="ac-produce">Produce</label>
      <ui-autocomplete data-autocomplete-sort="score">
        <input
          data-ui="input"
          id="ac-produce"
          name="produce"
          type="text"
          placeholder="Search produce..."
          role="combobox"
          aria-expanded="false"
          aria-autocomplete="list"
          autocomplete="off"
        />
        <div
          data-autocomplete-slot="panel"
          data-popover-side="bottom"
          data-popover-align="start"
          popover="manual"
        >
          <ul role="listbox" data-autocomplete-slot="list" aria-label="Produce suggestions">
            <li role="group" data-autocomplete-slot="group" aria-labelledby="ac-group-fruit">
              <span
                data-autocomplete-slot="group-label"
                id="ac-group-fruit"
                style="
                  --display: inline-flex;
                  --p: 2;
                  --font-size: var(--font-size-eyebrow);
                  --font-weight: strong;
                  --font-weight: var(--font-weight-eyebrow);
                  --leading: var(--leading-eyebrow);
                  --tracking: var(--tracking-eyebrow);
                  --text-transform: uppercase;
                  --text: var(--color-muted-foreground);
                "
                >Fruit</span
              >
              <div
                role="option"
                data-autocomplete-slot="item"
                data-ui="button"
                data-button-variant="ghost"
                data-autocomplete-value="Apple"
                data-autocomplete-keywords="fruit red"
                style="--justify: start"
              >
                Apple
              </div>
              <div
                role="option"
                data-autocomplete-slot="item"
                data-ui="button"
                data-button-variant="ghost"
                data-autocomplete-value="Cherry"
                data-autocomplete-keywords="fruit red"
                style="--justify: start"
              >
                Cherry
              </div>
            </li>
            <li role="group" data-autocomplete-slot="group" aria-labelledby="ac-group-veg">
              <span
                data-autocomplete-slot="group-label"
                id="ac-group-veg"
                style="
                  --display: inline-flex;
                  --p: 2;
                  --font-size: var(--font-size-eyebrow);
                  --font-weight: strong;
                  --font-weight: var(--font-weight-eyebrow);
                  --leading: var(--leading-eyebrow);
                  --tracking: var(--tracking-eyebrow);
                  --text-transform: uppercase;
                  --text: var(--color-muted-foreground);
                "
                >Vegetables</span
              >
              <div
                role="option"
                data-autocomplete-slot="item"
                data-ui="button"
                data-button-variant="ghost"
                data-autocomplete-value="Carrot"
                data-autocomplete-keywords="vegetable orange"
                style="--justify: start"
              >
                Carrot
              </div>
              <div
                role="option"
                data-autocomplete-slot="item"
                data-ui="button"
                data-button-variant="ghost"
                data-autocomplete-value="Cauliflower"
                data-autocomplete-keywords="vegetable white"
                style="--justify: start"
              >
                Cauliflower
              </div>
            </li>
          </ul>
          <p data-autocomplete-slot="empty" style="--text: var(--color-muted-foreground)">
            No results.
          </p>
        </div>
      </ui-autocomplete>
    </div>
    /**
     * autocomplete.css — Autocomplete (ui-autocomplete | [data-ui~="autocomplete"], [data-autocomplete-slot~="panel"])
     *
     * @layer      variables, components
     * @requires   _layers.css, _variables.css, popover.css, button.css, fields.css,
     *             select.css (--ui-option-*), input.css, menu.css (--ui-menu-shadow)
     * @uses       [popover="manual"] — panel opened/closed by autocomplete.ts
     * @uses       anchor-name, anchor-scope, position-anchor — tether panel to the input
     * @uses       anchor-size(width) — match panel width to the input (Baseline 2026)
     * @uses       :has() — group + empty-state visibility without JavaScript
     * @uses       data-popover-side / data-popover-align — maps to --ui-popover-position-* in popover.css
     * @tokens     --ui-autocomplete-* (@layer variables); items alias --ui-option-*
     * @see        autocomplete.ts — filtering, ranking, and keyboard behavior
     */
    
    @layer variables {
      :root {
        --ui-autocomplete-panel-max-h: calc(var(--spacing) * 72);
        --ui-autocomplete-shadow: var(--ui-menu-shadow);
      }
    }
    
    @layer ui.components {
      /* ===========================================================================
      AUTOCOMPLETE — input + anchored suggestion panel
      - The input is a plain [data-ui~="input"] (the no-JS baseline); the panel is a
        manual popover the script owns, riding popover.css's surface + placement.
      - Items are ghost buttons (--ui-option-*), matching a select's options.
      =========================================================================== */
    
      :where(ui-autocomplete, [data-ui~="autocomplete"]) {
        anchor-scope: --ui-autocomplete-trigger;
        display: block;
        inline-size: 100%;
      }
    
      :where(ui-autocomplete, [data-ui~="autocomplete"]) input:where([role="combobox"]) {
        anchor-name: --ui-autocomplete-trigger;
      }
    
      :where(ui-autocomplete, [data-ui~="autocomplete"]) [data-autocomplete-slot~="panel"] {
        position-anchor: --ui-autocomplete-trigger;
        /* ungated so the close fade keeps the column layout */
        flex-direction: column;
        --_max-h-len: var(--_max-h-resolved, var(--ui-autocomplete-panel-max-h));
        --_max-h-num: var(--_max-h-resolved, var(--ui-autocomplete-panel-max-h));
        max-block-size: calc(var(--_max-h-len) + var(--_max-h-num) * var(--spacing));
        overflow: auto;
        box-shadow: var(--_shadow-resolved, var(--ui-autocomplete-shadow));
      }
    
      /* Only display is gated: closed popovers stay display: none */
      :where(ui-autocomplete, [data-ui~="autocomplete"])
        [data-autocomplete-slot~="panel"]:popover-open {
        display: flex;
      }
    
      /* Inline variant (no [popover]): the list renders in flow, always open,
         without the floating surface chrome */
      :where(ui-autocomplete, [data-ui~="autocomplete"])
        [data-autocomplete-slot~="panel"]:not([popover]) {
        display: flex;
        box-shadow: none;
      }
    
      :where(ui-autocomplete, [data-ui~="autocomplete"]) [data-autocomplete-slot~="panel"] {
        min-inline-size: anchor-size(width);
      }
    
      :where(ui-autocomplete, [data-ui~="autocomplete"]) [data-autocomplete-slot~="list"] {
        display: flex;
        flex-direction: column;
        gap: 1px;
        margin: 0;
        padding: 0;
        list-style: none;
      }
    
      :where(ui-autocomplete, [data-ui~="autocomplete"]) [data-autocomplete-slot~="group"] {
        display: flex;
        flex-direction: column;
        gap: 1px;
      }
    
      /* score ranking writes order -1000..0 on items: keep the label first */
      :where(ui-autocomplete, [data-ui~="autocomplete"]) [data-autocomplete-slot~="group-label"] {
        order: -1001;
      }
    
      :where(ui-autocomplete, [data-ui~="autocomplete"]) [data-autocomplete-slot~="item"] {
        cursor: pointer;
      }
    
      /* The ghost-button variant writes the --_button-* privates, so the
         highlight writes the same ones (a hook would lose to the variant). */
      :where(ui-autocomplete, [data-ui~="autocomplete"])
        [data-autocomplete-slot~="item"][data-autocomplete-state~="highlighted"] {
        --_button-bg: var(--ui-button-bg--hover);
        --_button-text: var(--ui-button-text--hover);
      }
    
      /* a group with no visible items disappears, label and all */
      :where(ui-autocomplete, [data-ui~="autocomplete"])
        [data-autocomplete-slot~="group"]:not(:has([data-autocomplete-slot~="item"]:not([hidden]))) {
        display: none;
      }
    
      :where(ui-autocomplete, [data-ui~="autocomplete"]) [data-autocomplete-slot~="empty"] {
        display: none;
        padding: calc(var(--spacing) * 2);
      }
    
      :where(ui-autocomplete, [data-ui~="autocomplete"])
        [data-autocomplete-slot~="panel"]:not(:has([data-autocomplete-slot~="item"]:not([hidden])))
        [data-autocomplete-slot~="empty"] {
        display: block;
      }
    }
    // primitives/menu/menu.js
    "use strict";
    /**
     * @fileoverview `<ui-menu>`: HTML web component for keyboard-enhanced menus.
     * @description Light-DOM custom element that augments the CSS-only menu
     * pattern (trigger + anchored `[data-menu-slot~="popover"]` panel) with
     * arrow-key navigation. The attribute form `[data-ui~="menu"]` stays fully functional
     * without JavaScript: the Popover API provides open/close, light dismiss,
     * and focus return on its own.
     *
     * Keyboard behavior:
     * - ArrowDown / ArrowUp on the closed trigger open the panel and focus the
     *   first / last item.
     * - ArrowDown / ArrowUp inside the open panel move focus between items,
     *   wrapping around and skipping disabled items.
     * - Home / End jump to the first / last item.
     * - Escape and light dismiss are native Popover API behavior (no code here).
     *
     * The menu keeps the honest disclosure posture: items are plain links and
     * buttons, and no `role="menu"` is claimed. Add the full ARIA menu contract
     * yourself only if every item is an action and you implement the rest of the
     * pattern (typeahead, close-on-activate).
     *
     * @example
     * <ui-menu>
     *   <button data-ui="button" type="button" popovertarget="m1">Open</button>
     *   <div id="m1" data-menu-slot="popover" popover="auto">
     *     <menu>
     *       <li><a href="/docs" data-ui="button" data-button-variant="ghost" style="--justify: start">Docs</a></li>
     *     </menu>
     *   </div>
     * </ui-menu>
     */
    import { ZazzElement, defineZazzElement } from "../../base/zazz-element.js";
    class UiMenu extends ZazzElement {
        setup(signal) {
            this.addEventListener("keydown", (event) => this.#onKeydown(event), { signal });
        }
        /**
         * @description The menu's own panel: a direct child so nested menus keep
         * their panels to themselves.
         *
         * @returns The panel element, or null when the markup is incomplete.
         */
        #panel() {
            const panel = this.querySelector(':scope > [data-menu-slot~="popover"]');
            return panel instanceof HTMLElement ? panel : null;
        }
        /**
         * @description Focusable items inside the panel, in DOM order.
         *
         * @param panel - The menu panel.
         * @returns Enabled links and buttons the arrow keys move between.
         */
        #items(panel) {
            return Array.from(panel.querySelectorAll("a[href], button"))
                .filter((node) => node instanceof HTMLElement)
                .filter((item) => !item.hasAttribute("disabled") &&
                item.getAttribute("aria-disabled") !== "true" &&
                item.closest('ui-menu, [data-ui~="menu"]') === this);
        }
        /**
         * @description Routes arrow-key, Home, and End presses: opens the panel from
         * the trigger, or moves focus between items inside the open panel.
         *
         * @param event - The keydown event.
         */
        #onKeydown(event) {
            if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key))
                return;
            const target = event.target;
            if (!(target instanceof HTMLElement))
                return;
            // Ignore keys that belong to a nested ui-menu
            if (target.closest('ui-menu, [data-ui~="menu"]') !== this)
                return;
            const panel = this.#panel();
            if (!panel)
                return;
            const isTrigger = target.parentElement === this &&
                (target.hasAttribute("popovertarget") || target.hasAttribute("interestfor"));
            const open = panel.matches(":popover-open");
            if (isTrigger && !open && (event.key === "ArrowDown" || event.key === "ArrowUp")) {
                event.preventDefault();
                panel.showPopover();
                const items = this.#items(panel);
                items[event.key === "ArrowDown" ? 0 : items.length - 1]?.focus();
                return;
            }
            if (!open || !panel.contains(target))
                return;
            const items = this.#items(panel);
            if (items.length === 0)
                return;
            const index = items.indexOf(target);
            let nextIndex;
            switch (event.key) {
                case "ArrowDown":
                    nextIndex = index === -1 ? 0 : (index + 1) % items.length;
                    break;
                case "ArrowUp":
                    nextIndex = index === -1 ? items.length - 1 : (index - 1 + items.length) % items.length;
                    break;
                case "Home":
                    nextIndex = 0;
                    break;
                case "End":
                    nextIndex = items.length - 1;
                    break;
                default:
                    return;
            }
            event.preventDefault();
            items[nextIndex].focus();
        }
    }
    defineZazzElement("ui-menu", UiMenu);
    export { UiMenu };
    
    // primitives/select/multiselect.js
    "use strict";
    /**
     * @fileoverview `<ui-multiselect>`: a multi-select styled as a dropdown.
     * @description Light-DOM custom element that progressively enhances a real
     * `<select multiple data-ui="select">`. `appearance: base-select` does not
     * apply to multi-selects in stable engines, so the script hides the
     * select (which remains the form value carrier and source of truth) and
     * stamps a `[data-ui~="select"]`-look trigger button plus an anchored popover of
     * checkbox rows projected from the options. Checkbox changes write back to
     * `option.selected` and re-dispatch `change` on the select; external writes
     * and form resets flow the other way. Without JavaScript the native
     * multi-select listbox renders: fully functional and accessible.
     *
     * The trigger reads `<first selection> (+N more)`.
     *
     * Attributes on `<ui-multiselect>`:
     * - `data-multiselect-placeholder`: trigger text when nothing is selected.
     * - `data-multiselect-label-more`: overflow template, default `"(+{n} more)"`.
     * - `data-multiselect-side` / `data-multiselect-align`: forwarded to the stamped panel as `data-popover-*` (popover
     *   placement matrix).
     *
     * Stamped parts: `multiselect-trigger` (a `[data-ui~="select"]`-identity button),
     * `multiselect-icon` (chevron), `multiselect-panel` (`[popover]`),
     * `multiselect-option` (label + checkbox per option).
     */
    import { ZazzElement, defineZazzElement } from "../../base/zazz-element.js";
    import { effect, state } from "../../base/signals.js";
    /**
     * @description Formats the trigger label from the selected option labels.
     *
     * @param labels - Labels of the selected options, in DOM order.
     * @param placeholder - Text for an empty selection.
     * @param moreTemplate - Overflow template; `{n}` is the remaining count.
     * @returns The trigger text.
     */
    function resolveTriggerLabel(labels, placeholder, moreTemplate) {
        if (labels.length === 0)
            return placeholder;
        if (labels.length === 1)
            return labels[0];
        return `${labels[0]} ${moreTemplate.replace("{n}", String(labels.length - 1))}`;
    }
    let multiselectIdCounter = 0;
    class UiMultiselect extends ZazzElement {
        #stamped = [];
        #select = null;
        setup(signal) {
            const select = this.querySelector("select[multiple]");
            if (!(select instanceof HTMLSelectElement))
                return;
            this.#select = select;
            const placeholder = this.getAttribute("data-multiselect-placeholder") ?? "Select…";
            const moreTemplate = this.getAttribute("data-multiselect-label-more") ?? "(+{n} more)";
            const { trigger, label, panel, checkboxes } = this.#stamp(select);
            select.setAttribute("data-multiselect-state", "enhanced");
            const selectedLabels = () => Array.from(select.selectedOptions).map((option) => option.label);
            const selection = state(selectedLabels());
            // Checkbox → option: the select stays the source of truth
            checkboxes.forEach((checkbox, index) => {
                checkbox.addEventListener("change", () => {
                    const option = select.options[index];
                    if (option)
                        option.selected = checkbox.checked;
                    selection.set(selectedLabels());
                    select.dispatchEvent(new Event("change", { bubbles: true }));
                }, { signal });
            });
            // External writes and form resets → re-read (reset applies after the event)
            select.addEventListener("change", () => selection.set(selectedLabels()), { signal });
            select.form?.addEventListener("reset", () => queueMicrotask(() => selection.set(selectedLabels())), { signal });
            // Mirror popover open state onto the trigger's aria-expanded
            panel.addEventListener("toggle", (event) => {
                trigger.setAttribute("aria-expanded", String(event.newState === "open"));
            }, { signal });
            // Output adapter: trigger label + row checked states together
            effect(() => {
                selection.get();
                label.textContent = resolveTriggerLabel(selectedLabels(), placeholder, moreTemplate);
                checkboxes.forEach((checkbox, index) => {
                    const option = select.options[index];
                    if (option && checkbox.checked !== option.selected)
                        checkbox.checked = option.selected;
                });
            }, { signal });
        }
        teardown() {
            for (const node of this.#stamped)
                node.remove();
            this.#stamped = [];
            this.#select?.removeAttribute("data-multiselect-state");
            this.#select = null;
        }
        /**
         * @description Builds the trigger button and checkbox panel from the
         * select's options and inserts them after it.
         *
         * @param select - The enhanced select.
         * @returns The stamped parts and the checkbox list (option order).
         * @private
         */
        #stamp(select) {
            const panelId = `ui-multiselect-panel-${++multiselectIdCounter}`;
            const trigger = document.createElement("button");
            trigger.type = "button";
            trigger.dataset.ui = "select";
            trigger.setAttribute("data-multiselect-slot", "trigger");
            trigger.setAttribute("popovertarget", panelId);
            trigger.setAttribute("aria-expanded", "false");
            const label = document.createElement("span");
            label.setAttribute("data-multiselect-slot", "label");
            const icon = document.createElement("span");
            icon.setAttribute("data-multiselect-slot", "icon");
            icon.setAttribute("aria-hidden", "true");
            trigger.append(label, icon);
            const panel = document.createElement("div");
            panel.id = panelId;
            panel.setAttribute("data-multiselect-slot", "panel");
            panel.setAttribute("popover", "auto");
            const side = this.getAttribute("data-multiselect-side");
            const align = this.getAttribute("data-multiselect-align");
            if (side)
                panel.setAttribute("data-popover-side", side);
            if (align)
                panel.setAttribute("data-popover-align", align);
            const checkboxes = [];
            for (const [index, option] of Array.from(select.options).entries()) {
                const row = document.createElement("label");
                row.setAttribute("data-multiselect-slot", "option");
                const checkbox = document.createElement("input");
                checkbox.type = "checkbox";
                // an id, not a name: the select submits, and Chrome flags a field with neither
                checkbox.id = `${panelId}-${index}`;
                checkbox.checked = option.selected;
                checkbox.disabled = option.disabled;
                row.append(checkbox, document.createTextNode(option.label));
                panel.append(row);
                checkboxes.push(checkbox);
            }
            select.after(trigger, panel);
            this.#stamped = [trigger, panel];
            return { trigger, label, panel, checkboxes };
        }
    }
    defineZazzElement("ui-multiselect", UiMultiselect);
    export { UiMultiselect, resolveTriggerLabel };
    
    // primitives/autocomplete/autocomplete.js
    "use strict";
    /**
     * @fileoverview `<ui-autocomplete>`: an input that suggests options as you type.
     * @description Light-DOM custom element on the shared typeahead engine
     * (`base/typeahead.ts`). The visible input is the form value (free text is
     * allowed) and the anchored `popover="manual"` panel suggests matches ranked
     * by the vendored cmdk scorer. Committing a suggestion (Enter or click) fills
     * the input; without JavaScript the markup degrades to a plain `[data-ui~="input"]`.
     *
     * Attributes on the root:
     * - `data-autocomplete-sort="score"`: re-rank visually by match score (default: DOM order).
     * - `data-autocomplete-filter="none"`: show every item; another source filters.
     * - `data-autocomplete-min-length="<n>"`: query length before the panel opens (default 0).
     *
     * Parts: `autocomplete-panel` (popover="manual"), `autocomplete-list`
     * ([role="listbox"]), `autocomplete-item` ([role="option"], `data-autocomplete-value`,
     * optional `data-autocomplete-keywords`), `autocomplete-group` / `autocomplete-group-label`,
     * `autocomplete-empty`.
     */
    import { TypeaheadElement } from "../../base/typeahead.js";
    import { defineZazzElement } from "../../base/zazz-element.js";
    class UiAutocomplete extends TypeaheadElement {
        slotPrefix = "autocomplete";
        /**
         * @description Committing a suggestion fills the visible input (which is
         * the form value), closes the panel, and returns to typing position.
         *
         * @param item - The committed option.
         */
        commit(item, _source) {
            const input = this.searchInput;
            if (!input)
                return;
            input.value = this.itemValue(item);
            this.query.set(input.value);
            this.open.set(false);
            input.focus();
            input.dispatchEvent(new Event("change", { bubbles: true }));
        }
    }
    defineZazzElement("ui-autocomplete", UiAutocomplete);
    export { UiAutocomplete };

    Behavior

    primitives/autocomplete/autocomplete.js

    <ui-autocomplete>: an input that suggests options as you type. Light-DOM custom element on the shared typeahead engine (base/typeahead.ts). The visible input is the form value (free text is allowed) and the anchored popover="manual" panel suggests matches ranked by the vendored cmdk scorer. Committing a suggestion (Enter or click) fills the input; without JavaScript the markup degrades to a plain [data-ui~="input"].

    Attributes on the root:

    • data-autocomplete-sort="score": re-rank visually by match score (default: DOM order).
    • data-autocomplete-filter="none": show every item; another source filters.
    • data-autocomplete-min-length="<n>": query length before the panel opens (default 0).

    Parts: autocomplete-panel (popover="manual"), autocomplete-list ([role="listbox"]), autocomplete-item ([role="option"], data-autocomplete-value, optional data-autocomplete-keywords), autocomplete-group / autocomplete-group-label, autocomplete-empty.

    Attributes

    autocomplete attributes
    AttributeKindValuesNotes
    data-ui="autocomplete"Identityfree valueIdentity token in data-ui.
    <ui-autocomplete>Tag formfree valueTag form; styled and, when scripted, registered under this name.
    data-autocomplete-slotSlotempty group group-label item list panelSlot: a part inside the primitive.
    data-autocomplete-stateStatehighlightedState the kit's script writes; read it in selectors, never author it.
    data-autocomplete-filterConfigfree valueConfiguration the kit's script reads.
    data-autocomplete-keywordsConfigfree valueConfiguration the kit's script reads.
    data-autocomplete-min-lengthConfigfree valueConfiguration the kit's script reads.
    data-autocomplete-sortConfigfree valueConfiguration the kit's script reads.
    data-autocomplete-valueConfigfree valueConfiguration the kit's script reads.

    Requires: popover, button, fields, select, input.

    Hooks

    Set a hook on :root, on a subtree, or inline on one element. A state hook (--…--hover) themes that state only; the primitive keeps its other states.

    autocomplete hooks
    HookDefaultState
    --ui-autocomplete-panel-max-hcalc(var(--spacing) * 72)—
    --ui-autocomplete-shadowvar(--ui-menu-shadow)—

    API