<div class="dropdownContainer">
<button id="dropdownButton" class="dropdownButton" aria-haspopup="true" aria-expanded="false">
Select an option
<img src="/assets/example-content/downarrow.svg" alt="arrow" class="arrowIcon" id="dropdownArrow" />
</button>
<div id="dropdownList" class="dropdownList" style="display: none;">
<div class="dropdownItem" onclick="selectOption('Paris')">Paris</div>
<div class="dropdownItem" onclick="selectOption('London')">London</div>
<div class="dropdownItem" onclick="selectOption('Berlin')">Berlin</div>
<div class="dropdownItem" onclick="selectOption('Madrid')">Madrid</div>
</div>
</div>
No notes defined.
{
"dropdownOptions": [
"Paris",
"London",
"Berlin",
"Madrid"
]
}
/* stylelint-disable */
const dropdownButton = document.querySelector('#dropdownButton');
if (dropdownButton) {
const dropdownList = document.querySelector('#dropdownList');
const dropdownArrow = document.querySelector('#dropdownArrow');
const nextButton = document.querySelector('#nextButton');
const downArrowPath = '/assets/example-content/downarrow.svg';
dropdownButton.addEventListener('click', () => {
const isExpanded = dropdownButton.getAttribute('aria-expanded') === 'true';
dropdownButton.setAttribute('aria-expanded', !isExpanded);
// eslint-disable-next-line operator-linebreak
dropdownList.style.display = isExpanded ? 'none' : 'block';
});
// eslint-disable-next-line func-names
window.selectOption = function(option) {
dropdownButton.textContent = option;
dropdownButton.setAttribute('aria-expanded', 'false');
dropdownList.style.display = 'none';
nextButton.style.cursor = 'pointer';
nextButton.style.opacity = '1';
nextButton.disabled = false;
dropdownArrow.src = downArrowPath;
};
}
/* stylelint-disable */
.dropdownContainer {
position: relative;
width: 100%;
}
.dropdownButton {
width: 100%;
height: 48px;
padding: 12px;
gap: 10px;
border-radius: 2px;
border: 2px solid #AEBDE6;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
background-color: white;
font-size: 20px;
box-sizing: border-box;
color: #4F6074;
font-family: FS Dillon;
}
.arrowIcon {
width: 16px;
height: 16px;
margin-left: 100px;
}
.dropdownList {
position: absolute;
top: 100%;
left: 0;
width: 100%;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #fff;
box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.1);
z-index: 100;
max-height: 185px;
overflow: scroll;
&::-webkit-scrollbar {
width: 6px;
border-radius: 1rem;
}
&::-webkit-scrollbar-thumb {
background: #aebde6;
cursor: pointer;
border-radius: 1rem;
}
&::-webkit-scrollbar-track {
border-radius: 1rem;
}
}
.dropdownItem {
padding: 10px;
font-size: 18px;
cursor: pointer;
font-family: FS Dillon;
font-size: 20px;
font-weight: 400;
line-height: 24px;
text-align: left;
text-underline-position: from-font;
text-decoration-skip-ink: none;
}
.dropdownButton[aria-expanded="true"] .arrowIcon {
transform: rotate(180deg);
}
.dropdownButton[aria-expanded="false"] .arrowIcon {
transform: rotate(0deg);
}
/* stylelint-enable */
<div class="dropdownContainer">
<button id="dropdownButton" class="dropdownButton" aria-haspopup="true" aria-expanded="false">
{{#if dropdownButtonText}}{{dropdownButtonText}}{{else}}Select an option{{/if}}
<img src="/assets/example-content/downarrow.svg" alt="arrow" class="arrowIcon" id="dropdownArrow" />
</button>
<div id="dropdownList" class="dropdownList" style="display: none;">
{{#each dropdownOptions}}
<div class="dropdownItem" onclick="selectOption('{{this}}')">{{this}}</div>
{{/each}}
</div>
</div>