Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(a11y): add aria label to icon button #756

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/calendar/icon-button.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<button
type="button"
:aria-label="ariaLabel"
:disabled="disabled"
:class="[
`${prefixClass}-btn ${prefixClass}-btn-text ${prefixClass}-btn-icon-${type}`,
Expand All @@ -17,6 +18,7 @@
<script>
export default {
props: {
ariaLabel: String,
type: String,
disabled: Boolean,
},
Expand Down
27 changes: 17 additions & 10 deletions src/calendar/table-date.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@
<div :class="`${prefixClass}-calendar-header`">
<icon-button
type="double-left"
:aria-label="locale.prevYear"
:disabled="isDisabledArrows('last-year')"
@click="handleIconDoubleLeftClick"
></icon-button>
<icon-button
type="left"
:aria-label="locale.prevMonth"
:disabled="isDisabledArrows('last-month')"
@click="handleIconLeftClick"
></icon-button>
<icon-button
type="double-right"
:disabled="isDisabledArrows('next-year')"
@click="handleIconDoubleRightClick"
></icon-button>
<icon-button
type="right"
:disabled="isDisabledArrows('next-month')"
@click="handleIconRightClick"
></icon-button>
<span :class="`${prefixClass}-calendar-header-label`">
<button
v-for="item in yearMonth"
Expand All @@ -34,6 +26,18 @@
{{ item.label }}
</button>
</span>
<icon-button
type="right"
:aria-label="locale.nextMonth"
:disabled="isDisabledArrows('next-month')"
@click="handleIconRightClick"
></icon-button>
<icon-button
type="double-right"
:aria-label="locale.nextYear"
:disabled="isDisabledArrows('next-year')"
@click="handleIconDoubleRightClick"
></icon-button>
</div>
<div :class="`${prefixClass}-calendar-content`">
<table :class="`${prefixClass}-table ${prefixClass}-table-date`">
Expand Down Expand Up @@ -159,6 +163,9 @@ export default {
});
return chunk(arr, 7);
},
locale() {
return this.getLocale();
},
},
methods: {
isDisabledArrows(type) {
Expand Down
15 changes: 10 additions & 5 deletions src/calendar/table-month.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
<div :class="`${prefixClass}-calendar-header`">
<icon-button
type="double-left"
:aria-label="locale.prev"
:disabled="isDisabledArrows('last-year')"
@click="handleIconDoubleLeftClick"
></icon-button>
<icon-button
type="double-right"
:disabled="isDisabledArrows('next-year')"
@click="handleIconDoubleRightClick"
></icon-button>
<span :class="`${prefixClass}-calendar-header-label`">
<button
type="button"
Expand All @@ -20,6 +16,12 @@
{{ calendarYear }}
</button>
</span>
<icon-button
type="double-right"
:aria-label="locale.next"
:disabled="isDisabledArrows('next-year')"
@click="handleIconDoubleRightClick"
></icon-button>
</div>
<div :class="`${prefixClass}-calendar-content`">
<table :class="`${prefixClass}-table ${prefixClass}-table-month`" @click="handleClick">
Expand Down Expand Up @@ -82,6 +84,9 @@ export default {
});
return chunk(months, 3);
},
locale() {
return this.getLocale();
},
},
methods: {
isDisabledArrows(type) {
Expand Down
19 changes: 14 additions & 5 deletions src/calendar/table-year.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
<div :class="`${prefixClass}-calendar-header`">
<icon-button
type="double-left"
:aria-label="locale.prev"
:disabled="isDisabledArrows('last-decade')"
@click="handleIconDoubleLeftClick"
></icon-button>
<icon-button
type="double-right"
:disabled="isDisabledArrows('next-decade')"
@click="handleIconDoubleRightClick"
></icon-button>
<span :class="`${prefixClass}-calendar-header-label`">
<span>{{ firstYear }}</span>
<span :class="`${prefixClass}-calendar-decade-separator`"></span>
<span>{{ lastYear }}</span>
</span>
<icon-button
type="double-right"
:aria-label="locale.next"
:disabled="isDisabledArrows('next-decade')"
@click="handleIconDoubleRightClick"
></icon-button>
</div>
<div :class="`${prefixClass}-calendar-content`">
<table :class="`${prefixClass}-table ${prefixClass}-table-year`" @click="handleClick">
Expand All @@ -39,11 +41,15 @@
import IconButton from './icon-button';
import { chunk } from '../util/base';
import { setYear } from '../util/date';
import { getLocale } from '../locale';

export default {
name: 'TableYear',
components: { IconButton },
inject: {
getLocale: {
default: () => getLocale,
},
prefixClass: {
default: 'mx',
},
Expand Down Expand Up @@ -80,6 +86,9 @@ export default {
const last = arr => arr[arr.length - 1];
return last(last(this.years));
},
locale() {
return this.getLocale();
},
},
methods: {
isDisabledArrows(type) {
Expand Down
6 changes: 6 additions & 0 deletions src/locale/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const lang = {
yearFormat: 'YYYY',
monthFormat: 'MMM',
monthBeforeYear: true,
next: 'Next Page',
prev: 'Previous Page',
nextYear: 'Next Year',
prevMonth: 'Previous Month',
nextMonth: 'Next Month',
prevYear: 'Previous Year',
};

export default lang;
14 changes: 5 additions & 9 deletions src/style/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,8 @@
line-height: 34px;
text-align: center;
overflow: hidden;
}

.#{$namespace}-btn-icon-left,
.#{$namespace}-btn-icon-double-left {
float: left;
}
.#{$namespace}-btn-icon-right,
.#{$namespace}-btn-icon-double-right {
float: right;
display: flex;
justify-content: space-between;
}

.#{$namespace}-calendar-header-label {
Expand Down Expand Up @@ -200,6 +193,9 @@
color: $disabled-color;
background-color: $disabled-background-color;
}
&.focus {
outline: -webkit-focus-ring-color auto 1px;
}
}
}

Expand Down