From 363a80b18430aed6ce02b696d984ae9e2305b2ed Mon Sep 17 00:00:00 2001 From: maranran Date: Wed, 8 Nov 2017 21:21:20 -0600 Subject: [PATCH] Accessibility for Popover, Tooltip, Message & Notification (#8009) * Accessibility for Tooltip & Popover * Accessibility for message & notification * fixbug for popover with nodeType --- examples/docs/zh-CN/popover.md | 2 +- examples/docs/zh-CN/tooltip.md | 2 +- packages/message/src/main.vue | 47 ++++++++++---------------- packages/notification/src/main.vue | 21 ++++++++++-- packages/popover/src/main.vue | 45 +++++++++++++++++++++++-- packages/theme-chalk/src/tooltip.scss | 3 ++ packages/tooltip/src/main.js | 48 ++++++++++++++++++++++----- 7 files changed, 123 insertions(+), 45 deletions(-) diff --git a/examples/docs/zh-CN/popover.md b/examples/docs/zh-CN/popover.md index 449874882..b3c52c3fa 100644 --- a/examples/docs/zh-CN/popover.md +++ b/examples/docs/zh-CN/popover.md @@ -146,7 +146,7 @@ Popover 的属性与 Tooltip 很类似,它们都是基于`Vue-popper`开发的 width="200" trigger="focus" content="这是一段内容,这是一段内容,这是一段内容,这是一段内容。"> - focus 激活 + focus 激活 ``` ::: diff --git a/examples/docs/zh-CN/tooltip.md b/examples/docs/zh-CN/tooltip.md index 07eb8d03f..83aeeba5b 100644 --- a/examples/docs/zh-CN/tooltip.md +++ b/examples/docs/zh-CN/tooltip.md @@ -63,7 +63,7 @@
- 上左 + 上左 上边 diff --git a/packages/message/src/main.vue b/packages/message/src/main.vue index 882b76f4d..c6f9956d8 100644 --- a/packages/message/src/main.vue +++ b/packages/message/src/main.vue @@ -9,15 +9,15 @@ v-show="visible" @mouseenter="clearTimer" @mouseleave="startTimer" - role="alertdialog" + role="alert" > -

{{ message }}

-

+

{{ message }}

+

- +
@@ -44,9 +44,7 @@ closed: false, timer: null, dangerouslyUseHTMLString: false, - center: false, - initFocus: null, - originFocus: null + center: false }; }, @@ -87,18 +85,18 @@ if (typeof this.onClose === 'function') { this.onClose(this); } - if (!this.originFocus || !this.originFocus.getBoundingClientRect) return; - - // restore keyboard focus - const { top, left, bottom, right } = this.originFocus.getBoundingClientRect(); - const viewportHeight = window.innerHeight || document.documentElement.clientHeight; - const viewportWidth = window.innerWidth || document.documentElement.clientWidth; - if (top >= 0 && - left >= 0 && - bottom <= viewportHeight && - right <= viewportWidth) { - this.originFocus.focus(); - } +// if (!this.originFocus || !this.originFocus.getBoundingClientRect) return; +// +// // restore keyboard focus +// const { top, left, bottom, right } = this.originFocus.getBoundingClientRect(); +// const viewportHeight = window.innerHeight || document.documentElement.clientHeight; +// const viewportWidth = window.innerWidth || document.documentElement.clientWidth; +// if (top >= 0 && +// left >= 0 && +// bottom <= viewportHeight && +// right <= viewportWidth) { +// this.originFocus.focus(); +// } }, clearTimer() { @@ -115,24 +113,15 @@ } }, keydown(e) { - if (e.keyCode === 46 || e.keyCode === 8) { - this.clearTimer(); // detele 取消倒计时 - } else if (e.keyCode === 27) { // esc关闭消息 + if (e.keyCode === 27) { // esc关闭消息 if (!this.closed) { this.close(); } - } else { - this.startTimer(); // 恢复倒计时 } } }, mounted() { this.startTimer(); - this.originFocus = document.activeElement; - this.initFocus = this.showClose ? this.$el.querySelector('.el-icon-close') : this.$el.querySelector('.el-message__content'); - setTimeout(() => { - this.initFocus && this.initFocus.focus(); - }); document.addEventListener('keydown', this.keydown); }, beforeDestroy() { diff --git a/packages/notification/src/main.vue b/packages/notification/src/main.vue index 4b98c1244..ee47e46be 100644 --- a/packages/notification/src/main.vue +++ b/packages/notification/src/main.vue @@ -6,7 +6,9 @@ :style="positionStyle" @mouseenter="clearTimer()" @mouseleave="startTimer()" - @click="click"> + @click="click" + role="alert" + > 0) { this.timer = setTimeout(() => { @@ -130,6 +142,11 @@ } }, this.duration); } + document.addEventListener('keydown', this.keydown); + }, + beforeDestroy() { + document.removeEventListener('keydown', this.keydown); } }; + diff --git a/packages/popover/src/main.vue b/packages/popover/src/main.vue index 88ff571a3..3e498336d 100644 --- a/packages/popover/src/main.vue +++ b/packages/popover/src/main.vue @@ -6,7 +6,11 @@ :class="[popperClass, content && 'el-popover--plain']" ref="popper" v-show="!disabled && showPopper" - :style="{ width: width + 'px' }"> + :style="{ width: width + 'px' }" + role="tooltip" + :id="tooltipId" + :aria-hidden="(disabled || !showPopper) ? 'true' : 'false'" + >
{{ content }}
@@ -14,10 +18,10 @@ -