GridSelectGridSelect
Guide
Reference
Demo
npm
GitHub
Guide
Reference
Demo
npm
GitHub
  • Options
  • Attributes and hooks
  • Instance and events
  • CSS variables
  • Changelog
  • Contributing

Options

This page lists every setting of GridSelect in one place. The guide explains the features in detail; here you find the exact names, values and defaults.

gridselect(wrapper, options?)

The function gridselect() sets up one group. Its first argument is the wrapper element that contains the group, its second, optional argument an object with options. It returns an instance, an object with the property value and the methods setItems() and destroy().

import { gridselect } from "@emmgeede/gridselect";

const gs = gridselect(document.querySelector("#currency"), { threshold: 5, search: "highlight" });

Calling gridselect() again on the same wrapper does not create a second instance. It returns the existing one and ignores the options of the later call; to change options, call gs.destroy() first and then gridselect() again.

The wrapper must contain either radio buttons that share one name, or checkboxes, or one <select>, or nothing at all when you pass items or load. GridSelect throws a TypeError if the first argument is not an element, if the wrapper mixes radio buttons and checkboxes, if its radio buttons have different names, or if it contains a <select> and other inputs at the same time. If two entries share a value, a warning appears in the browser console.

Options and data attributes

Most options can also be written as a data- attribute on the wrapper, which is convenient when the markup comes from a server or a template. If both are given, the option passed to gridselect() wins. An invalid value, such as an unknown layout name, is ignored, and the default applies.

Display

OptionAttributeDefaultWhat it does
thresholddata-threshold10The number of items up to which they stay visible on the page. With more items, GridSelect shows a field that opens a panel. 0 means the panel is always used. See How GridSelect works.
layoutdata-layout"grid"How the panel arranges the items: "grid" in columns as wide as the longest item, "list" one per row for long texts, "flow" one after another like words. See The panel.
panelWidthdata-panel-width"full""full" makes the panel as wide as the window, 10 pixels from each edge, and narrower when all items fit in one row. "fixed" uses the CSS variable --gs-panel-width, starting at the field's left edge.
panelContainerdata-panel-containernoneWith panelWidth: "full", keeps the panel inside the nearest ancestor whose data-gridselect-container has this name, between its inner edges. Without a matching ancestor the window's width applies.
sheetdata-sheet="off"trueOn phones (touch screens at most 640 pixels wide) the panel opens as a full-screen sheet with the group's name and a close button. false keeps the normal panel. See Phones and tablets.
closeText"Close"The accessible name of the close button that touch screens show in the panel.
panelHeightdata-panel-height"auto""auto" opens the panel where there is more room and lets it grow up to the window's edge, never beyond its content. "fixed" always opens below, with the list at most --gs-list-max-height high.
placeholder"Select…"The text in the field while nothing is chosen.
selectedTextn => n + " selected"A function that returns the field text when more than two entries are chosen in a multiple choice. One or two chosen entries show their labels.

Search

OptionAttributeDefaultWhat it does
searchdata-search"filter""filter" hides items that do not match. "highlight" keeps every item in place and marks the matches. See Search.
matchdata-match-mode"substring""substring" needs the typed text in the label as one piece. "fuzzy" lets the letters appear with gaps and the words in any order.
searchDescriptiondata-search-descriptionfalseWhen true, the search also looks at the items' descriptions; matches in the label still come first.
searchPlaceholder"Search…"The placeholder text of the search input.
noResultsText"No matches"The text shown and announced when nothing matches.
resultsTextn => n === 1 ? "1 result" : n + " results"A function that returns the screen reader announcement for a number of matches, so that plural rules of any language fit.

Keyboard

OptionAttributeDefaultWhat it does
shortcutsdata-shortcuts="off"["", "Shift", "Alt"]The modifier keys for the digit shortcuts, one entry per tier of ten items. An empty string stands for plain digits. false turns the digit shortcuts off. See Keyboard and digits.

Entries from JavaScript

OptionAttributeDefaultWhat it does
itemsAn array of entries for an empty wrapper: strings, numbers, objects with value, label, description and disabled, or groups { label, items }. GridSelect builds the inputs from them. See Sources.
nameThe form name of the inputs built from items. Without a name the inputs are not submitted.
valueThe initial choice for items; an array with multiple.
multiplefalseWhen true, items become checkboxes and several entries can be chosen.

Entries from a server

OptionAttributeDefaultWhat it does
loadA function (query, signal) => Promise<items> that returns the entries for the typed text. GridSelect calls it when the panel opens and 250 milliseconds after typing. See Entries from a server.
minQueryLength0The number of characters people must type before load is called.
minQueryTextn => "Type " + n + " characters to search"A function that returns the hint shown below minQueryLength.
loadingText"Loading…"The text shown and announced while a request runs.
errorText"Could not load entries"The text shown and announced when a request fails.

Multiple choice

OptionAttributeDefaultWhat it does
maxdata-maxnoneThe largest number of entries that can be chosen. At the limit the other entries are locked. See Multiple choice.
maxTextn => "Maximum of " + n + " reached"A function that returns the announcement when the limit is reached or hit.

Pinned and recent entries

OptionAttributeDefaultWhat it does
pinneddata-pinnednoneValues to show at the top of the panel, in this order. As an attribute, separate them with commas. See Pinned and recent entries.
recentdata-recentoffA storage key. When set, GridSelect remembers the last picks in the browser and shows them at the top.
recentMaxdata-recent-max5How many recent picks are kept and shown. 0 turns recent entries off.
pinnedText"Pinned"The heading of the pinned entries.
recentText"Recent"The heading of the recent entries.
Edit this page
Last Updated: 11/10/26, 4:41 PM
Contributors: Michael Grossklos, Claude Opus 5.5