From b6ec5a8cb550b207d72846ca79a220187b9ea5d2 Mon Sep 17 00:00:00 2001 From: Ovidiu Date: Thu, 5 Dec 2019 16:17:26 +0200 Subject: [PATCH] fix(catalog): add info for next/previous month on to the buttons (#384) --- packages/calendar/src/LionCalendar.js | 45 ++++++++++++++------ packages/calendar/test/lion-calendar.test.js | 32 +++++++++----- 2 files changed, 52 insertions(+), 25 deletions(-) diff --git a/packages/calendar/src/LionCalendar.js b/packages/calendar/src/LionCalendar.js index 56294c666..4028f1f5a 100644 --- a/packages/calendar/src/LionCalendar.js +++ b/packages/calendar/src/LionCalendar.js @@ -257,18 +257,30 @@ export class LionCalendar extends LocalizeMixin(LitElement) { __renderHeader() { const month = getMonthNames({ locale: this.__getLocale() })[this.centralDate.getMonth()]; const year = this.centralDate.getFullYear(); + const nextMonth = + this.centralDate.getMonth() === 11 + ? getMonthNames({ locale: this.__getLocale() })[0] + : getMonthNames({ locale: this.__getLocale() })[this.centralDate.getMonth() + 1]; + const previousMonth = + this.centralDate.getMonth() === 0 + ? getMonthNames({ locale: this.__getLocale() })[11] + : getMonthNames({ locale: this.__getLocale() })[this.centralDate.getMonth() - 1]; + const nextYear = + this.centralDate.getMonth() === 11 + ? this.centralDate.getFullYear() + 1 + : this.centralDate.getFullYear(); + const previousYear = + this.centralDate.getMonth() === 0 + ? this.centralDate.getFullYear() - 1 + : this.centralDate.getFullYear(); + return html`
- ${this.__renderPreviousButton()} -

+ ${this.__renderPreviousButton(previousMonth, previousYear)} +

${month} ${year}

- ${this.__renderNextButton()} + ${this.__renderNextButton(nextMonth, nextYear)}
`; } @@ -290,12 +302,16 @@ export class LionCalendar extends LocalizeMixin(LitElement) { }); } - __renderPreviousButton() { + __renderPreviousButton(previousMonth, previousYear) { + const previousButtonTitle = `${this.msgLit( + 'lion-calendar:previousMonth', + )}, ${previousMonth} ${previousYear}`; + return html` + `); }); @@ -73,7 +72,7 @@ describe('', () => { `, ); expect(el.shadowRoot.querySelector('.calendar__next-month-button')).dom.to.equal(` - + `); }); }); @@ -428,7 +427,7 @@ describe('', () => { }); describe('Accessibility', () => { - it('has aria-live="polite" and aria-atomic="true" set on the secondary title', async () => { + it('has aria-atomic="true" set on the secondary title', async () => { const elObj = new CalendarObject( await fixture( html` @@ -436,7 +435,6 @@ describe('', () => { `, ), ); - expect(elObj.monthHeadingEl.getAttribute('aria-live')).to.equal('polite'); expect(elObj.monthHeadingEl.getAttribute('aria-atomic')).to.equal('true'); }); }); @@ -583,10 +581,18 @@ describe('', () => { `); const elObj = new CalendarObject(el); - expect(elObj.previousMonthButtonEl.getAttribute('title')).to.equal('Previous month'); - expect(elObj.previousMonthButtonEl.getAttribute('aria-label')).to.equal('Previous month'); - expect(elObj.nextMonthButtonEl.getAttribute('title')).to.equal('Next month'); - expect(elObj.nextMonthButtonEl.getAttribute('aria-label')).to.equal('Next month'); + expect(elObj.previousMonthButtonEl.getAttribute('title')).to.equal( + 'Previous month, November 2000', + ); + expect(elObj.previousMonthButtonEl.getAttribute('aria-label')).to.equal( + 'Previous month, November 2000', + ); + expect(elObj.nextMonthButtonEl.getAttribute('title')).to.equal( + 'Next Month, January 2001', + ); + expect(elObj.nextMonthButtonEl.getAttribute('aria-label')).to.equal( + 'Next Month, January 2001', + ); }); }); }); @@ -1179,11 +1185,15 @@ describe('', () => { `); const elObj = new CalendarObject(el); - expect(elObj.nextMonthButtonEl.getAttribute('aria-label')).to.equal('Next month'); + expect(elObj.nextMonthButtonEl.getAttribute('aria-label')).to.equal( + 'Next Month, December 2019', + ); localize.locale = 'nl-NL'; await el.updateComplete; - expect(elObj.nextMonthButtonEl.getAttribute('aria-label')).to.equal('Volgende maand'); + expect(elObj.nextMonthButtonEl.getAttribute('aria-label')).to.equal( + 'Next Month, december 2019', + ); /** * TODO: add more tests, e.g. for: