[Button] add accessibility (#6180)

* 	add accessibility for Alert、Button、 Breadcrumb、 Checkbox

* Update checkbox.md
pull/6325/head
maranran 2017-08-05 18:33:50 +08:00 committed by 杨奕
parent e294273c50
commit c20ff5e55c
8 changed files with 46 additions and 17 deletions

View File

@ -1,6 +1,11 @@
<template> <template>
<transition name="el-alert-fade"> <transition name="el-alert-fade">
<div class="el-alert" :class="[ typeClass ]" v-show="visible"> <div
class="el-alert"
:class="[ typeClass ]"
v-show="visible"
role="alert"
>
<i class="el-alert__icon" :class="[ iconClass, isBigIcon ]" v-if="showIcon"></i> <i class="el-alert__icon" :class="[ iconClass, isBigIcon ]" v-if="showIcon"></i>
<div class="el-alert__content"> <div class="el-alert__content">
<span class="el-alert__title" :class="[ isBoldTitle ]" v-if="title">{{ title }}</span> <span class="el-alert__title" :class="[ isBoldTitle ]" v-if="title">{{ title }}</span>

View File

@ -1,6 +1,6 @@
<template> <template>
<span class="el-breadcrumb__item"> <span class="el-breadcrumb__item">
<span class="el-breadcrumb__item__inner" ref="link"><slot></slot></span><span class="el-breadcrumb__separator">{{separator}}</span> <span class="el-breadcrumb__item__inner" ref="link" role="link"><slot></slot></span><span class="el-breadcrumb__separator" role="presentation">{{separator}}</span>
</span> </span>
</template> </template>
<script> <script>
@ -20,6 +20,7 @@
var self = this; var self = this;
if (this.to) { if (this.to) {
let link = this.$refs.link; let link = this.$refs.link;
link.setAttribute('role', 'link');
link.addEventListener('click', _ => { link.addEventListener('click', _ => {
let to = this.to; let to = this.to;
self.replace ? self.$router.replace(to) self.replace ? self.$router.replace(to)

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="el-breadcrumb"> <div class="el-breadcrumb" aria-label="Breadcrumb" role="navigation">
<slot></slot> <slot></slot>
</div> </div>
</template> </template>
@ -12,6 +12,10 @@
type: String, type: String,
default: '/' default: '/'
} }
},
mounted() {
const items = this.$el.querySelectorAll('.el-breadcrumb__item');
items[items.length - 1].setAttribute('aria-current', 'page');
} }
}; };
</script> </script>

View File

@ -1,7 +1,8 @@
<template> <template>
<button :disabled="disabled" class="el-button" <button
v-bind="$props"
class="el-button"
@click="handleClick" @click="handleClick"
:autofocus="autofocus"
:type="nativeType" :type="nativeType"
:class="[ :class="[
type ? 'el-button--' + type : '', type ? 'el-button--' + type : '',

View File

@ -7,6 +7,9 @@
{ 'is-checked': isChecked }, { 'is-checked': isChecked },
{ 'is-focus': focus }, { 'is-focus': focus },
]" ]"
role="checkbox"
:aria-checked="isChecked"
:aria-disabled="disabled"
> >
<input <input
v-if="trueLabel || falseLabel" v-if="trueLabel || falseLabel"

View File

@ -26,7 +26,7 @@
</script> </script>
<template> <template>
<div class="el-checkbox-group"> <div class="el-checkbox-group" role="group" aria-label="checkbox-group">
<slot></slot> <slot></slot>
</div> </div>
</template> </template>

View File

@ -1,5 +1,11 @@
<template> <template>
<label class="el-checkbox"> <label
class="el-checkbox"
role="checkbox"
:aria-checked="indeterminate ? 'mixed': isChecked"
:aria-disabled="disabled"
:id="id"
>
<span class="el-checkbox__input" <span class="el-checkbox__input"
:class="{ :class="{
'is-disabled': disabled, 'is-disabled': disabled,
@ -7,6 +13,7 @@
'is-indeterminate': indeterminate, 'is-indeterminate': indeterminate,
'is-focus': focus 'is-focus': focus
}" }"
aria-checked="mixed"
> >
<span class="el-checkbox__inner"></span> <span class="el-checkbox__inner"></span>
<input <input
@ -120,7 +127,9 @@
checked: Boolean, checked: Boolean,
name: String, name: String,
trueLabel: [String, Number], trueLabel: [String, Number],
falseLabel: [String, Number] falseLabel: [String, Number],
id: String, /* 当indeterminate为真时为controls提供相关连的checkbox的id表明元素间的控制关系*/
controls: String /* 当indeterminate为真时为controls提供相关连的checkbox的id表明元素间的控制关系*/
}, },
methods: { methods: {
@ -146,6 +155,11 @@
created() { created() {
this.checked && this.addToStore(); this.checked && this.addToStore();
},
mounted() { // indeterminate aria-controls
if (this.indeterminate) {
this.$el.setAttribute('aria-controls', this.controls);
}
} }
}; };
</script> </script>

View File

@ -70,9 +70,10 @@
} }
} }
} }
@when focus { @when focus { /*focus时 视觉上区分*/
.el-checkbox__inner { .el-checkbox__inner {
border-color: var(--checkbox-input-border-color-hover); border-color: var(--checkbox-input-border-color-hover);
box-shadow: 0 0 1px 0 var(--checkbox-input-border-color-hover);
} }
} }
@when indeterminate { @when indeterminate {
@ -192,7 +193,6 @@
outline: none; outline: none;
position: absolute; position: absolute;
margin: 0; margin: 0;
visibility: hidden;
left: -999px; left: -999px;
} }
@ -215,13 +215,6 @@
box-shadow: none; box-shadow: none;
} }
} }
&.is-focus {
& .el-checkbox-button__inner {
border-color: var(--checkbox-button-checked-border-color);
}
}
&:first-child { &:first-child {
.el-checkbox-button__inner { .el-checkbox-button__inner {
@ -230,6 +223,14 @@
box-shadow: none !important; box-shadow: none !important;
} }
} }
&.is-focus {
& .el-checkbox-button__inner {
border-color: var(--checkbox-button-checked-border-color);
box-shadow: 0 0 1px 0 var(--checkbox-button-checked-border-color) !important;
}
}
&:last-child { &:last-child {
.el-checkbox-button__inner { .el-checkbox-button__inner {
border-radius: 0 var(--border-radius-base) var(--border-radius-base) 0; border-radius: 0 var(--border-radius-base) var(--border-radius-base) 0;