交互键盘

One thing that inevitably makes its way into our QA process on any project is the unexpected appearance of focus rings.

在任何项目中都不可避免地进入质量检查流程的一件事是聚焦环的意外出现。

We’ve had a lot of discussions about how to handle these. The project manager and designer often suggest removing them. While that would be the easy solution, it would be a web design anti-pattern. Default focus rings are provided by all browsers so that keyboard users can determine which element is currently in focus. In fact, focus rings are required to meet accessibility standards:

关于如何处理这些问题,我们进行了很多讨论。 项目经理和设计师经常建议删除它们。 尽管这将是一个简单的解决方案,但它将是一个网页设计反模式 。 所有浏览器均提供默认的聚焦环,以便键盘用户可以确定当前处于焦点的元素。 实际上, 需要聚焦环才能达到可访问性标准

Any keyboard operable user interface has a mode of operation where the keyboard focus indicator is visible.

任何键盘可操作的用户界面都具有键盘焦点指示器可见的操作模式。

- W3 Web Content Accessibility Guidelines

-W3 Web内容可访问性指南

Even when we decide not to remove focus rings, designers are usually unhappy with the default styles. One question that came up recently is if focus ring styles are made for keyboard users to keep track of the focus on the page, why do they need to show up when I click on an element? Can we add focus rings for keyboard users only?

即使我们决定不移除对焦环,设计师通常也对默认样式不满意。 最近出现的一个问题是,是否为键盘用户设计了焦点环样式以跟踪页面上的焦点,为什么单击元素时他们需要显示? 我们可以仅为键盘用户添加对焦环吗?

The answer is yes! We can use the :focus-visible polyfill to add focus rings only when a user is navigating with a keyboard.

答案是肯定的! 仅当用户使用键盘导航时,才可以使用:focus-visible polyfill添加聚焦环。

如何使用:focus-visible polyfill (How to use the :focus-visible polyfill)

Here’s how you can implement the :focus-visible in your projects right now.

这是您现在:focus-visible在项目中实现:focus-visible

If you are using ES6 modules, install the polyfill via npm:npm install --save focus-visible

如果使用ES6模块,请通过npm install --save focus-visible polyfill: npm install --save focus-visible

Import the module into your main JavaScript file:

将模块导入到您的主JavaScript文件中:

import 'focus-visible';

When your page loads, your <body> will get a class of .js-focus-visible so you can conditionally hide default focus rings only if the polyfill is loaded. Additionally, when you are navigating via keyboard, focused elements will get a class of .focus-visible.

当页面加载时,您的<body>将获得一类.js-focus-visible因此,只有在加载了polyfill时,您才可以有条件地隐藏默认的聚焦环。 此外,当您通过键盘导航时,焦点元素将获得一类.focus-visible

Now we can add our css:

现在我们可以添加我们的css:

// override UA stylesheet, only when polyfill is loaded
.js-focus-visible :focus:not(.focus-visible) {outline-width: 0;
}// establish desired focus ring appearance for appropriate input modalities
.focus-visible {outline: 2px solid $bright-brand-color;
}

其他资源 (Other Resources)

  • :focus-visible polyfill on Github

    :focus-visible Github上的:focus-visible polyfill

  • Focus-ring on A11y Casts

    聚焦于A11y演员表

  • The CSS Working Group focus-visible pseudo-class spec

    CSS工作组关注焦点的伪类规范

Want to dive deeper into building accessible websites? Join my free email course: ? Common accessibility mistakes and how to avoid them. 30 days, 10 lessons, 100% fun! ? Sign up here!

想更深入地建设可访问的网站吗? 加入我的免费电子邮件课程: 常见的可访问性错误以及如何避免它们 30天,10节课,100%的乐趣!在这里注册

This post originally appeared on benrobertson.io.

该帖子最初出现在benrobertson.io上 。

翻译自: https://www.freecodecamp.org/news/focus-rings-for-keyboard-interactions-only/

交互键盘

