Components · Form

Select

A select lets the user choose one option from a list. It looks and behaves like an input field, with a dropdown arrow. It opens the ECO Menu as its list.

How to add a select to a page. The files are components/css/select.css, components/css/menu.css and components/js/select-menu.js.

Basic Usage

Link the shared files once per page. Never copy the rules into a page.

StepWhat to do
1. Linkselect.css and menu.css in /components/css/, and /components/js/select-menu.js. Both templates already have them.
2. MarkupA form-field with a label, an input-wrap around a native select.form-select and the form-select-arrow span, and an optional form-helper message.
3. PlaceholderStart the options with <option value="" disabled selected hidden>.
4. SizeLarge is the default. Add form-select--sm and form-label--sm for Small, form-select--xs for XSmall (desktop only).
5. Keyboard focusAdd the keyboard script under CSS / Tailwind once per page.

Select

Copy the markup you need. Hover and focus come from :hover and keyboard focus; the [data-state] selectors in the CSS exist only so the documentation can force a state.


API

Classes

ClassUse
form-field, form-label, form-label--smThe column and the label.
input-wrapThe wrapper: focus ring, arrow and open menu.
form-select, --sm, --xsThe select. Large, Small, XSmall.
form-select--error, --successRed or green border.
form-select-arrowThe arrow icon, after the select inside the wrapper.
form-helper, --error, --success, --disabled, form-helper-iconThe message.

Things to know

  • select-menu.js opens the ECO Menu instead of the browser list. The select stays the form control: its value, label and disabled state do not change.
  • The Active border is read from the chosen option with :has(), so no script is needed.
  • Without select-menu.js the select works with the browser’s own list.
  • The [data-state] selectors do nothing outside the documentation pages.

CSS / Tailwind

The component is two CSS files and one script, shared by every page. Link them, never copy them. The code below is read from the files the page links, so it is always what you see.

CSS (components/css/select.css)
CSS for the menu (from eco-menu, plus the opening position)
JavaScript (components/js/select-menu.js: opens the menu from the select)
JavaScript (focus ring on keyboard only)