Skip to main content

Select

Use cases:

  • Selecting from a list of options
  • Selecting multiple options
  • Sorting
  • Filtering

Example

SmallLarge

Declaration

<rapid-select>
<rapid-option value="s">Small</rapid-option>
<rapid-option value="l">Large</rapid-option>
</rapid-select>

Usage

@customElement({
name: 'my-element',
template: html`
<rapid-select @change=${(x, ctx) => x.selectChanged(ctx.event)}>
<rapid-option value="s">Small</rapid-option>
<rapid-option value="l">Large</rapid-option>
</rapid-select>
`,
})
export class MyElement extends GenesisElement {
selectChanged(e: Event) {
alert('Select Changed', e.target.value)
}
}

API

Property and attribute binding examples for Genesis Component syntax. Closing tag omitted.

NameTypeDescriptionExample
disabledbooleanSimilar to readonly, but with a blur on the component.
<rapid-select disabled>
formstringAssociates this component with a form. Form id needs to be passed. If no Id is provided, then it will be associated with the ancestor form.
<rapid-select form="sampleForm">
multiplebooleanEnables the user to select more than one option; this automatically opens the selection and removes the side arrow. Default: false
<rapid-select multiple>
namestringGives this component a name.
<rapid-select name="mySelect">
openbooleanDefines whether the list starts opened or not. Default: false
<rapid-select open>
positionstringPlaces the list above or below the component; can be above or below. Default: it will try to fit with the page.
<rapid-select position="below">
sizenumberDefines the display size of the list. For example, if you set size="2", then the list displays two items at a time for the user to scroll through; Default: it will try to fit with the page.
<rapid-select size=2>
valuestringSets a value for this component.
<rapid-select value="s">
note

If you set the size, the list is displayed by default (the user does not need to click to view it). This overrides any setting you make for open.

Option attributes

In order to use the component, you need to create a list of options for the user to select from. You create this list using <rapid-option>. You can define the following attributes for an <rapid-option>:

NameTypeDescription
disabledbooleanDisables an option so that the user cannot interact with it, but the option is still visible
selectedbooleanSelects the option, so it turns to the selected mode
valuestringThe value of the attribute
|

note
  • If you specify a selected or value to more than one option while multiple = false, then the component selects only the first in the rapid-option list

You can also use the repeat directive to create options dynamically in the code:

  const sampleSelectOptions = [
{label: 'Large', value: 'l'},
{label: 'Small', value: 's'},
]
import {html, repeat} from '@genesislcap/web-core';
html`
<rapid-select>
${repeat(
(x) => x.sampleSelectOptions,
html`
<rapid-option value="${(x) => x.value}">${(x) => x.label}</rapid-option>
`,
)}
</rapid-select>
`

Properties

This component doesn't have any properties which are not also controlled via attributes.

Slots

NameDescription
startContent which can be provided before the button content
endContent which can be provided after the button content
button-containerThe element representing the select button
selected-valueThe selected value
indicatorThe visual indicator for the expand/collapse state of the button

Parts

NameDescription
controlThe element representing the select invoking element
selected-valueThe element wrapping the selected value
indicatorThe element wrapping the visual indicator
listboxThe listbox element

Events fired

NameDescription
changeFires a custom 'change' event when the value updates
inputFires a custom 'input' event when the value updates

Events listened to

This component doesn't listen to any events.

Further details

This component is an implementation of a HTML select element.