Select
A field that opens a menu of options, for choosing one from a known list. For two to four options that should stay visible, use a segmented control instead. Filters with many options go in a select, with the current choice visible. Rules: UX Elements & Rules → Select, Input and Menu, and UX-33.
Add it to a page
Load the pinned file once in your Latitude Site or web page, then use the tag.
<script type="module" src="https://web-components.sites.latd.com/components/lat-select/0.1.0/lat-select.js"></script>The file is an ES module. It loads Lit, the design-system tokens and the Roobert stylesheet from this catalog once per page, however many components you use.
| Version | 0.1.0 |
|---|---|
| File | /components/lat-select/0.1.0/lat-select.js (2.5 KB gzipped) |
| SHA-256 | 321b2cce2b0bb4c54e3dcb523813ea6619c5c3e4d5d542bd785efe4138cbc854 |
The options are <lat-menu-item> rows; this file includes the menu, so it works alone.
Permutations
Placeholder, chosen and disabled
Dark
TV
Connected TV
YouTube
TikTok
Instagram
Last 7 days
Last 30 days
Last 90 days
All time
All viewers
Light
TV
Connected TV
YouTube
TikTok
Instagram
Last 7 days
Last 30 days
Last 90 days
All time
All viewers
<lat-select label="Channel" placeholder="Choose a channel">
<lat-menu-item value="tv">TV</lat-menu-item>
<lat-menu-item value="ctv">Connected TV</lat-menu-item>
<lat-menu-item value="youtube">YouTube</lat-menu-item>
<lat-menu-item value="tiktok">TikTok</lat-menu-item>
<lat-menu-item value="instagram">Instagram</lat-menu-item>
</lat-select>
<lat-select label="Date range" value="30d">
<lat-menu-item value="7d">Last 7 days</lat-menu-item>
<lat-menu-item value="30d">Last 30 days</lat-menu-item>
<lat-menu-item value="90d">Last 90 days</lat-menu-item>
<lat-menu-item value="all">All time</lat-menu-item>
</lat-select>
<lat-select label="Audience" placeholder="Choose an audience" disabled>
<lat-menu-item>All viewers</lat-menu-item>
</lat-select>Open list, shown in place
Dark
Last 7 days
Last 30 days
Last 90 days
All time
Light
Last 7 days
Last 30 days
Last 90 days
All time
<lat-menu inline listbox aria-label="Date range">
<lat-menu-item value="7d">Last 7 days</lat-menu-item>
<lat-menu-item value="30d" selected checked>Last 30 days</lat-menu-item>
<lat-menu-item value="90d">Last 90 days</lat-menu-item>
<lat-menu-item value="all">All time</lat-menu-item>
</lat-menu>Grouped options
Dark
18 to 24
25 to 34
35 to 54
55 and over
Light
18 to 24
25 to 34
35 to 54
55 and over
<lat-select label="Age group" placeholder="Everyone">
<lat-menu-item group="Younger"></lat-menu-item>
<lat-menu-item value="18-24">18 to 24</lat-menu-item>
<lat-menu-item value="25-34">25 to 34</lat-menu-item>
<lat-menu-item group="Older"></lat-menu-item>
<lat-menu-item value="35-54">35 to 54</lat-menu-item>
<lat-menu-item value="55+">55 and over</lat-menu-item>
</lat-select>In a form, with submit and reset
Dark
Light
<form style="display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px"
onsubmit="event.preventDefault(); this.querySelector('output').value = 'Submitted ' + new URLSearchParams(new FormData(this))"
onreset="this.querySelector('output').value = ''">
<lat-select label="Date range" name="range" value="30d">
<lat-menu-item value="7d">Last 7 days</lat-menu-item>
<lat-menu-item value="30d">Last 30 days</lat-menu-item>
<lat-menu-item value="90d">Last 90 days</lat-menu-item>
<lat-menu-item value="all">All time</lat-menu-item>
</lat-select>
<lat-select label="Sentiment" name="sentiment" placeholder="Any sentiment" required>
<lat-menu-item value="positive">Positive</lat-menu-item>
<lat-menu-item value="neutral">Neutral</lat-menu-item>
<lat-menu-item value="negative">Negative</lat-menu-item>
</lat-select>
<lat-button variant="primary" type="submit">Apply</lat-button>
<lat-button type="reset">Reset</lat-button>
<output></output>
</form>Keyboard
| Key | On the field | In the list |
|---|---|---|
| Enter, Space, Down, Up | Opens at the chosen option | Enter and Space choose; Down and Up move, wrapping |
| Home, End | Opens at the first or last option | First or last option |
| Letters | Opens at the first match | The next option starting with what was typed |
| Escape | Closes without changing, focus back on the field | |
| Tab | Chooses the focused option and moves on |
Attributes
| Attribute | Values | Notes |
|---|---|---|
label | text | The label above the field. Without it, give the select an aria-label. |
placeholder | text | Shown while nothing is chosen. |
value | an option's value | The chosen option. As an attribute it's also the value the form resets to; marking an option selected does the same. |
name | text | Submitted with the form as name=value. Nothing is submitted while empty. |
disabled | boolean | Also disabled inside a disabled <fieldset>. |
required | boolean | The form won't submit while nothing is chosen. |
open | boolean | Reflects whether the list is open. Use show() and hide() to change it. |
Events
| Event | Notes |
|---|---|
change, input | The user chose a different option. Read event.target.value. |