Skip to content

Commit 9b6c7c8

Browse files
authored
refactor: remove usage of AriaModalController from overlay (#10026)
1 parent 2674a57 commit 9b6c7c8

File tree

9 files changed

+3
-271
lines changed

9 files changed

+3
-271
lines changed

packages/confirm-dialog/src/vaadin-confirm-dialog-overlay.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,6 @@ class ConfirmDialogOverlay extends OverlayMixin(DirMixin(ThemableMixin(PolylitMi
9090
return this.owner;
9191
}
9292

93-
/**
94-
* Override method from OverlayFocusMixin to use owner as modal root
95-
* @protected
96-
* @override
97-
*/
98-
get _modalRoot() {
99-
return this.owner;
100-
}
101-
10293
/**
10394
* Override method from OverlayFocusMixin to use owner as focus trap root
10495
* @protected
@@ -107,15 +98,6 @@ class ConfirmDialogOverlay extends OverlayMixin(DirMixin(ThemableMixin(PolylitMi
10798
get _focusTrapRoot() {
10899
return this.owner;
109100
}
110-
111-
/**
112-
* Override method from OverlayFocusMixin to not set `aria-hidden`
113-
* @protected
114-
* @override
115-
*/
116-
get _useAriaHidden() {
117-
return false;
118-
}
119101
}
120102

121103
defineCustomElement(ConfirmDialogOverlay);

packages/crud/src/vaadin-crud-dialog.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ class CrudDialogOverlay extends OverlayMixin(DirMixin(ThemableMixin(PolylitMixin
3939
return crudDialogOverlayStyles;
4040
}
4141

42-
/**
43-
* Override method from OverlayFocusMixin to use the owner (CRUD element) as modal root
44-
* @protected
45-
* @override
46-
*/
47-
get _modalRoot() {
48-
return this.owner;
49-
}
50-
5142
/**
5243
* Override method from OverlayFocusMixin to use dialog as focus trap root
5344
* @protected
@@ -58,15 +49,6 @@ class CrudDialogOverlay extends OverlayMixin(DirMixin(ThemableMixin(PolylitMixin
5849
return this.getRootNode().host;
5950
}
6051

61-
/**
62-
* Override method from OverlayFocusMixin to not set `aria-hidden`
63-
* @protected
64-
* @override
65-
*/
66-
get _useAriaHidden() {
67-
return false;
68-
}
69-
7052
/** @protected */
7153
render() {
7254
return html`

packages/dialog/src/vaadin-dialog-overlay-mixin.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,6 @@ export const DialogOverlayMixin = (superClass) =>
5353
return this.owner;
5454
}
5555

56-
/**
57-
* Override method from OverlayFocusMixin to use owner as modal root
58-
* @protected
59-
* @override
60-
*/
61-
get _modalRoot() {
62-
return this.owner;
63-
}
64-
6556
/** @protected */
6657
ready() {
6758
super.ready();

packages/dialog/src/vaadin-dialog-overlay.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@ export class DialogOverlay extends DialogOverlayMixin(
4242
return this.owner;
4343
}
4444

45-
/**
46-
* Override method from OverlayFocusMixin to not set `aria-hidden`
47-
* @protected
48-
* @override
49-
*/
50-
get _useAriaHidden() {
51-
return false;
52-
}
53-
5445
/** @protected */
5546
render() {
5647
return html`

packages/login/src/vaadin-login-overlay-wrapper.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ class LoginOverlayWrapper extends OverlayMixin(DirMixin(ThemableMixin(PolylitMix
4141
};
4242
}
4343

44-
/**
45-
* @protected
46-
* @override
47-
*/
48-
get _modalRoot() {
49-
return this.owner;
50-
}
51-
5244
/**
5345
* Override method from OverlayFocusMixin to use owner as focus trap root
5446
* @protected
@@ -58,15 +50,6 @@ class LoginOverlayWrapper extends OverlayMixin(DirMixin(ThemableMixin(PolylitMix
5850
return this.owner;
5951
}
6052

61-
/**
62-
* Override method from OverlayFocusMixin to not set `aria-hidden`
63-
* @protected
64-
* @override
65-
*/
66-
get _useAriaHidden() {
67-
return false;
68-
}
69-
7053
/** @protected */
7154
render() {
7255
return html`

packages/overlay/src/vaadin-overlay-focus-mixin.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright (c) 2017 - 2025 Vaadin Ltd.
44
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
55
*/
6-
import { AriaModalController } from '@vaadin/a11y-base/src/aria-modal-controller.js';
76
import { FocusRestorationController } from '@vaadin/a11y-base/src/focus-restoration-controller.js';
87
import { FocusTrapController } from '@vaadin/a11y-base/src/focus-trap-controller.js';
98
import { getDeepActiveElement, isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
@@ -48,7 +47,6 @@ export const OverlayFocusMixin = (superClass) =>
4847
constructor() {
4948
super();
5049

51-
this.__ariaModalController = new AriaModalController(this, () => this._modalRoot);
5250
this.__focusTrapController = new FocusTrapController(this);
5351
this.__focusRestorationController = new FocusRestorationController();
5452
}
@@ -66,20 +64,10 @@ export const OverlayFocusMixin = (superClass) =>
6664
ready() {
6765
super.ready();
6866

69-
this.addController(this.__ariaModalController);
7067
this.addController(this.__focusTrapController);
7168
this.addController(this.__focusRestorationController);
7269
}
7370

74-
/**
75-
* Override to specify another element used as a modality root,
76-
* e.g. the overlay's owner element, rather than overlay itself.
77-
* @protected
78-
*/
79-
get _modalRoot() {
80-
return this;
81-
}
82-
8371
/**
8472
* Override to specify another element used as a focus trap root,
8573
* e.g. the overlay's owner element, rather than overlay part.
@@ -89,25 +77,13 @@ export const OverlayFocusMixin = (superClass) =>
8977
return this.$.overlay;
9078
}
9179

92-
/**
93-
* Override not use a controller for setting `aria-hidden` on
94-
* elements outside the overlay, e.g. when using `aria-modal`.
95-
* @protected
96-
*/
97-
_useAriaHidden() {
98-
return true;
99-
}
100-
10180
/**
10281
* Release focus and restore focus after the overlay is closed.
10382
*
10483
* @protected
10584
*/
10685
_resetFocus() {
10786
if (this.focusTrap) {
108-
if (this._useAriaHidden) {
109-
this.__ariaModalController.close();
110-
}
11187
this.__focusTrapController.releaseFocus();
11288
}
11389

@@ -135,9 +111,6 @@ export const OverlayFocusMixin = (superClass) =>
135111
*/
136112
_trapFocus() {
137113
if (this.focusTrap) {
138-
if (this._useAriaHidden) {
139-
this.__ariaModalController.showModal();
140-
}
141114
this.__focusTrapController.trapFocus(this._focusTrapRoot);
142115
}
143116
}
Lines changed: 1 addition & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from '@vaadin/chai-plugins';
22
import { fixtureSync, nextRender, oneEvent, tabKeyDown } from '@vaadin/testing-helpers';
3+
import '../src/vaadin-overlay.js';
34
import { getFocusableElements, isElementFocused } from '@vaadin/a11y-base/src/focus-utils.js';
4-
import { Overlay } from '../src/vaadin-overlay.js';
55

66
describe('focus-trap', () => {
77
let overlay, overlayPart, focusableElements;
@@ -141,157 +141,4 @@ describe('focus-trap', () => {
141141
expect(getFocusedElementIndex()).to.equal(0);
142142
});
143143
});
144-
145-
describe('aria-hidden', () => {
146-
let wrapper, sibling, overlay;
147-
148-
beforeEach(() => {
149-
wrapper = fixtureSync(`
150-
<div>
151-
<aside>
152-
<button>Foo</button>
153-
</aside>
154-
<div>
155-
<button>Foo</button>
156-
<vaadin-overlay focus-trap></vaadin-overlay>
157-
<button>Bar</button>
158-
</div>
159-
</div>
160-
`);
161-
162-
overlay = wrapper.querySelector('vaadin-overlay');
163-
sibling = wrapper.querySelector('aside');
164-
overlay.renderer = (root) => {
165-
root.innerHTML = '<input placeholder="Input">';
166-
};
167-
});
168-
169-
afterEach(() => {
170-
overlay.opened = false;
171-
});
172-
173-
it('should set aria-hidden on other elements on overlay open', async () => {
174-
overlay.opened = true;
175-
await oneEvent(overlay, 'vaadin-overlay-open');
176-
177-
expect(sibling.getAttribute('aria-hidden')).to.equal('true');
178-
});
179-
180-
it('should remove aria-hidden from other elements on overlay close', async () => {
181-
overlay.opened = true;
182-
await oneEvent(overlay, 'vaadin-overlay-open');
183-
184-
overlay.opened = false;
185-
expect(sibling.hasAttribute('aria-hidden')).to.be.false;
186-
});
187-
188-
it('should not set aria-hidden on other elements if focusTrap is set to false', async () => {
189-
overlay.focusTrap = false;
190-
191-
overlay.opened = true;
192-
await oneEvent(overlay, 'vaadin-overlay-open');
193-
194-
expect(sibling.hasAttribute('aria-hidden')).to.be.false;
195-
});
196-
});
197-
198-
describe('aria-hidden modal root', () => {
199-
customElements.define(
200-
'custom-overlay-wrapper',
201-
class extends HTMLElement {
202-
constructor() {
203-
super();
204-
205-
this.attachShadow({ mode: 'open' });
206-
207-
const overlay = document.createElement('custom-overlay');
208-
209-
const owner = document.createElement('div');
210-
overlay.owner = owner;
211-
212-
// Forward the slotted content from wrapper to overlay
213-
const slot = document.createElement('slot');
214-
overlay.appendChild(slot);
215-
216-
overlay.focusTrap = true;
217-
overlay.renderer = (root) => {
218-
root.innerHTML = '<input placeholder="Input">';
219-
};
220-
221-
this.shadowRoot.append(overlay);
222-
this.append(owner);
223-
}
224-
},
225-
);
226-
227-
customElements.define(
228-
'custom-overlay',
229-
class extends Overlay {
230-
get _contentRoot() {
231-
return this.owner;
232-
}
233-
234-
get _modalRoot() {
235-
return this.owner;
236-
}
237-
},
238-
);
239-
240-
let outer, inner, wrapper, overlay;
241-
242-
beforeEach(() => {
243-
outer = fixtureSync(`
244-
<div>
245-
<aside>
246-
<button>Foo</button>
247-
</aside>
248-
<div>
249-
<button>Bar</button>
250-
<custom-overlay-wrapper></custom-overlay-wrapper>
251-
<button>Baz</button>
252-
</div>
253-
</div>
254-
`);
255-
256-
wrapper = outer.querySelector('custom-overlay-wrapper');
257-
inner = outer.querySelector('div');
258-
overlay = wrapper.shadowRoot.querySelector('custom-overlay');
259-
});
260-
261-
afterEach(() => {
262-
overlay.opened = false;
263-
});
264-
265-
it('should not set aria-hidden on wrapping elements on overlay open', async () => {
266-
overlay.opened = true;
267-
await oneEvent(overlay, 'vaadin-overlay-open');
268-
269-
expect(outer.hasAttribute('aria-hidden')).to.be.false;
270-
expect(inner.hasAttribute('aria-hidden')).to.be.false;
271-
expect(wrapper.hasAttribute('aria-hidden')).to.be.false;
272-
});
273-
274-
it('should not set aria-hidden on content root element on overlay open', async () => {
275-
overlay.opened = true;
276-
await oneEvent(overlay, 'vaadin-overlay-open');
277-
278-
const root = wrapper.querySelector('div');
279-
const input = root.firstElementChild;
280-
281-
expect(root.hasAttribute('aria-hidden')).to.be.false;
282-
expect(input.hasAttribute('aria-hidden')).to.be.false;
283-
});
284-
285-
it('should set aria-hidden on sibling elements on overlay open', async () => {
286-
overlay.opened = true;
287-
await oneEvent(overlay, 'vaadin-overlay-open');
288-
289-
const buttons = wrapper.parentElement.querySelectorAll('button');
290-
expect(buttons[0].getAttribute('aria-hidden')).to.equal('true');
291-
expect(buttons[1].getAttribute('aria-hidden')).to.equal('true');
292-
293-
const aside = outer.querySelector('aside');
294-
expect(aside.getAttribute('aria-hidden')).to.equal('true');
295-
});
296-
});
297144
});

packages/popover/src/vaadin-popover-overlay.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ class PopoverOverlay extends PopoverOverlayMixin(
6868
return this.owner;
6969
}
7070

71-
/**
72-
* @override
73-
* @protected
74-
*/
75-
get _modalRoot() {
76-
return this.owner;
77-
}
78-
7971
/**
8072
* Override method from OverlayFocusMixin to use owner as focus trap root
8173
* @protected
@@ -85,15 +77,6 @@ class PopoverOverlay extends PopoverOverlayMixin(
8577
return this.owner;
8678
}
8779

88-
/**
89-
* Override method from OverlayFocusMixin to not set `aria-hidden`
90-
* @protected
91-
* @override
92-
*/
93-
get _useAriaHidden() {
94-
return false;
95-
}
96-
9780
/**
9881
* Override method from `OverlayMixin` to always add outside
9982
* click listener so that it can be used by modeless popover.

0 commit comments

Comments
 (0)