From ac66215399954c972267b9d18bbd5aa5ef41a4c1 Mon Sep 17 00:00:00 2001 From: Sean Perkins Date: Tue, 28 Feb 2023 17:42:08 -0500 Subject: [PATCH] fix(datetime): aria-label for show/hide year picker (#26848) --- core/src/components/datetime/datetime.tsx | 32 ++++++++++-- .../datetime/test/a11y/datetime.spec.ts | 52 +++++++++++++++++++ 2 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 core/src/components/datetime/test/a11y/datetime.spec.ts diff --git a/core/src/components/datetime/datetime.tsx b/core/src/components/datetime/datetime.tsx index 0a00353220..12a8556a63 100644 --- a/core/src/components/datetime/datetime.tsx +++ b/core/src/components/datetime/datetime.tsx @@ -82,6 +82,7 @@ import { export class Datetime implements ComponentInterface { private inputId = `ion-dt-${datetimeIds++}`; private calendarBodyRef?: HTMLElement; + private monthYearToggleItemRef?: HTMLIonItemElement; private popoverRef?: HTMLIonPopoverElement; private clearFocusVisible?: () => void; private parsedMinuteValues?: number[]; @@ -1890,7 +1891,32 @@ export class Datetime implements ComponentInterface {
- this.toggleMonthAndYearView()}> + (this.monthYearToggleItemRef = el)} + button + aria-label="Show year picker" + detail={false} + lines="none" + onClick={() => { + this.toggleMonthAndYearView(); + /** + * TODO: FW-3547 + * + * Currently there is not a way to set the aria-label on the inner button + * on the `ion-item` and have it be reactive to changes. This is a workaround + * until we either refactor `ion-item` to a button or Stencil adds a way to + * have reactive props for built-in properties, such as `aria-label`. + */ + const { monthYearToggleItemRef } = this; + if (monthYearToggleItemRef) { + const btn = monthYearToggleItemRef.shadowRoot?.querySelector('.item-native'); + if (btn) { + const monthYearAriaLabel = this.showMonthAndYear ? 'Hide year picker' : 'Show year picker'; + btn.setAttribute('aria-label', monthYearAriaLabel); + } + } + }} + > {getMonthAndYear(this.locale, this.workingParts)} - this.prevMonth()}> + this.prevMonth()}> - this.nextMonth()}> + this.nextMonth()}>