Skip to content
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
5 changes: 3 additions & 2 deletions core/src/components/datetime/datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,7 @@ export class Datetime implements ComponentInterface {

private renderCalendarHeader(mode: Mode) {
const { disabled } = this;
const monthAndYear = getMonthAndYear(this.locale, this.workingParts);
const expandedIcon = mode === 'ios' ? chevronDown : caretUpSharp;
const collapsedIcon = mode === 'ios' ? chevronForward : caretDownSharp;

Expand All @@ -2274,11 +2275,11 @@ export class Datetime implements ComponentInterface {
}}
part="month-year-button"
disabled={disabled}
aria-label={this.showMonthAndYear ? 'Hide year picker' : 'Show year picker'}
aria-label={`${monthAndYear}, ${this.showMonthAndYear ? 'Hide year picker' : 'Show year picker'}`}
onClick={() => this.toggleMonthAndYearView()}
>
<span id="toggle-wrapper">
{getMonthAndYear(this.locale, this.workingParts)}
{monthAndYear}
<ion-icon
aria-hidden="true"
icon={this.showMonthAndYear ? expandedIcon : collapsedIcon}
Expand Down
21 changes: 16 additions & 5 deletions core/src/components/datetime/test/a11y/datetime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ describe('datetime', () => {
beforeEach(async () => {
page = await newSpecPage({
components: [Datetime],
html: `<ion-datetime></ion-datetime>`,
html: `<ion-datetime locale="en-US" value="2022-02-22"></ion-datetime>`,
});
});

it('should have aria-label "Show year picker" when collapsed', async () => {
it('should include the visible month/year and show action when collapsed', async () => {
const datetime = page.body.querySelector('ion-datetime')!;
const monthYearToggleBtn = datetime.shadowRoot!.querySelector('.calendar-month-year .calendar-month-year-toggle');
const ariaLabel = monthYearToggleBtn!.getAttribute('aria-label');

expect(ariaLabel).toContain('Show year picker');
expect(ariaLabel).toBe('February 2022, Show year picker');
});

it('should have aria-label "Hide year picker" when expanded', async () => {
it('should include the visible month/year and hide action when expanded', async () => {
const datetime = page.body.querySelector('ion-datetime')!;
const monthYearToggleBtn = datetime.shadowRoot!.querySelector<HTMLButtonElement>(
'.calendar-month-year .calendar-month-year-toggle'
Expand All @@ -47,7 +47,18 @@ describe('datetime', () => {
);
const ariaLabel = monthYearToggleBtnAfter!.getAttribute('aria-label');

expect(ariaLabel).toContain('Hide year picker');
expect(ariaLabel).toBe('February 2022, Hide year picker');
});

it('should include the localized month/year when the locale changes', async () => {
const datetime = page.body.querySelector('ion-datetime')!;
datetime.locale = 'de-DE';

await page.waitForChanges();

const monthYearToggleBtn = datetime.shadowRoot!.querySelector('.calendar-month-year .calendar-month-year-toggle');

expect(monthYearToggleBtn!.getAttribute('aria-label')).toBe('Februar 2022, Show year picker');
});
});
});
Loading