Select2
Overview
Select2 (v4.1.0-rc.0) replaces native <select> elements with a styled, accessible dropdown that supports search filtering and multi-select. It is initialized via the shared js/components/selects.js utility.
Standard usage
Wrap a native <select> in a .c-select container:
1<div class="c-select">
2 <select name="">
3
4 <option value=""></option>
5
6 </select>
7</div>The shared utility automatically initializes Select2 on all .c-select select elements when the page loads.
Variants
| Selector | Behavior | Notes |
|---|---|---|
.c-select select | Standard dropdown; search hidden | Default for all styled selects |
.event-form-select | Shows search field after 5 results | Event filter forms |
.mktoForm select | Auto-wrapped in .c-select on init | Marketo form fields; 1s timeout on init |
.c-lang-switcher select | Language switcher; no search | Uses custom .c-lang-switcher__dropdown CSS class |
.c-provider-finder__select select | Provider finder filter; no search | Provider search pages |
.c-provider-finder__select--treatment select | Multi-select with selection counter | Reads CYNO_DATA.filter_labels for i18n strings |
.c-provider-finder__select--product select | Multi-select with selection counter | Reads CYNO_DATA.filter_labels for i18n strings |
.c-select--treatment select | Footer multi-select with counter | Footer "Find a Provider" form |
.c-select--product select | Footer multi-select with counter | Footer "Find a Provider" form |
Importing the utility
In your block's script.js:
1/**
2 * CTA Provider Block
3 *
4 * Provider search form with filterable select dropdowns.
5 *
6 * @shared selects
7 * Trigger: .c-select select
8 * Behavior: Select2 styled dropdown; search hidden (minimumResultsForSearch: Infinity)
9 *
10 * @see /guidelines/javascript/selects
11 * @see /guidelines/javascript/shared-utilities
12 */
13import '../../js/components/selects.js';i18n strings
Multi-select variants use CYNO_DATA.filter_labels for user-facing strings. This object is injected by WordPress via wp_localize_script. Available keys:
1CYNO_DATA.filter_labels = {
2 any: "Any",
3 selected: "selected",
4 select_treatment_any: "Select treatment (any)",
5 select_product_any: "Select product (any)",
6};Accessibility notes
- Select2 generates ARIA attributes (
role="listbox",aria-selected,aria-activedescendant) automatically. - Keyboard navigation (arrow keys, Enter, Escape) is built in.
- Do not hide the native
<select>withdisplay: nonebefore Select2 initializes — Select2 handles this itself. - The
.c-select__dropdownCSS class is applied to the dropdown container to allow scoped styling.
Blocks that use selects.js
cta-provider, download, downloads-columns, downloads-list, downloads-split, events-upcoming-list-sidebar, footer, grid-three-column, grid-three-column-nav, hero-contact, hero-news, hero-search-provider, posts-latest
On This Page