diff --git a/packages/date-picker/src/styles/vaadin-month-calendar-base-styles.js b/packages/date-picker/src/styles/vaadin-month-calendar-base-styles.js
index 39ed44d3b96..ecd18453d14 100644
--- a/packages/date-picker/src/styles/vaadin-month-calendar-base-styles.js
+++ b/packages/date-picker/src/styles/vaadin-month-calendar-base-styles.js
@@ -69,7 +69,8 @@ export const monthCalendarStyles = css`
[part~='weekday'],
[part~='week-number'],
- [part~='date'] {
+ [part~='date'],
+ [part~='date-button'] {
align-items: center;
display: flex;
justify-content: center;
@@ -81,7 +82,6 @@ export const monthCalendarStyles = css`
position: relative;
height: var(--vaadin-date-picker-date-height, 2rem);
cursor: var(--vaadin-clickable-cursor);
- outline: none;
}
[part~='date']:empty {
@@ -97,7 +97,13 @@ export const monthCalendarStyles = css`
aspect-ratio: 1;
}
- :where([part~='date']:focus-visible)::after {
+ [part~='date-button'] {
+ flex: 1;
+ align-self: stretch;
+ outline: none;
+ }
+
+ :where([part~='date']:has(:focus-visible))::after {
outline: var(--vaadin-focus-ring-width) solid var(--vaadin-focus-ring-color);
outline-offset: calc(var(--vaadin-focus-ring-width) * -1);
}
diff --git a/packages/date-picker/src/vaadin-date-picker-overlay-content-mixin.js b/packages/date-picker/src/vaadin-date-picker-overlay-content-mixin.js
index f97c2d30293..f5b72be3a6b 100644
--- a/packages/date-picker/src/vaadin-date-picker-overlay-content-mixin.js
+++ b/packages/date-picker/src/vaadin-date-picker-overlay-content-mixin.js
@@ -230,6 +230,10 @@ export const DatePickerOverlayContentMixin = (superClass) =>
return this.calendars.map((calendar) => calendar.focusableDateElement).find(Boolean);
}
+ get focusableDateButton() {
+ return this.calendars.map((calendar) => calendar.focusableDateButton).find(Boolean);
+ }
+
/** @protected */
_initControllers() {
this.addController(
@@ -897,12 +901,12 @@ export const DatePickerOverlayContentMixin = (superClass) =>
__tryFocusDate() {
const dateToFocus = this.__pendingDateFocus;
if (dateToFocus) {
- // Check the date element with tabindex="0"
+ // Check the cell of the date that has the focusable button
const dateElement = this.focusableDateElement;
if (dateElement && dateEquals(dateElement.date, this.__pendingDateFocus)) {
delete this.__pendingDateFocus;
- dateElement.focus();
+ this.focusableDateButton.focus();
}
}
}
diff --git a/packages/date-picker/src/vaadin-month-calendar-mixin.js b/packages/date-picker/src/vaadin-month-calendar-mixin.js
index 6ab5e4b35a4..75a32464073 100644
--- a/packages/date-picker/src/vaadin-month-calendar-mixin.js
+++ b/packages/date-picker/src/vaadin-month-calendar-mixin.js
@@ -146,15 +146,32 @@ export const MonthCalendarMixin = (superClass) =>
return ['__focusedDateChanged(focusedDate, _days)', '_showWeekNumbersChanged(showWeekNumbers, i18n)'];
}
+ /**
+ * The date cell of the focused date. It carries the `date` property and the date part names,
+ * while the button inside it is the element that takes DOM focus.
+ */
get focusableDateElement() {
return [...this.shadowRoot.querySelectorAll('[part~=date]')].find((datePart) => {
return dateEquals(datePart.date, this.focusedDate);
});
}
+ /**
+ * The button inside the cell of the focused date. Screen readers get the date's name and state
+ * from this element, so it is also the element that takes DOM focus.
+ */
+ get focusableDateButton() {
+ const cell = this.focusableDateElement;
+ return cell ? cell.querySelector('[part~=date-button]') : undefined;
+ }
+
/** @protected */
ready() {
super.ready();
+
+ // Use application to enforce focus mode for date cells in NVDA
+ this.setAttribute('role', 'application');
+
addListener(this.$.monthGrid, 'tap', this._handleTap.bind(this));
}
@@ -294,11 +311,11 @@ export const MonthCalendarMixin = (superClass) =>
/** @protected */
_handleTap(e) {
- if (!this.ignoreTaps && !this._notTapping && e.target.date && !e.target.hasAttribute('disabled')) {
- this.selectedDate = e.target.date;
- this.dispatchEvent(
- new CustomEvent('date-tap', { detail: { date: e.target.date }, bubbles: true, composed: true }),
- );
+ // A tap can land on the button or on the cell padding around it.
+ const cell = e.target.closest('[part~=date]');
+ if (!this.ignoreTaps && !this._notTapping && cell?.date && !cell.hasAttribute('disabled')) {
+ this.selectedDate = cell.date;
+ this.dispatchEvent(new CustomEvent('date-tap', { detail: { date: cell.date }, bubbles: true, composed: true }));
}
}
diff --git a/packages/date-picker/src/vaadin-month-calendar.js b/packages/date-picker/src/vaadin-month-calendar.js
index fce2c1855df..1232352c128 100644
--- a/packages/date-picker/src/vaadin-month-calendar.js
+++ b/packages/date-picker/src/vaadin-month-calendar.js
@@ -3,7 +3,7 @@
* Copyright (c) 2016 - 2026 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
-import { html, LitElement } from 'lit';
+import { html, LitElement, nothing } from 'lit';
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
import { LumoInjectionMixin } from '@vaadin/vaadin-themable-mixin/lumo-injection-mixin.js';
@@ -80,16 +80,24 @@ class MonthCalendar extends MonthCalendarMixin(ThemableMixin(PolylitMixin(LumoIn
)}"
.date="${date}"
?disabled="${this.__isDayDisabled(date, this.minDate, this.maxDate, this.isDateDisabled)}"
- tabindex="${this.__computeDayTabIndex(date, this.focusedDate)}"
aria-selected="${this.__computeDayAriaSelected(date, this.selectedDate)}"
- aria-disabled="${this.__computeDayAriaDisabled(
- date,
- this.minDate,
- this.maxDate,
- this.isDateDisabled,
- )}"
- aria-label="${this.__computeDayAriaLabel(date)}"
- >${this._getDate(date)}${
+ date
+ ? html`
${this._getDate(date)}
`
+ : nothing
+ }
`;
})}
diff --git a/packages/date-picker/test/date-metadata-provider.test.js b/packages/date-picker/test/date-metadata-provider.test.js
index e398b80ba81..fd08770f2cb 100644
--- a/packages/date-picker/test/date-metadata-provider.test.js
+++ b/packages/date-picker/test/date-metadata-provider.test.js
@@ -4,7 +4,16 @@ import sinon from 'sinon';
import '../src/vaadin-date-picker.js';
import { DateMetadataController } from '../src/vaadin-date-metadata-controller.js';
import { formatISODate, monthIndex, parseDate } from '../src/vaadin-date-picker-helper.js';
-import { getCalendars, getDateCell, getDateCells, getMonthCalendar, isoDate, isoDateInMonth, open } from './helpers.js';
+import {
+ getCalendars,
+ getDateButton,
+ getDateCell,
+ getDateCells,
+ getMonthCalendar,
+ isoDate,
+ isoDateInMonth,
+ open,
+} from './helpers.js';
describe('dateMetadataProvider integration', () => {
let datePicker, overlayContent, today, year, month;
@@ -84,8 +93,8 @@ describe('dateMetadataProvider integration', () => {
});
it('should set aria-disabled on a provider-disabled date', () => {
- expect(cell15.getAttribute('aria-disabled')).to.equal('true');
- expect(cell16.getAttribute('aria-disabled')).to.equal('false');
+ expect(getDateButton(cell15).getAttribute('aria-disabled')).to.equal('true');
+ expect(getDateButton(cell16).getAttribute('aria-disabled')).to.equal('false');
});
it('should not report loading for an answer that needs no waiting', () => {
@@ -121,7 +130,7 @@ describe('dateMetadataProvider integration', () => {
it('should keep the dates of a pending month selectable', () => {
expect(isDisabled(cell15)).to.be.false;
- expect(cell15.getAttribute('aria-disabled')).to.equal('false');
+ expect(getDateButton(cell15).getAttribute('aria-disabled')).to.equal('false');
});
it('should commit a date picked from a month being fetched', async () => {
@@ -144,10 +153,10 @@ describe('dateMetadataProvider integration', () => {
expect(overlayContent.hasAttribute('aria-busy')).to.be.false;
expect(isDisabled(cell15)).to.be.true;
- expect(cell15.getAttribute('aria-disabled')).to.equal('true');
+ expect(getDateButton(cell15).getAttribute('aria-disabled')).to.equal('true');
expect(isDisabled(cell16)).to.be.false;
- expect(cell16.getAttribute('aria-disabled')).to.equal('false');
+ expect(getDateButton(cell16).getAttribute('aria-disabled')).to.equal('false');
expect(cell15.part.contains('loading')).to.be.false;
expect(cell16.part.contains('loading')).to.be.false;
diff --git a/packages/date-picker/test/dom/__snapshots__/date-picker.test.snap.js b/packages/date-picker/test/dom/__snapshots__/date-picker.test.snap.js
index 776f441da61..3fe2ef67148 100644
--- a/packages/date-picker/test/dom/__snapshots__/date-picker.test.snap.js
+++ b/packages/date-picker/test/dom/__snapshots__/date-picker.test.snap.js
@@ -389,27 +389,42 @@ snapshots["vaadin-date-picker host opened default"] =
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/packages/date-picker/test/dom/__snapshots__/month-calendar.test.snap.js b/packages/date-picker/test/dom/__snapshots__/month-calendar.test.snap.js
index d85b3ff243e..baede4dacf0 100644
--- a/packages/date-picker/test/dom/__snapshots__/month-calendar.test.snap.js
+++ b/packages/date-picker/test/dom/__snapshots__/month-calendar.test.snap.js
@@ -2,7 +2,10 @@
export const snapshots = {};
snapshots["vaadin-month-calendar host default"] =
-`
+`
`;
/* end snapshot vaadin-month-calendar host default */
@@ -106,73 +109,100 @@ snapshots["vaadin-month-calendar shadow default"] =
5
|
- 1
+
+ 1
+
|
- 2
+
+ 2
+
|
- 3
+
+ 3
+
|
- 4
+
+ 4
+
|
- 5
+
+ 5
+
|
- 6
+
+ 6
+
|
@@ -184,74 +214,109 @@ snapshots["vaadin-month-calendar shadow default"] =
5
|
- 7
+
+ 7
+
|
- 8
+
+ 8
+
|
- 9
+
+ 9
+
|
- 10
+
+ 10
+
|
- 11
+
+ 11
+
|
- 12
+
+ 12
+
|
- 13
+
+ 13
+
|
@@ -263,74 +328,109 @@ snapshots["vaadin-month-calendar shadow default"] =
6
|
- 14
+
+ 14
+
|
- 15
+
+ 15
+
|
- 16
+
+ 16
+
|
- 17
+
+ 17
+
|
- 18
+
+ 18
+
|
- 19
+
+ 19
+
|
- 20
+
+ 20
+
|
@@ -342,74 +442,109 @@ snapshots["vaadin-month-calendar shadow default"] =
7
|
- 21
+
+ 21
+
|
- 22
+
+ 22
+
|
- 23
+
+ 23
+
|
- 24
+
+ 24
+
|
- 25
+
+ 25
+
|
- 26
+
+ 26
+
|
- 27
+
+ 27
+
|
@@ -421,24 +556,34 @@ snapshots["vaadin-month-calendar shadow default"] =
8
|
- 28
+
+ 28
+
|
- 29
+
+ 29
+
|
@@ -545,73 +690,100 @@ snapshots["vaadin-month-calendar shadow max date"] =
5
|
- 1
+
+ 1
+
|
- 2
+
+ 2
+
|
- 3
+
+ 3
+
|
- 4
+
+ 4
+
|
- 5
+
+ 5
+
|
- 6
+
+ 6
+
|
@@ -623,77 +795,112 @@ snapshots["vaadin-month-calendar shadow max date"] =
5
|
- 7
+
+ 7
+
|
- 8
+
+ 8
+
|
- 9
+
+ 9
+
|
- 10
+
+ 10
+
|
- 11
+
+ 11
+
|
- 12
+
+ 12
+
|
- 13
+
+ 13
+
|
@@ -705,81 +912,116 @@ snapshots["vaadin-month-calendar shadow max date"] =
6
|
- 14
+
+ 14
+
|
- 15
+
+ 15
+
|
- 16
+
+ 16
+
|
- 17
+
+ 17
+
|
- 18
+
+ 18
+
|
- 19
+
+ 19
+
|
- 20
+
+ 20
+
|
@@ -791,81 +1033,116 @@ snapshots["vaadin-month-calendar shadow max date"] =
7
|
- 21
+
+ 21
+
|
- 22
+
+ 22
+
|
- 23
+
+ 23
+
|
- 24
+
+ 24
+
|
- 25
+
+ 25
+
|
- 26
+
+ 26
+
|
- 27
+
+ 27
+
|
@@ -877,26 +1154,36 @@ snapshots["vaadin-month-calendar shadow max date"] =
8
|
- 28
+
+ 28
+
|
- 29
+
+ 29
+
|
@@ -1001,74 +1288,109 @@ snapshots["vaadin-month-calendar shadow week numbers"] =
5
- 1
+
+ 1
+
|
- 2
+
+ 2
+
|
- 3
+
+ 3
+
|
- 4
+
+ 4
+
|
- 5
+
+ 5
+
|
- 6
+
+ 6
+
|
- 7
+
+ 7
+
|
@@ -1079,74 +1401,109 @@ snapshots["vaadin-month-calendar shadow week numbers"] =
6
|
- 8
+
+ 8
+
|
- 9
+
+ 9
+
|
- 10
+
+ 10
+
|
- 11
+
+ 11
+
|
- 12
+
+ 12
+
|
- 13
+
+ 13
+
|
- 14
+
+ 14
+
|
@@ -1157,74 +1514,109 @@ snapshots["vaadin-month-calendar shadow week numbers"] =
7
|
- 15
+
+ 15
+
|
- 16
+
+ 16
+
|
- 17
+
+ 17
+
|
- 18
+
+ 18
+
|
- 19
+
+ 19
+
|
- 20
+
+ 20
+
|
- 21
+
+ 21
+
|
@@ -1235,74 +1627,109 @@ snapshots["vaadin-month-calendar shadow week numbers"] =
8
|
- 22
+
+ 22
+
|
- 23
+
+ 23
+
|
- 24
+
+ 24
+
|
- 25
+
+ 25
+
|
- 26
+
+ 26
+
|
- 27
+
+ 27
+
|
- 28
+
+ 28
+
|
@@ -1313,14 +1740,19 @@ snapshots["vaadin-month-calendar shadow week numbers"] =
9
|
- 29
+
+ 29
+
|
@@ -1427,76 +1859,103 @@ snapshots["vaadin-month-calendar shadow disabled dates"] =
5
|
- 1
+
+ 1
+
|
- 2
+
+ 2
+
|
- 3
+
+ 3
+
|
- 4
+
+ 4
+
|
- 5
+
+ 5
+
|
- 6
+
+ 6
+
|
@@ -1508,78 +1967,113 @@ snapshots["vaadin-month-calendar shadow disabled dates"] =
5
|
- 7
+
+ 7
+
|
- 8
+
+ 8
+
|
- 9
+
+ 9
+
|
- 10
+
+ 10
+
|
- 11
+
+ 11
+
|
- 12
+
+ 12
+
|
- 13
+
+ 13
+
|
@@ -1591,77 +2085,112 @@ snapshots["vaadin-month-calendar shadow disabled dates"] =
6
|
- 14
+
+ 14
+
|
- 15
+
+ 15
+
|
- 16
+
+ 16
+
|
- 17
+
+ 17
+
|
- 18
+
+ 18
+
|
- 19
+
+ 19
+
|
- 20
+
+ 20
+
|
@@ -1673,78 +2202,113 @@ snapshots["vaadin-month-calendar shadow disabled dates"] =
7
|
- 21
+
+ 21
+
|
- 22
+
+ 22
+
|
- 23
+
+ 23
+
|
- 24
+
+ 24
+
|
- 25
+
+ 25
+
|
- 26
+
+ 26
+
|
- 27
+
+ 27
+
|
@@ -1756,25 +2320,35 @@ snapshots["vaadin-month-calendar shadow disabled dates"] =
8
|
- 28
+
+ 28
+
|
- 29
+
+ 29
+
|
@@ -1881,73 +2455,100 @@ snapshots["vaadin-month-calendar shadow date metadata loading month"] =
5
|
- 1
+
+ 1
+
|
- 2
+
+ 2
+
|
- 3
+
+ 3
+
|
- 4
+
+ 4
+
|
- 5
+
+ 5
+
|
- 6
+
+ 6
+
|
@@ -1959,74 +2560,109 @@ snapshots["vaadin-month-calendar shadow date metadata loading month"] =
5
|
- 7
+
+ 7
+
|
- 8
+
+ 8
+
|
- 9
+
+ 9
+
|
- 10
+
+ 10
+
|
- 11
+
+ 11
+
|
- 12
+
+ 12
+
|
- 13
+
+ 13
+
|
@@ -2038,74 +2674,109 @@ snapshots["vaadin-month-calendar shadow date metadata loading month"] =
6
|
- 14
+
+ 14
+
|
- 15
+
+ 15
+
|
- 16
+
+ 16
+
|
- 17
+
+ 17
+
|
- 18
+
+ 18
+
|
- 19
+
+ 19
+
|
- 20
+
+ 20
+
|
@@ -2117,74 +2788,109 @@ snapshots["vaadin-month-calendar shadow date metadata loading month"] =
7
|
- 21
+
+ 21
+
|
- 22
+
+ 22
+
|
- 23
+
+ 23
+
|
- 24
+
+ 24
+
|
- 25
+
+ 25
+
|
- 26
+
+ 26
+
|
- 27
+
+ 27
+
|
@@ -2196,24 +2902,34 @@ snapshots["vaadin-month-calendar shadow date metadata loading month"] =
8
|
- 28
+
+ 28
+
|
- 29
+
+ 29
+
|
@@ -2320,76 +3036,103 @@ snapshots["vaadin-month-calendar shadow date metadata provider disabled dates"]
5
|
- 1
+
+ 1
+
|
- 2
+
+ 2
+
|
- 3
+
+ 3
+
|
- 4
+
+ 4
+
|
- 5
+
+ 5
+
|
- 6
+
+ 6
+
|
@@ -2401,78 +3144,113 @@ snapshots["vaadin-month-calendar shadow date metadata provider disabled dates"]
5
|
- 7
+
+ 7
+
|
- 8
+
+ 8
+
|
- 9
+
+ 9
+
|
- 10
+
+ 10
+
|
- 11
+
+ 11
+
|
- 12
+
+ 12
+
|
- 13
+
+ 13
+
|
@@ -2484,77 +3262,112 @@ snapshots["vaadin-month-calendar shadow date metadata provider disabled dates"]
6
|
- 14
+
+ 14
+
|
- 15
+
+ 15
+
|
- 16
+
+ 16
+
|
- 17
+
+ 17
+
|
- 18
+
+ 18
+
|
- 19
+
+ 19
+
|
- 20
+
+ 20
+
|
@@ -2566,78 +3379,113 @@ snapshots["vaadin-month-calendar shadow date metadata provider disabled dates"]
7
|
- 21
+
+ 21
+
|
- 22
+
+ 22
+
|
- 23
+
+ 23
+
|
- 24
+
+ 24
+
|
- 25
+
+ 25
+
|
- 26
+
+ 26
+
|
- 27
+
+ 27
+
|
@@ -2649,25 +3497,35 @@ snapshots["vaadin-month-calendar shadow date metadata provider disabled dates"]
8
|
- 28
+
+ 28
+
|
- 29
+
+ 29
+
|
diff --git a/packages/date-picker/test/dropdown.test.js b/packages/date-picker/test/dropdown.test.js
index 023a7db2f82..bb6729df137 100644
--- a/packages/date-picker/test/dropdown.test.js
+++ b/packages/date-picker/test/dropdown.test.js
@@ -3,7 +3,7 @@ import { resetMouse, sendKeys, sendMouse } from '@vaadin/test-runner-commands';
import { aTimeout, fire, fixtureSync, mousedown, nextRender, oneEvent, touchstart } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import '../src/vaadin-date-picker.js';
-import { getFocusableCell, monthsEqual, open, untilOverlayRendered } from './helpers.js';
+import { getFocusableDateButton, monthsEqual, open, untilOverlayRendered } from './helpers.js';
describe('dropdown', () => {
let datePicker, input, overlay;
@@ -273,10 +273,10 @@ describe('dropdown', () => {
describe('date tap', () => {
function dateTap() {
- const date = getFocusableCell(datePicker);
- mousedown(date);
- date.focus();
- date.click();
+ const button = getFocusableDateButton(datePicker);
+ mousedown(button);
+ button.focus();
+ button.click();
}
it('should close the overlay on date tap', async () => {
diff --git a/packages/date-picker/test/fullscreen.test.js b/packages/date-picker/test/fullscreen.test.js
index 6037bf88e21..67e8a7b8b0f 100644
--- a/packages/date-picker/test/fullscreen.test.js
+++ b/packages/date-picker/test/fullscreen.test.js
@@ -3,7 +3,7 @@ import { resetMouse, sendKeys, sendMouse, setViewport } from '@vaadin/test-runne
import { aTimeout, fixtureSync, nextRender, nextUpdate, outsideClick, tabKeyDown, tap } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import '../src/vaadin-date-picker.js';
-import { getFocusableCell, open, touchTap, untilOverlayRendered } from './helpers.js';
+import { getFocusableCell, getFocusableDateButton, open, touchTap, untilOverlayRendered } from './helpers.js';
describe('fullscreen mode', () => {
let datePicker, input, overlay, width, height;
@@ -333,9 +333,9 @@ describe('fullscreen mode', () => {
expect(spy.calledOnce).to.be.true;
});
- it('should move focus to date cell button on Cancel button Tab', async () => {
- const cell = getFocusableCell(datePicker);
- const spy = sinon.spy(cell, 'focus');
+ it('should move focus to date button on Cancel button Tab', async () => {
+ const button = getFocusableDateButton(datePicker);
+ const spy = sinon.spy(button, 'focus');
// Move focus to Cancel button
await sendKeys({ press: 'Shift+Tab' });
diff --git a/packages/date-picker/test/helpers.js b/packages/date-picker/test/helpers.js
index ff6a0bf8c9a..5675b1d17f2 100644
--- a/packages/date-picker/test/helpers.js
+++ b/packages/date-picker/test/helpers.js
@@ -188,9 +188,22 @@ export function getWeekDayCells(calendar) {
}
/**
+ * The button inside a date cell. It takes DOM focus and carries the date's accessible name and
+ * ARIA state, while the cell carries the `date` property and the part names.
+ *
+ * @param {HTMLElement} cell a date cell of a month calendar
+ * @return {HTMLElement | null}
+ */
+export function getDateButton(cell) {
+ return cell.querySelector('[part~="date-button"]');
+}
+
+/**
+ * The date button that is in the tab sequence, i.e. the one the calendar focuses.
+ *
* @param {HTMLElement} root vaadin-date-picker or vaadin-date-picker-overlay-content
*/
-export function getFocusableCell(root) {
+export function getFocusableDateButton(root) {
const focusableMonth = getCalendars(root).find((month) => {
return !!month.shadowRoot.querySelector('[tabindex="0"]');
});
@@ -201,12 +214,26 @@ export function getFocusableCell(root) {
}
/**
+ * The cell of the date button that is in the tab sequence.
+ *
+ * @param {HTMLElement} root vaadin-date-picker or vaadin-date-picker-overlay-content
+ */
+export function getFocusableCell(root) {
+ const button = getFocusableDateButton(root);
+ if (button) {
+ return button.closest('[part~="date"]');
+ }
+}
+
+/**
+ * The cell of the date button that currently has DOM focus.
+ *
* @param {HTMLElement} root vaadin-date-picker or vaadin-date-picker-overlay-content
*/
export function getFocusedCell(root) {
- const focusableCell = getFocusableCell(root);
- if (focusableCell && isElementFocused(focusableCell)) {
- return focusableCell;
+ const button = getFocusableDateButton(root);
+ if (button && isElementFocused(button)) {
+ return button.closest('[part~="date"]');
}
}
diff --git a/packages/date-picker/test/month-calendar.test.js b/packages/date-picker/test/month-calendar.test.js
index dfc436f181f..08e446cbb34 100644
--- a/packages/date-picker/test/month-calendar.test.js
+++ b/packages/date-picker/test/month-calendar.test.js
@@ -2,7 +2,7 @@ import { expect } from '@vaadin/chai-plugins';
import { aTimeout, fixtureSync, makeSoloTouchEvent, nextFrame, nextRender, tap } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import '../src/vaadin-month-calendar.js';
-import { getDateCell, getDateCells, getDefaultI18n, getWeekDayCells } from './helpers.js';
+import { getDateButton, getDateCell, getDateCells, getDefaultI18n, getWeekDayCells } from './helpers.js';
describe('vaadin-month-calendar', () => {
let monthCalendar, valueChangedSpy;
@@ -99,6 +99,13 @@ describe('vaadin-month-calendar', () => {
expect(monthCalendar.selectedDate.getDate()).to.equal(10);
});
+ it('should update value on tapping the date button', () => {
+ tap(getDateButton(getDateCell(monthCalendar, 10)));
+ expect(monthCalendar.selectedDate.getFullYear()).to.equal(2016);
+ expect(monthCalendar.selectedDate.getMonth()).to.equal(1);
+ expect(monthCalendar.selectedDate.getDate()).to.equal(10);
+ });
+
it('should not react if the tap takes more than 300ms', async () => {
const tapSpy = sinon.spy();
monthCalendar.addEventListener('date-tap', tapSpy);
@@ -179,7 +186,7 @@ describe('vaadin-month-calendar', () => {
it('should label dates in correct locale', () => {
const dates = getDateCells(monthCalendar);
dates.slice(0, 7).forEach((date, index) => {
- const label = date.getAttribute('aria-label');
+ const label = getDateButton(date).getAttribute('aria-label');
const day = ['maanantai', 'tiistai', 'keskiviikko', 'torstai', 'perjantai', 'lauantai', 'sunnuntai'][index];
expect(label).to.equal(`${index + 1} helmikuu 2016, ${day}`);
});
@@ -189,7 +196,7 @@ describe('vaadin-month-calendar', () => {
monthCalendar.month = new Date();
await nextRender();
const today = getDateCells(monthCalendar).find((date) => date.getAttribute('part').includes('today'));
- expect(today.getAttribute('aria-label').split(', ').pop()).to.equal('Tänään');
+ expect(getDateButton(today).getAttribute('aria-label').split(', ').pop()).to.equal('Tänään');
});
it('should render month name in correct locale', () => {
diff --git a/packages/date-picker/test/wai-aria.test.js b/packages/date-picker/test/wai-aria.test.js
index 26135969e83..c643f61a87e 100644
--- a/packages/date-picker/test/wai-aria.test.js
+++ b/packages/date-picker/test/wai-aria.test.js
@@ -1,7 +1,7 @@
import { expect } from '@vaadin/chai-plugins';
import { fixtureSync, nextFrame, nextRender } from '@vaadin/testing-helpers';
import '../src/vaadin-date-picker.js';
-import { activateScroller, getCalendars, getDefaultI18n, open } from './helpers.js';
+import { activateScroller, getCalendars, getDateButton, getDefaultI18n, open } from './helpers.js';
describe('WAI-ARIA', () => {
describe('date picker', () => {
@@ -126,11 +126,11 @@ describe('WAI-ARIA', () => {
await nextRender();
});
- it('should indicate today on date cells', async () => {
+ it('should indicate today on date buttons', async () => {
monthCalendar.month = new Date();
await nextFrame();
const todayElement = monthCalendar.shadowRoot.querySelector('[part~="today"]');
- expect(todayElement.getAttribute('aria-label')).to.match(/, Today$/u);
+ expect(getDateButton(todayElement).getAttribute('aria-label')).to.match(/, Today$/u);
});
});