Skip to content

Searchable select (combobox) in WordPress

A keyboard-filterable dropdown to pick one or several values, shown as chips, backed by a real select field.

Here is an excerpt of this component's code in WordPress. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in WordPress

champ-selection-combobox.php
<?php
/**
 * Plugin Name: Forge, Sélecteur avec recherche (combobox)
 * Description: Une liste déroulante filtrable au clavier pour choisir une ou plusieurs valeurs, affichées en pastilles, adossée à un vrai champ select. Ajoute la composition « Sélecteur avec recherche (combobox) » à l'éditeur de blocs.
 * Version: 1.0.0
 * Requires at least: 6.6
 * Requires PHP: 8.1
 * Author: Forge
 * License: GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: forge-champ-selection-combobox
 *
pattern.html
<!-- wp:group {"tagName": "section", "className": "cbx-card", "layout": {"type": "default"}} -->
<section class="wp-block-group cbx-card"><!-- wp:group {"className": "cbx-head", "layout": {"type": "default"}} -->
<div class="wp-block-group cbx-head"><!-- wp:heading {"level": 2, "anchor": "cbx-titre"} -->
<h2 class="wp-block-heading" id="cbx-titre">Votre activité</h2>
<!-- /wp:heading -->
<!-- wp:paragraph {"className": "cbx-intro"} -->
<p class="cbx-intro">Ces informations apparaissent sur votre fiche artisan et servent à vous proposer les bons chantiers.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->
<!-- wp:html -->
<div class="cbx-field" data-cbx>
        <div class="cbx-native" data-cbx-native>
script.js
(() => {
  if (!document.querySelector(".cbx-card")) return;
  document.querySelectorAll("[data-cbx]").forEach((root) => {
    const select = root.querySelector("select");
    const ui = root.querySelector("[data-cbx-ui]");
    const input = ui.querySelector("[role=combobox]");
    const toggle = ui.querySelector("[data-cbx-toggle]");
    const popup = ui.querySelector("[data-cbx-popup]");
    const empty = ui.querySelector("[data-cbx-empty]");
    const status = ui.querySelector("[data-cbx-status]");
    const chips = ui.querySelector("[data-cbx-chips]");
    const counter = ui.querySelector("[data-cbx-count]");
style.css
:root {
  --cbx-text: #1e1b2e;
  --cbx-muted: #57536b;
  --cbx-card: #ffffff;
  --cbx-line: #e4dff2;
  --cbx-border: #8a83a3;
  --cbx-field: #ffffff;
  --cbx-accent: #6d28d9;
  --cbx-chip-bg: #ede9fe;
  --cbx-chip-text: #4c1d95;
  --cbx-chip-hover: #ddd6fe;
  --cbx-hover: #f3effe;

Free component: copy it freely, including for commercial projects.

Forms and inputs components in WordPress
  • A quote request form for tradespeople: the customer describes the work, picks a start date range and attaches up to six site photos, each with a preview, its size and a button to remove it.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A quote request form whose labels, hints and error messages are full French sentences, still readable at 320 px: nothing overflows, nothing is cut off, and each error is tied to its field.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Visitors pick a package and tick options: the pre-tax total, VAT and total including tax update live, and the summary is sent with the contact form.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A short NPS survey: a 0 to 10 score as radio buttons, then a follow-up question adapted to whether the customer is a detractor, passive or promoter.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • An honest unsubscribe page: address prefilled from the link, choice between stopping everything or receiving less, optional reason and an undo.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A callback request form: French phone number checked and formatted, topic, working day and time slot, with explicit consent to the call.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component