Advanced Multiple Custom Select
Custom select with advanced structure options and where multiple options can be selected.
Projects /
Custom select with advanced structure options and where multiple options can be selected.
The Advanced Multiple Custom Select component is used to overwrite the multiple (native) select appearance and replace it with a custom list of selectable options.
The custom list structure can be customized by modifying the content of the .js-adv-multi-select__list
element.
The basic list structure (.js-adv-multi-select__list
content) is:
<div role="group" describedby="optgroup-label">
<!-- label -->
<div class="adv-multi-select__label js-adv-multi-select__label" id="optgroup-label">{optgroup-label}</div>
<!-- option -->
<div class="adv-multi-select__option js-adv-multi-select__option" role="option">{option-label}</div>
</div>
where:
.adv-multi-select__label
is the label of the <optgroup>
element; {optgroup-label}
will be replaced by the <optgroup>
label attribute;.adv-multi-select__option
is the option element; {option-label}
will be replaced by the <option>
label.The template used for the option elements can be customized based on your project needs. For example, if you want to include an image next to the option text, modify the template as follows:
<div role="group" describedby="optgroup-label">
<!-- label -->
<div class="adv-multi-select__label js-adv-multi-select__label" id="optgroup-label">{optgroup-label}</div>
<!-- option -->
<div class="adv-multi-select__option js-adv-multi-select__option" role="option">
<img src="{img-src}" alt="{img-alt}">
<span>{option-label}</span>
</div>
</div>
To each <option>
in the native <select>
element, make sure to add a data-img-src
and data-img-alt
to pass the image src and alt attribute respectively:
<select multiple>
<optgroup label="Group 1">
<option value="1" data-img-src="image-1.png" data-img-alt="Image 1 Description">Option 1</option>
<option value="2" data-img-src="image-2.png" data-img-alt="Image 2 Description">Option 2</option>
<option value="2" data-img-src="image-3.png" data-img-alt="Image 3 Description">Option 3</option>
</optgroup>
</select>
The basic dropdown list (.js-adv-multi-select__list
content) is:
<div class="adv-multi-select__option js-adv-multi-select__option" role="option">{option-label}</div>
You can customize this template (see <select> with <optgroup> elements section).
Optionally, you can include a reset button to deselect all the options. To do so, add the .js-advm-select-reset-btn
class to the button and make sure the aria-controls value of the button is equal to the id value of the <select>
element.
The component behaves differently depending on wheter the user is on a touch device or not.
If the user is on a touch device:
If the user isn't on a touch device:
By default, the custom select is a block element and occupies the parent's full width. If you set the display property equal to inline-block, the width depends on the longest select option.
<div class="advm-select inline-block js-advm-select">
<!-- ... -->
</div>