Client - make language dropdown keyboard-navigable

This commit is contained in:
Sam 2023-07-12 19:53:37 +02:00
parent 3b59c4599f
commit 4b3270f546
2 changed files with 54 additions and 39 deletions

View File

@ -1,15 +1,21 @@
<template> <template>
<div class="dropdown-wrapper"> <div class="dropdown-wrapper">
<div class="dropdown-selected" @click="toggleDropdown"> <button
:aria-expanded="isOpen"
class="dropdown-selector transparent"
@click="toggleDropdown"
>
<slot></slot> <slot></slot>
</div> </button>
<ul class="dropdown-list" v-if="isOpen"> <ul class="dropdown-list" v-if="isOpen">
<li <li
class="dropdown-item" class="dropdown-item"
:class="{ selected: option.value === selected }" :class="{ selected: option.value === selected }"
v-for="(option, index) in dropdownOptions" v-for="(option, index) in dropdownOptions"
:key="index" :key="index"
tabindex="0"
@click="updateSelected(option)" @click="updateSelected(option)"
@keydown.enter="updateSelected(option)"
> >
{{ option.label }} {{ option.label }}
</li> </li>
@ -51,36 +57,39 @@
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.dropdown-list { @import '~@/scss/vars.scss';
list-style-type: none; .dropdown-wrapper {
background-color: #ffffff; .dropdown-selector {
padding: 0 !important; margin: 0;
margin-top: 5px; padding: $default-padding * 0.5;
margin-left: -20px !important;
position: absolute;
text-align: left;
border: solid 1px lightgrey;
box-shadow: 2px 2px 5px lightgrey;
width: auto !important;
li {
padding: 3px 8px;
}
}
.dropdown-item {
cursor: pointer;
&.selected {
font-weight: bold;
} }
&.selected::after { .dropdown-list {
content: ' ✔'; list-style-type: none;
} background-color: #ffffff;
padding: 0 !important;
margin-top: 5px;
margin-left: -20px !important;
position: absolute;
text-align: left;
border: solid 1px lightgrey;
box-shadow: 2px 2px 5px lightgrey;
width: auto !important;
&:hover { .dropdown-item {
background-color: var(--dropdown-hover-color); padding: 3px 12px;
&.selected {
font-weight: bold;
}
&.selected::after {
content: ' ✔';
}
&:hover {
background-color: var(--dropdown-hover-color);
}
}
} }
} }
</style> </style>

View File

@ -175,6 +175,7 @@
font-size: 1.2em; font-size: 1.2em;
font-weight: bold; font-weight: bold;
margin-right: 10px; margin-right: 10px;
line-height: 1.6em;
} }
.fa { .fa {
@ -194,7 +195,7 @@
display: flex; display: flex;
flex: 1; flex: 1;
justify-content: space-between; justify-content: space-between;
line-height: 1.8em; line-height: 2em;
width: 100%; width: 100%;
.nav-items-close { .nav-items-close {
@ -213,11 +214,14 @@
} }
.nav-item { .nav-item {
padding: 0 10px; padding: 0 10px;
&.dropdown-wrapper {
::v-deep(.dropdown-list) { padding: 0;
z-index: 1000; margin-left: 2px;
margin-left: -160px !important; ::v-deep(.dropdown-list) {
width: 180px !important; z-index: 1000;
margin-left: -150px !important;
width: 180px !important;
}
} }
} }
@ -330,10 +334,12 @@
.nav-item { .nav-item {
padding: 7px 25px; padding: 7px 25px;
&.dropdown-wrapper {
::v-deep(.dropdown-list) { padding-left: 15px;
margin-left: initial !important; ::v-deep(.dropdown-list) {
width: auto !important; margin-left: initial !important;
width: auto !important;
}
} }
} }