Skip to content

Commit

Permalink
feat(date-picker): accessibility enhancements (#462)
Browse files Browse the repository at this point in the history
* feat(date-picker): accessibility enhancements

* fix(date-picker): remove default value of identifier prop

* test(date-picker): update visual snapshot
  • Loading branch information
nowseemee authored Jul 20, 2021
1 parent 7772dcd commit 117c4d7
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 28 deletions.
16 changes: 16 additions & 0 deletions packages/components/src/components/date-picker/date-picker.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ duet-date-picker .duet-date__toggle:active scale-icon-content-calendar {
color: var(--scl-color-primary-active);
}

@media screen and (forced-colors: active), (-ms-high-contrast: active) {
duet-date-picker .duet-date__toggle scale-icon-content-calendar {
color: var(--scl-color-white);
}
}

.scale-date-picker {
position: relative;
}
Expand Down Expand Up @@ -191,6 +197,10 @@ duet-date-picker .duet-date__input:focus::placeholder {
color: var(--scl-color-grey-20);
}

.scale-date-picker__popup-heading {
text-align: center;
padding-bottom: var(--scl-spacing-16);
}
/* Popover layout */

duet-date-picker .duet-date__dialog-content {
Expand Down Expand Up @@ -303,3 +313,9 @@ duet-date-picker .duet-date__day:hover::before {
background: transparent;
color: var(--scl-color-white);
}

@media (max-width: 35.9375em) and (orientation: landscape) {
duet-date-picker .duet-date__dialog-content {
zoom: 70%;
}
}
42 changes: 33 additions & 9 deletions packages/components/src/components/date-picker/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ export class DatePicker {
*/
@Prop() name: string = 'date';

/**
* Name of the date picker input.
*/
@Prop() popupTitle: string = 'Pick a date';

/**
* Adds a unique identifier for the date picker input. Use this instead of html `id` attribute.
*/
@Prop() identifier: string = '';
@Prop() identifier: string;

/**
* Makes the date picker input component disabled. This prevents users from being able to
Expand Down Expand Up @@ -158,6 +163,8 @@ export class DatePicker {
*/
@Event() scaleFocus: EventEmitter<DuetDatePickerFocusEvent>;

private helperTextId = `helper-message-${i}`;

/**
* Public methods API
*/
Expand Down Expand Up @@ -215,6 +222,30 @@ export class DatePicker {
if (input) {
input.addEventListener('keyup', this.handleKeyPress);
}

if (input && this.helperText) {
input.setAttribute('aria-describedby', this.helperTextId);
}

if (input && this.status === 'error') {
input.setAttribute('aria-invalid', 'true');
}

const dialog = this.hostElement.querySelector('.duet-date__dialog-content');
if (dialog) {
const heading = document.createElement('h2');
heading.className = 'scale-date-picker__popup-heading';
heading.innerHTML = this.popupTitle;
dialog.insertBefore(heading, dialog.firstChild);
}

const today = this.hostElement.querySelector(
'.duet-date__day.is-today span.duet-date__vhidden'
);

if (today) {
today.innerHTML = `${today.innerHTML}, today`;
}
}

connectedCallback() {
Expand All @@ -236,11 +267,6 @@ export class DatePicker {
}

render() {
const ariaInvalidAttr =
this.status === 'error' ? { 'aria-invalid': true } : {};
const helperTextId = `helper-message-${i}`;
const ariaDescribedByAttr = { 'aria-describedBy': helperTextId };

return (
<div
class={classNames(
Expand Down Expand Up @@ -282,13 +308,11 @@ export class DatePicker {
value={this.value}
// @ts-ignore
ref={(element) => (this.duetInput = element)}
{...ariaInvalidAttr}
{...(this.helperText ? ariaDescribedByAttr : {})}
></duet-date-picker>
{!!this.helperText && (
<div
class="date-picker__meta"
id={helperTextId}
id={this.helperTextId}
aria-live="polite"
aria-relevant="additions removals"
>
Expand Down
37 changes: 19 additions & 18 deletions packages/components/src/components/date-picker/readme.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ scale-nav-icon {
color: var(--color);
}

@media screen and (forced-colors: active), (-ms-high-contrast: active) {
.meta-navigation__item-link {
color: var(--scl-color-white);
}
}

.meta-navigation__item-link:hover {
color: var(--color-hover);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const Template = (args, { argTypes }) => ({
export const RangeTemplate = (args, { argTypes }) => ({
components: { ScaleDatePicker },
template: `
<div style="height: 380px; display: inline-flex;">
<div style="height: 380px;">
<scale-date-picker
ref="start"
identifier="start"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
:helper-text="helperText"
:status="status"
:size="size"
:popup-title="popupTitle"
@scaleChange="scaleChange"
@scaleFocus="scaleFocus"
@scaleBlur="scaleBlur"
Expand Down Expand Up @@ -44,6 +45,7 @@ export default {
status: { type: String },
disabled: { type: Boolean },
size: { type: String },
popupTitle: { type: String },
},
methods: {
scaleChange($event) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 117c4d7

Please sign in to comment.