如何解决对于可访问的自定义下拉列表,为什么某些键不起作用?
-
如何添加到我目前必须在导航到某个项目后使用 Enter 键选择项目的辅助功能?
-
如何确保退出键关闭菜单?
-
箭头键不允许导航,只有 Tab 键似乎可以工作。
除了这些部分,一切似乎都在工作。
for (const dropdown of document.querySelectorAll(".custom__select-wrapper:not(.clearFilter)")) {
dropdown.addEventListener("click",function () {
this.querySelector(".custom__select").classList.toggle("open");
});
}
for (const option of document.querySelectorAll(".custom__option")) {
option.addEventListener("click",function () {
if (!this.classList.contains("selected")) {
this.parentNode
.querySelector(".custom__option.selected")
.classList.remove("selected");
this.classList.add("selected");
this.closest(".custom__select").querySelector(
".custom__select-trigger h6"
).textContent = this.textContent;
if (this.getAttribute("data-type")) {
current_story = this.dataset["type"];
storyFilter(this.dataset["type"]);
}
}
});
}
window.addEventListener("click",function (e) {
for (const select of document.querySelectorAll(".custom__select")) {
if (!select.contains(e.target)) {
select.classList.remove("open");
}
}
});
button.clear {
border: 0;
background: #fff;
}
#selectedFilter {
color: #005fec;
}
ul {
padding-left: 0;
margin: 0;
}
.filter {
padding-right: 15px;
padding-left: 15px;
margin-bottom: 2rem;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
}
@media (min-width: 768px) {
.filter__settings {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
border-top: 1px solid #E0E5EC;
border-bottom: 1px solid #E0E5EC;
}
}
.custom__select {
position: relative;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
}
@media (min-width: 768px) {
.custom::before,.custom__options {
-webkit-transition: all .2s ease-in;
transition: all .2s ease-in;
}
}
.custom__select-wrapper {
position: relative;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
padding: 0;
border-bottom: 1px solid #E0E5EC;
}
.custom__select-wrapper:last-child {
border: 0;
}
.custom__select-wrapper.clearFilter {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
.custom__select-wrapper .selected-clearFilter {
position: relative;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
padding: 1rem 0 !important;
}
@media (min-width: 768px) {
.custom__select-wrapper {
padding: 0 2em;
border: 0;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.custom__select-wrapper:first-child,.custom__select-wrapper:last-child {
padding: 0;
}
}
.custom__select-wrapper h6 {
padding: 20px 3px;
color: #62668C;
font-weight: 300;
}
.custom__select-trigger {
position: relative;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
cursor: pointer;
}
@media (min-width: 768px) {
.custom__select-trigger {
-webkit-box-pack: space-evenly;
-ms-flex-pack: space-evenly;
justify-content: space-evenly;
margin-right: auto;
}
}
.custom__select-wrapper h6,.custom__select-trigger h6 {
font-size: .75rem;
line-height: .75rem;
letter-spacing: 1px;
text-transform: uppercase;
padding: 20px 0;
}
.custom__select-trigger h6 {
color: #005fec;
font-weight: 900;
}
.custom__select-wrapper #selectedFilter {
font-size: 12px;
line-height: 12px;
letter-spacing: 1px;
text-transform: uppercase;
color: #005fec;
font-weight: 800;
padding: 0;
}
.custom__options {
top: 100%;
left: 0;
right: 0;
border-top: 0;
opacity: 0;
visibility: hidden;
pointer-events: none;
z-index: 2;
color: #E0E5EC;
}
@media (min-width: 768px) {
.custom__options {
position: absolute;
background-color: #005fec;
max-height: 320px;
overflow-y: scroll;
}
.custom__options#storyFilter {
overflow: hidden;
}
}
.custom__options.active {
display: block;
visibility: visible;
opacity: 1;
z-index: 10;
}
.custom__select-trigger,.custom__option {
letter-spacing: 1px;
font-weight: 800;
color: #005fec;
border: 0;
background: transparent;
}
.custom__select.open::before {
content: "";
position: absolute;
bottom: 0;
left: 11px;
border-left: 11px solid transparent;
border-right: 11px solid transparent;
border-bottom: 11px solid #005fec;
}
.custom__select .custom__options {
min-width: 15rem;
}
.custom__select.open .custom__options {
opacity: 1;
visibility: visible;
pointer-events: all;
color: #fff;
min-width: 15rem;
}
@media (min-width: 768px) {
.custom__select.open .custom__options {
-webkit-box-shadow: 0px 12px 30px rgba(0,0.12);
box-shadow: 0px 12px 30px rgba(0,0.12);
}
}
.custom__option {
position: relative;
display: block;
padding: 0 22px 0 12px;
font-weight: 400;
color: #62668C;
cursor: pointer;
font-size: 1rem;
line-height: 1rem;
margin: 1.5rem 0;
}
@media (min-width: 768px) {
.custom__option {
font-size: 1.25rem;
line-height: 1.25rem;
color: white;
font-weight: 300;
padding: 0 22px 0 20px;
}
}
.custom__option:hover {
cursor: pointer;
}
.custom__option.selected {
color: #005fec;
}
@media (min-width: 768px) {
.custom__option.selected {
color: #ffffff;
}
}
.custom__option.selected::before {
content: "•";
margin-left: -12px;
padding-right: 8px;
}
.empty-state {
width: 100%;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
background: #005fec;
padding: 1rem;
border-radius: 4px;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
margin: 2rem .5rem;
}
.empty-state h4 {
color: white;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 300;
margin-left: .5rem;
}
.empty-state h4 span {
color: white;
text-decoration: underline;
cursor: pointer;
}
.arrow {
position: relative;
height: 5px;
width: 3px;
margin-left: .5rem;
margin-bottom: .1rem;
}
.arrow::before,.arrow::after {
content: "";
position: absolute;
bottom: 0px;
width: 0.1rem;
height: 100%;
-webkit-transition: all 0.45s;
transition: all 0.45s;
}
.arrow::before {
left: 0px;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
background-color: #005fec;
}
@media (min-width: 768px) {
.arrow::before {
left: 7px;
}
}
.arrow::after {
left: -2.5px;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
background-color: #005fec;
}
@media (min-width: 768px) {
.arrow::after {
left: 4.5px;
}
}
.open .arrow::before {
left: 0px;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
}
@media (min-width: 768px) {
.open .arrow::before {
left: 7px;
}
}
.open .arrow::after {
left: -2.5px;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
@media (min-width: 768px) {
.open .arrow::after {
left: 4.5px;
}
}
<div class="container">
<section class="filter">
<div class="filter__settings">
<div class="custom__select-wrapper">
<h6>filter by</h6>
</div>
<div class="custom__select-wrapper">
<div class="custom__select story-sel selector">
<button type="button" class="custom__select-trigger" aria-haspopup="listbox" aria-labelledby="storySelection" id="storySelector">
<h6>Story Type</h6>
<div class="arrow"></div>
</button>
<ul class="custom__options dropdown story-selector" id="storyFilter" tabindex="-1" role="listbox" aria-labelledby="storySelection">
<li class="custom__option selected" role="option" tabindex="0" data-type="all" id="storyItem_all">All</li>
<li class="custom__option" role="option" tabindex="0" data-type="news" id="storyItem_nm">News and media
</li>
<li class="custom__option" role="option" tabindex="0" data-type="analysis" id="storyItem_analysis">
Analysis</li>
<li class="custom__option" role="option" tabindex="0" data-type="press" id="storyItem_pr">Press releases
</li>
</ul>
</div>
</div>
<div class="custom__select-wrapper">
<div class="custom__select year-sel selector">
<button type="button" class="custom__select-trigger" aria-haspopup="listbox" aria-labelledby="yearSelection" id="yearSelector">
<h6>Year</h6>
<div class=" arrow"></div>
</button>
<ul class="custom__options dropdown year-selector" tabindex="-1" role="listbox" aria-labelledby="yearSelection">
<li class="custom__option selected" role="option" tabindex="0" data-year="all">All</li>
<li class="custom__option" role="option" tabindex="0" data-year="2021">2021</li>
<li class="custom__option" role="option" tabindex="0" data-year="2020">2020</li>
<li class="custom__option" role="option" tabindex="0" data-year="2019">2019</li>
<li class="custom__option" role="option" tabindex="0" data-year="2018">2018</li>
<li class="custom__option" role="option" tabindex="0" data-year="2017">2017</li>
<li class="custom__option" role="option" tabindex="0" data-year="2016">2016</li>
<li class="custom__option" role="option" tabindex="0" data-year="2015">2015</li>
<li class="custom__option" role="option" tabindex="0" data-year="2014">2014</li>
<li class="custom__option" role="option" tabindex="0" data-year="2013">2013</li>
<li class="custom__option" role="option" tabindex="0" data-year="2012">2012</li>
<li class="custom__option" role="option" tabindex="0" data-year="2011">2011</li>
<li class="custom__option" role="option" tabindex="0" data-year="2010">2010</li>
<li class="custom__option" role="option" tabindex="0" data-year="2009">2009</li>
<li class="custom__option" role="option" tabindex="0" data-year="2008">2008</li>
<li class="custom__option" role="option" tabindex="0" data-year="2007">2007</li>
<li class="custom__option" role="option" tabindex="0" data-year="2006">2006</li>
</ul>
</div>
</div>
</div>
</section>
</div>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。