Skip to content

Aria attributes #86

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

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3a450d7
Change span to button to allow element to have focus
betweenbrain Feb 8, 2021
03fa142
Adds dynamic open/close datepicker aria-label
betweenbrain Feb 8, 2021
32939f3
Update test spec to not look for calendar button as a specific element
betweenbrain Feb 8, 2021
a1bfb61
Adds and implements button reset styles to maintain existing appearance
betweenbrain Feb 8, 2021
b9c542e
Set background to none to unset default styling
betweenbrain Feb 10, 2021
6c8b967
Use button instead of span
betweenbrain Feb 10, 2021
19e9616
Adds dynamic aria-label using LocaleDateString
betweenbrain Feb 10, 2021
f3ea70d
Use button instead of span, adds dynamic aria-label using LocaleDateS…
betweenbrain Feb 10, 2021
3c61064
Use month instead of day for parameter
betweenbrain Feb 10, 2021
1b586e9
Use button instead of span, adds dynamic aria-label using LocaleDateS…
betweenbrain Feb 10, 2021
ebf4fd2
Adds aria-expanded
betweenbrain Feb 10, 2021
d6c963e
Adds uid prop, consumed for aria-controls
betweenbrain Feb 10, 2021
dfee9a5
Fix uid prop type
betweenbrain Feb 10, 2021
9a81f79
Implements previous and next aria-labels
betweenbrain Feb 10, 2021
ce09c21
Code formatting
betweenbrain Feb 10, 2021
014b93a
Change prev and next buttons to buttons
betweenbrain Feb 10, 2021
19320e4
Use background transparent instead of none
betweenbrain Feb 10, 2021
1aacaee
Lint fixes
betweenbrain Feb 10, 2021
8c6e4e4
Lint fixes
betweenbrain Feb 10, 2021
e143b53
Adds format prop and formatDate method
betweenbrain Feb 23, 2021
f09273b
Add format argument to Datepicker
betweenbrain Feb 23, 2021
c21ccfc
Implement use of format for aria-label
betweenbrain Feb 23, 2021
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
11 changes: 9 additions & 2 deletions src/components/DateInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
<div :class="{ 'input-group': bootstrapStyling }">
<slot name="beforeDateInput" />
<!-- Calendar Button -->
<span
<button
v-if="calendarButton"
:aria-controls="`vdp-datepicker-${uid}`"
:aria-expanded="`${isOpen ? 'true' : 'false'}`"
:aria-label="`${isOpen ? 'Close' : 'Open'} Datepicker`"
:class="{
'input-group-prepend': bootstrapStyling,
'calendar-btn-disabled': disabled,
Expand All @@ -19,7 +22,7 @@
</i>
</slot>
</span>
</span>
</button>
<!-- Input -->
<input
:id="id"
Expand Down Expand Up @@ -87,6 +90,10 @@ export default {
return {}
},
},
uid: {
type: Number,
default: null,
},
},
data() {
const constructedDateUtils = makeDateUtils(this.useUtc)
Expand Down
3 changes: 3 additions & 0 deletions src/components/Datepicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
:tabindex="tabindex"
:translation="translation"
:typeable="typeable"
:uid="_uid"
:use-utc="useUtc"
@blur="onBlur"
@clear-date="clearDate"
Expand All @@ -52,6 +53,7 @@
>
<div
v-if="isOpen"
:id="`vdp-datepicker-${_uid}`"
ref="datepicker"
:class="pickerClasses"
@mousedown.prevent
Expand All @@ -64,6 +66,7 @@
:day-cell-content="dayCellContent"
:disabled-dates="disabledDates"
:first-day-of-week="firstDayOfWeek"
:format="format"
:highlighted="highlighted"
:is-rtl="isRtl"
:page-date="pageDate"
Expand Down
6 changes: 4 additions & 2 deletions src/components/PickerDay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:config="headerConfig"
:next="nextMonth"
:previous="previousMonth"
control-label="month"
>
<span
:class="allowedToShowView('month') ? 'up' : ''"
Expand All @@ -20,15 +21,16 @@
<span v-for="d in daysOfWeek" :key="d.timestamp" class="cell day-header">
{{ d }}
</span>
<span
<button
v-for="day in days"
:key="day.timestamp"
:aria-label="`Select ${formatDate(day)}`"
class="cell day"
:class="dayClasses(day)"
@click="selectDate(day)"
>
{{ dayCellContent(day) }}
</span>
</button>
</div>
<slot name="calendarFooterDay" />
</div>
Expand Down
14 changes: 10 additions & 4 deletions src/components/PickerHeader.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
<template>
<header v-if="config.showHeader">
<span
<button
class="prev"
:aria-label="`${config.isRtl ? 'next' : 'previous'} ${controlLabel}`"
:class="{ disabled: isLeftNavDisabled }"
@click="config.isRtl ? next() : previous()"
>
<slot name="prevIntervalBtn">
<span class="default">&lt;</span>
</slot>
</span>
</button>
<slot />
<span
<button
class="next"
:aria-label="`${config.isRtl ? 'previous' : 'next'} ${controlLabel}`"
:class="{ disabled: isRightNavDisabled }"
@click="config.isRtl ? previous() : next()"
>
<slot name="nextIntervalBtn">
<span class="default">&gt;</span>
</slot>
</span>
</button>
</header>
</template>

Expand All @@ -37,6 +39,10 @@ export default {
}
},
},
controlLabel: {
type: String,
default: null,
},
next: {
type: Function,
required: true,
Expand Down
6 changes: 4 additions & 2 deletions src/components/PickerMonth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:config="headerConfig"
:next="nextYear"
:previous="previousYear"
control-label="year"
>
<span
class="month__year_btn"
Expand All @@ -16,15 +17,16 @@
<slot slot="nextIntervalBtn" name="nextIntervalBtn" />
<slot slot="prevIntervalBtn" name="prevIntervalBtn" />
</PickerHeader>
<span
<button
v-for="month in months"
:key="month.timestamp"
:aria-label="`Select ${formatDate(month)}`"
:class="{ selected: month.isSelected, disabled: month.isDisabled }"
class="cell month"
@click.stop="selectMonth(month)"
>
{{ month.month }}
</span>
</button>
<slot name="calendarFooterMonth" />
</div>
</template>
Expand Down
6 changes: 4 additions & 2 deletions src/components/PickerYear.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:config="headerConfig"
:next="nextDecade"
:previous="previousDecade"
control-label="decade"
>
<span>
{{ pageTitleYear }}
Expand All @@ -13,15 +14,16 @@
<slot slot="prevIntervalBtn" name="prevIntervalBtn" />
</PickerHeader>

<span
<button
v-for="year in years"
:key="year.timestamp"
:aria-label="`Select ${formatDate(year)}`"
:class="{ selected: year.isSelected, disabled: year.isDisabled }"
class="cell year"
@click.stop="selectYear(year)"
>
{{ year.year }}
</span>
</button>
<slot name="calendarFooterYear" />
</div>
</template>
Expand Down
13 changes: 13 additions & 0 deletions src/mixins/pickerMixin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export default {
return {}
},
},
format: {
type: [String, Function],
default: 'dd MMM yyyy',
},
isRtl: {
type: Boolean,
default: false,
Expand Down Expand Up @@ -79,6 +83,15 @@ export default {
},
},
methods: {
formatDate(date) {
return typeof this.format === 'function'
? this.format(new Date(date.timestamp))
: this.utils.formatDate(
new Date(date.timestamp),
this.format,
this.translation,
)
},
/**
* Emit an event to show the month picker
*/
Expand Down
22 changes: 22 additions & 0 deletions src/styles/mixins.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@mixin button-reset {
background: transparent;
border: none;
margin: 0;
overflow: visible;
padding: 0;
width: auto;

/* Inherit font & color from ancestor */
color: inherit;
font: inherit;

/* Normalize `line-height`. Cannot be changed from `normal` in Firefox 4+. */
line-height: normal;

/* Corrects font smoothing for webkit */
-webkit-font-smoothing: inherit;
-moz-osx-font-smoothing: inherit;

/* Corrects inability to style clickable `input` types in iOS */
-webkit-appearance: none;
}
6 changes: 6 additions & 0 deletions src/styles/style.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "mixins";

.rtl {
direction: rtl;
}
Expand Down Expand Up @@ -44,6 +46,8 @@

.prev,
.next {
background: transparent;
border: none;
float: left;
max-height: 40px;
position: relative;
Expand Down Expand Up @@ -116,6 +120,7 @@
}

.cell {
background: transparent;
border: 1px solid transparent;
display: inline-block;
height: 40px;
Expand Down Expand Up @@ -196,6 +201,7 @@

.vdp-datepicker__clear-button,
.vdp-datepicker__calendar-button {
@include button-reset;
cursor: pointer;
font-style: normal;

Expand Down
6 changes: 3 additions & 3 deletions test/unit/specs/Datepicker/Datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('Datepicker mounted', () => {
calendarButton: true,
})

const calendarButton = wrapper.find('span.vdp-datepicker__calendar-button')
const calendarButton = wrapper.find('.vdp-datepicker__calendar-button')

await calendarButton.trigger('click')
expect(wrapper.vm.isOpen).toBeTruthy()
Expand All @@ -83,7 +83,7 @@ describe('Datepicker mounted', () => {
showCalendarOnFocus: true,
})

const calendarButton = wrapper.find('span.vdp-datepicker__calendar-button')
const calendarButton = wrapper.find('.vdp-datepicker__calendar-button')

await calendarButton.trigger('click')
expect(wrapper.vm.isOpen).toBeTruthy()
Expand All @@ -99,7 +99,7 @@ describe('Datepicker mounted', () => {
})

const input = wrapper.find('input')
const calendarButton = wrapper.find('span.vdp-datepicker__calendar-button')
const calendarButton = wrapper.find('.vdp-datepicker__calendar-button')

await input.trigger('focus')
expect(wrapper.vm.isOpen).toBeTruthy()
Expand Down