对于可访问的自定义下拉列表,为什么某些键不起作用?

如何解决对于可访问的自定义下拉列表,为什么某些键不起作用?

  1. 如何添加到我目前必须在导航到某个项目后使用 Enter 键选择项目的辅助功能?

  2. 如何确保退出键关闭菜单?

  3. 箭头键不允许导航,只有 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 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-