Skip to content

Commit bfc21e3

Browse files
fix(a11y): add aria label to icon button
1 parent bb90ec8 commit bfc21e3

File tree

6 files changed

+54
-29
lines changed

6 files changed

+54
-29
lines changed

src/calendar/icon-button.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<button
33
type="button"
4+
:aria-label="ariaLabel"
45
:disabled="disabled"
56
:class="[
67
`${prefixClass}-btn ${prefixClass}-btn-text ${prefixClass}-btn-icon-${type}`,
@@ -17,6 +18,7 @@
1718
<script>
1819
export default {
1920
props: {
21+
ariaLabel: String,
2022
type: String,
2123
disabled: Boolean,
2224
},

src/calendar/table-date.vue

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,16 @@
33
<div :class="`${prefixClass}-calendar-header`">
44
<icon-button
55
type="double-left"
6+
:aria-label="locale.prevYear"
67
:disabled="isDisabledArrows('last-year')"
78
@click="handleIconDoubleLeftClick"
89
></icon-button>
910
<icon-button
1011
type="left"
12+
:aria-label="locale.prevMonth"
1113
:disabled="isDisabledArrows('last-month')"
1214
@click="handleIconLeftClick"
1315
></icon-button>
14-
<icon-button
15-
type="double-right"
16-
:disabled="isDisabledArrows('next-year')"
17-
@click="handleIconDoubleRightClick"
18-
></icon-button>
19-
<icon-button
20-
type="right"
21-
:disabled="isDisabledArrows('next-month')"
22-
@click="handleIconRightClick"
23-
></icon-button>
2416
<span :class="`${prefixClass}-calendar-header-label`">
2517
<button
2618
v-for="item in yearMonth"
@@ -34,6 +26,18 @@
3426
{{ item.label }}
3527
</button>
3628
</span>
29+
<icon-button
30+
type="right"
31+
:aria-label="locale.nextMonth"
32+
:disabled="isDisabledArrows('next-month')"
33+
@click="handleIconRightClick"
34+
></icon-button>
35+
<icon-button
36+
type="double-right"
37+
:aria-label="locale.nextYear"
38+
:disabled="isDisabledArrows('next-year')"
39+
@click="handleIconDoubleRightClick"
40+
></icon-button>
3741
</div>
3842
<div :class="`${prefixClass}-calendar-content`">
3943
<table :class="`${prefixClass}-table ${prefixClass}-table-date`">
@@ -159,6 +163,9 @@ export default {
159163
});
160164
return chunk(arr, 7);
161165
},
166+
locale() {
167+
return this.getLocale();
168+
},
162169
},
163170
methods: {
164171
isDisabledArrows(type) {

src/calendar/table-month.vue

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
<div :class="`${prefixClass}-calendar-header`">
44
<icon-button
55
type="double-left"
6+
:aria-label="locale.prev"
67
:disabled="isDisabledArrows('last-year')"
78
@click="handleIconDoubleLeftClick"
89
></icon-button>
9-
<icon-button
10-
type="double-right"
11-
:disabled="isDisabledArrows('next-year')"
12-
@click="handleIconDoubleRightClick"
13-
></icon-button>
1410
<span :class="`${prefixClass}-calendar-header-label`">
1511
<button
1612
type="button"
@@ -20,6 +16,12 @@
2016
{{ calendarYear }}
2117
</button>
2218
</span>
19+
<icon-button
20+
type="double-right"
21+
:aria-label="locale.next"
22+
:disabled="isDisabledArrows('next-year')"
23+
@click="handleIconDoubleRightClick"
24+
></icon-button>
2325
</div>
2426
<div :class="`${prefixClass}-calendar-content`">
2527
<table :class="`${prefixClass}-table ${prefixClass}-table-month`" @click="handleClick">
@@ -82,6 +84,9 @@ export default {
8284
});
8385
return chunk(months, 3);
8486
},
87+
locale() {
88+
return this.getLocale();
89+
},
8590
},
8691
methods: {
8792
isDisabledArrows(type) {

src/calendar/table-year.vue

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
<div :class="`${prefixClass}-calendar-header`">
44
<icon-button
55
type="double-left"
6+
:aria-label="locale.prev"
67
:disabled="isDisabledArrows('last-decade')"
78
@click="handleIconDoubleLeftClick"
89
></icon-button>
9-
<icon-button
10-
type="double-right"
11-
:disabled="isDisabledArrows('next-decade')"
12-
@click="handleIconDoubleRightClick"
13-
></icon-button>
1410
<span :class="`${prefixClass}-calendar-header-label`">
1511
<span>{{ firstYear }}</span>
1612
<span :class="`${prefixClass}-calendar-decade-separator`"></span>
1713
<span>{{ lastYear }}</span>
1814
</span>
15+
<icon-button
16+
type="double-right"
17+
:aria-label="locale.next"
18+
:disabled="isDisabledArrows('next-decade')"
19+
@click="handleIconDoubleRightClick"
20+
></icon-button>
1921
</div>
2022
<div :class="`${prefixClass}-calendar-content`">
2123
<table :class="`${prefixClass}-table ${prefixClass}-table-year`" @click="handleClick">
@@ -39,11 +41,15 @@
3941
import IconButton from './icon-button';
4042
import { chunk } from '../util/base';
4143
import { setYear } from '../util/date';
44+
import { getLocale } from '../locale';
4245
4346
export default {
4447
name: 'TableYear',
4548
components: { IconButton },
4649
inject: {
50+
getLocale: {
51+
default: () => getLocale,
52+
},
4753
prefixClass: {
4854
default: 'mx',
4955
},
@@ -80,6 +86,9 @@ export default {
8086
const last = arr => arr[arr.length - 1];
8187
return last(last(this.years));
8288
},
89+
locale() {
90+
return this.getLocale();
91+
},
8392
},
8493
methods: {
8594
isDisabledArrows(type) {

src/locale/en.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ const lang = {
55
yearFormat: 'YYYY',
66
monthFormat: 'MMM',
77
monthBeforeYear: true,
8+
next: 'Next Page',
9+
prev: 'Previous Page',
10+
nextYear: 'Next Year',
11+
prevMonth: 'Previous Month',
12+
nextMonth: 'Next Month',
13+
prevYear: 'Previous Year',
814
};
915

1016
export default lang;

src/style/index.scss

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,8 @@
154154
line-height: 34px;
155155
text-align: center;
156156
overflow: hidden;
157-
}
158-
159-
.#{$namespace}-btn-icon-left,
160-
.#{$namespace}-btn-icon-double-left {
161-
float: left;
162-
}
163-
.#{$namespace}-btn-icon-right,
164-
.#{$namespace}-btn-icon-double-right {
165-
float: right;
157+
display: flex;
158+
justify-content: space-between;
166159
}
167160

168161
.#{$namespace}-calendar-header-label {
@@ -200,6 +193,9 @@
200193
color: $disabled-color;
201194
background-color: $disabled-background-color;
202195
}
196+
&.focus {
197+
outline: -webkit-focus-ring-color auto 1px;
198+
}
203199
}
204200
}
205201

0 commit comments

Comments
 (0)