Skip to content

Commit f076b75

Browse files
committed
refactor: use aria-modal in date-picker instead of aria-hidden
1 parent 858c565 commit f076b75

File tree

5 files changed

+32
-58
lines changed

5 files changed

+32
-58
lines changed

packages/date-picker/src/vaadin-date-picker-mixin.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright (c) 2016 - 2025 Vaadin Ltd.
44
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
55
*/
6-
import { hideOthers } from '@vaadin/a11y-base/src/aria-hidden.js';
76
import { DelegateFocusMixin } from '@vaadin/a11y-base/src/delegate-focus-mixin.js';
87
import { isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
98
import { KeyboardMixin } from '@vaadin/a11y-base/src/keyboard-mixin.js';
@@ -461,6 +460,15 @@ export const DatePickerMixin = (subclass) =>
461460
// Currently only supported for locales that start the week on Monday.
462461
this.toggleAttribute('week-numbers', this.showWeekNumbers && this.__effectiveI18n.firstDayOfWeek === 1);
463462
}
463+
464+
if ((props.has('opened') || props.has('_noInput')) && this._overlayContent) {
465+
if (this.opened && this._noInput) {
466+
// Mark as modal on mobile if the input can not be accessed
467+
this._overlayContent.setAttribute('aria-modal', 'true');
468+
} else {
469+
this._overlayContent.removeAttribute('aria-modal');
470+
}
471+
}
464472
}
465473

466474
/** @protected */
@@ -910,9 +918,6 @@ export const DatePickerMixin = (subclass) =>
910918
input.blur();
911919
this._overlayContent.focusDateElement();
912920
}
913-
914-
const focusables = this._noInput ? content : [input, content];
915-
this.__showOthers = hideOthers(focusables);
916921
}
917922

918923
/** @private */
@@ -959,11 +964,6 @@ export const DatePickerMixin = (subclass) =>
959964

960965
/** @protected */
961966
_onOverlayClosed() {
962-
// Reset `aria-hidden` state.
963-
if (this.__showOthers) {
964-
this.__showOthers();
965-
this.__showOthers = null;
966-
}
967967
window.removeEventListener('scroll', this._boundOnScroll, true);
968968

969969
if (this._closedByEscape) {

packages/date-picker/src/vaadin-date-picker-overlay-content-mixin.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ export const DatePickerOverlayContentMixin = (superClass) =>
165165
}
166166

167167
/** @protected */
168-
_initControllers() {
168+
firstUpdated() {
169+
super.firstUpdated();
170+
171+
this.setAttribute('role', 'dialog');
172+
169173
this.addController(
170174
new MediaQueryController(this._desktopMediaQuery, (matches) => {
171175
this._desktopMode = matches;

packages/date-picker/src/vaadin-date-picker-overlay-content.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,6 @@ class DatePickerOverlayContent extends DatePickerOverlayContentMixin(
5353
</div>
5454
`;
5555
}
56-
57-
/** @protected */
58-
firstUpdated() {
59-
super.firstUpdated();
60-
61-
this.setAttribute('role', 'dialog');
62-
63-
this._initControllers();
64-
}
6556
}
6657

6758
defineCustomElement(DatePickerOverlayContent);

packages/date-picker/test/dom/__snapshots__/date-picker.test.snap.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,12 @@ snapshots["vaadin-date-picker host opened default"] =
319319
top-aligned=""
320320
>
321321
<label
322-
aria-hidden="true"
323-
data-aria-hidden="true"
324322
for="search-input-vaadin-date-picker-3"
325323
id="label-vaadin-date-picker-0"
326324
slot="label"
327325
>
328326
</label>
329327
<div
330-
aria-hidden="true"
331-
data-aria-hidden="true"
332328
hidden=""
333329
id="error-message-vaadin-date-picker-2"
334330
slot="error-message"

packages/date-picker/test/wai-aria.test.js

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ describe('WAI-ARIA', () => {
2929
expect(calendar.getAttribute('aria-hidden')).to.equal(focusable ? null : 'true');
3030
});
3131
});
32+
33+
it('should not set aria-modal attribute on the overlay content on open by default', async () => {
34+
await open(datePicker);
35+
const content = datePicker._overlayContent;
36+
37+
expect(content.hasAttribute('aria-modal')).to.be.false;
38+
});
39+
40+
it('should toggle aria-modal attribute on the overlay content on open if fullscreen', async () => {
41+
datePicker._fullscreen = true;
42+
43+
await open(datePicker);
44+
const content = datePicker._overlayContent;
45+
expect(content.getAttribute('aria-modal')).to.equal('true');
46+
47+
datePicker.close();
48+
expect(content.hasAttribute('aria-modal')).to.be.false;
49+
});
3250
});
3351

3452
describe('overlay contents', () => {
@@ -84,39 +102,4 @@ describe('WAI-ARIA', () => {
84102
expect(todayElement.getAttribute('aria-label')).to.match(/, Today$/u);
85103
});
86104
});
87-
88-
describe('aria-hidden', () => {
89-
let wrapper, datePicker, input, button;
90-
91-
beforeEach(async () => {
92-
wrapper = fixtureSync(`
93-
<div>
94-
<button>Button</button>
95-
<vaadin-date-picker></vaadin-date-picker>
96-
<input placeholder="input" />
97-
</div>
98-
`);
99-
await nextRender();
100-
[button, datePicker, input] = wrapper.children;
101-
});
102-
103-
it('should set aria-hidden on other elements when overlay is opened', async () => {
104-
await open(datePicker);
105-
expect(button.getAttribute('aria-hidden')).to.equal('true');
106-
expect(input.getAttribute('aria-hidden')).to.equal('true');
107-
});
108-
109-
it('should not set aria-hidden on slotted input and overlay element', async () => {
110-
await open(datePicker);
111-
expect(datePicker.inputElement.hasAttribute('aria-hidden')).to.be.false;
112-
expect(datePicker.$.overlay.hasAttribute('aria-hidden')).to.be.false;
113-
});
114-
115-
it('should remove aria-hidden from other elements when overlay is closed', async () => {
116-
await open(datePicker);
117-
datePicker.close();
118-
expect(button.hasAttribute('aria-hidden')).to.be.false;
119-
expect(input.hasAttribute('aria-hidden')).to.be.false;
120-
});
121-
});
122105
});

0 commit comments

Comments
 (0)