Skip to content

Commit 5be9540

Browse files
committed
Merge branch 'schilchSICKAG-fix/a11y-errors-for-blur' into next
2 parents eef4c17 + d2ce983 commit 5be9540

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

docs/pages/resources/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ New versions of Shoelace are released as-needed and generally occur when a criti
1818
- Fixed a bug that in `<sl-dropdown>` that prevented tab from working properly in some cases [#2371]
1919
- Fixed the guard on popover to allow virtual elements [#2399]
2020
- Fixed the close button in `<sl-alert>` so clicking above/below it doesn't inadvertently close it [#2375]
21+
- Fixed accessibility issues for elements that are closed while having slotted focused children. [#2383]
2122

2223
## 2.20.0
2324

src/components/alert/alert.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { animateTo, stopAnimations } from '../../internal/animate.js';
2+
import { blurActiveElement } from '../../internal/closeActiveElement.js';
23
import { classMap } from 'lit/directives/class-map.js';
34
import { getAnimation, setDefaultAnimation } from '../../utilities/animation-registry.js';
45
import { HasSlotController } from '../../internal/slot.js';
@@ -157,6 +158,7 @@ export default class SlAlert extends ShoelaceElement {
157158
this.emit('sl-after-show');
158159
} else {
159160
// Hide
161+
blurActiveElement(this);
160162
this.emit('sl-hide');
161163

162164
clearTimeout(this.autoHideTimeout);

src/components/dialog/dialog.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { animateTo, stopAnimations } from '../../internal/animate.js';
2+
import { blurActiveElement } from '../../internal/closeActiveElement.js';
23
import { classMap } from 'lit/directives/class-map.js';
34
import { getAnimation, setDefaultAnimation } from '../../utilities/animation-registry.js';
45
import { HasSlotController } from '../../internal/slot.js';
@@ -208,6 +209,7 @@ export default class SlDialog extends ShoelaceElement {
208209
this.emit('sl-after-show');
209210
} else {
210211
// Hide
212+
blurActiveElement(this);
211213
this.emit('sl-hide');
212214
this.removeOpenListeners();
213215
this.modal.deactivate();

src/components/drawer/drawer.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { animateTo, stopAnimations } from '../../internal/animate.js';
2+
import { blurActiveElement } from '../../internal/closeActiveElement.js';
23
import { classMap } from 'lit/directives/class-map.js';
34
import { getAnimation, setDefaultAnimation } from '../../utilities/animation-registry.js';
45
import { HasSlotController } from '../../internal/slot.js';
@@ -237,6 +238,7 @@ export default class SlDrawer extends ShoelaceElement {
237238
this.emit('sl-after-show');
238239
} else {
239240
// Hide
241+
blurActiveElement(this);
240242
this.emit('sl-hide');
241243
this.removeOpenListeners();
242244

src/internal/closeActiveElement.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Calls the blur method on the current active element if it is a child of the provided element.
3+
* Needed for fixing a11y errors in console.
4+
* @see https://github.com/shoelace-style/shoelace/issues/2283
5+
* @param elm The element to check
6+
*/
7+
export const blurActiveElement = (elm: HTMLElement) => {
8+
const { activeElement } = document;
9+
if (activeElement && elm.contains(activeElement)) {
10+
(document.activeElement as HTMLElement)?.blur();
11+
}
12+
};

0 commit comments

Comments
 (0)