交互键盘_如何仅为键盘交互添加聚焦环相关推荐

  1. windows10添加键盘_如何在Windows中免费添加键盘并用您的语言书写

    windows10添加键盘 A lot of people don't realize that Windows supports a LOT of different languages out o ...

  2. 安卓如何调出软键盘_智能汽车到底如何交互?小鹏用全场景语音给出了答案

    车东西(公众号:chedongxi) 文 | 晓寒 智能汽车大潮汹涌而来. 新上市的车型,车内屏幕越来越大也越来越多.在特斯拉的带动下,中控台上的实体按键在最近几年迅速"被绞杀". ...

  3. vant 软键盘_移动端软键盘监听(弹出,收起),及影响定位布局的问题

    移动端软键盘监听(弹出,收起),及影响定位布局的问题 一:移动端软键盘监听(弹出,收起) 1.监听resize ( Android) var winHeight = $(window).height( ...

  4. java怎么编写软键盘_安卓手机软键盘操作

    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVIC ...

  5. axure键盘弹出_AxureRP实现键盘交互效果

    与键盘的交互一般都简化成输入内容,或者改为由鼠标来控制会比较多,因为B/S架构的系统或者网站其实不大需要跟键盘有交互,用鼠标就可以全部都实现了,这也是为了提升用户体验的满意度.不过现在网页游戏这么流行 ...

  6. carplay是否可以用安卓系统_是否可以仅用键盘来操作Windows 10系统和Windows 10应用?...

    一.问题的由来 1. 当时的情景: Windows 10系统上面的鼠标驱动存在问题,鼠标无法使用.我需要打开计算机管理中的设备管理器更新或者重新安装鼠标驱动. 2. 提出问题: 如何使用键盘来做这些操 ...

  7. 基于易语言的键盘监听器(仅供学习)

    基于易语言的键盘监听器(仅供学习) 软件原理 梳理 输入内容检测部分 发送部分 结束部分 准备工作 邮箱准备 支持库准备 模块准备 窗口准备 代码部分 程序集 启动窗口创建完毕 子程序1 编辑框1内容 ...

  8. 计算机键盘光标上下键失灵,键盘键位失灵_教你分析键盘失灵的原因及解决方案...

    摘要 腾兴网为您分享:教你分析键盘失灵的原因及解决方案,优美图,携程,明星衣橱,面包视频等软件知识,以及希沃轻白板,人人乐超市网上购物,微信群发软件,小雨音效,xl迅雷,叶子影视,韩剧直播,深入解析w ...

  9. hid自定义report 影响键盘_【iOS12人机交互指南】10.1-自定义键盘

    该系列是iOS12人机交互指南的翻译,翻译的过程中加深自己的理解. 键盘扩展用自定义键盘替换标准键盘.在"设置"应用中,在"常规>键盘"下启用自定义键盘. ...

最新文章

  1. android -各种适配器
  2. css实现图片动画效果
  3. 函数式编程语言python-函数式编程初探
  4. iOS- UITableView could not hold the selected row after reload
  5. Maximum Likelihood Method极大似然估计的朴素理解
  6. 《淘宝店铺 大数据营销+SEO+爆款打造 一册通》一一2.2 实时直播抢占生意先机...
  7. 16.1数组为什么特殊
  8. 学习Spring Boot:(五)使用 devtools热部署
  9. 18. javacript高级程序设计-JavaScript与XML
  10. [ZJOI 2012]灾难
  11. [debug] RuntimeError: “nll_loss_forward_reduce_cuda_kernel_2d_index“ not implemented for ‘Int‘
  12. php libiconv close_PHP 5.2.17 编译安装时出现 undefined reference to `libiconv_open’ 错误的解决方法...
  13. 【FPGA从0开始系列】黑金EP4CE10F17C8开发板按键实验(二)
  14. python 函数调用自身_Python-函数的递归调用
  15. 2020.12.10丨cufflinks 简介及使用说明
  16. 搜索算法之爬山法总结和实现
  17. 心理测量?预知犯罪?AI可以减少京都之殇吗?
  18. 盘符修改后,node重装一顿操作猛如虎
  19. ListView点击事件失效
  20. 太牛逼了,Python和算法简直是绝配

热门文章

  1. 【Python管理GPU】pynvml工具的安装与使用
  2. JVM——Java对象是如何创建、存储和访问的?
  3. 对象交互。英雄搏击游戏。0107
  4. python-模块-pymysql操作数据库
  5. jquery-ajax请求-1909
  6. Django 优秀资源大全项目资源非 Python 包工具贡献
  7. Sql server 数据转到 Mysql 数据库
  8. (7)Microsoft office Word 2013版本操作入门_常用技巧
  9. Java单链表、双端链表、有序链表实现
  10. 《Spark 官方文档》Spark配置(一)