@vaadin/a11y-base 24.1.0 → 24.2.0-alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +4 -4
- package/src/aria-modal-controller.d.ts +6 -0
- package/src/aria-modal-controller.js +11 -2
- package/src/focus-restoration-controller.d.ts +27 -0
- package/src/focus-restoration-controller.js +44 -0
- package/src/styles/sr-only-styles.d.ts +8 -0
- package/src/styles/sr-only-styles.js +28 -0
package/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export {
|
|
|
12
12
|
isKeyboardActive,
|
|
13
13
|
} from './src/focus-utils.js';
|
|
14
14
|
export { FocusTrapController } from './src/focus-trap-controller.js';
|
|
15
|
+
export { FocusRestorationController } from './src/focus-restoration-controller.js';
|
|
15
16
|
export { KeyboardDirectionMixin } from './src/keyboard-direction-mixin.js';
|
|
16
17
|
export { KeyboardMixin } from './src/keyboard-mixin.js';
|
|
17
18
|
export { ListMixin } from './src/list-mixin.js';
|
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export { DisabledMixin } from './src/disabled-mixin.js';
|
|
|
5
5
|
export { FieldAriaController } from './src/field-aria-controller.js';
|
|
6
6
|
export { FocusMixin } from './src/focus-mixin.js';
|
|
7
7
|
export { FocusTrapController } from './src/focus-trap-controller.js';
|
|
8
|
+
export { FocusRestorationController } from './src/focus-restoration-controller.js';
|
|
8
9
|
export {
|
|
9
10
|
getFocusableElements,
|
|
10
11
|
isElementFocusable,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/a11y-base",
|
|
3
|
-
"version": "24.
|
|
3
|
+
"version": "24.2.0-alpha1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
34
34
|
"@polymer/polymer": "^3.0.0",
|
|
35
|
-
"@vaadin/component-base": "
|
|
35
|
+
"@vaadin/component-base": "24.2.0-alpha1",
|
|
36
36
|
"lit": "^2.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@esm-bundle/chai": "^4.3.4",
|
|
40
|
-
"@vaadin/testing-helpers": "^0.4.
|
|
40
|
+
"@vaadin/testing-helpers": "^0.4.2",
|
|
41
41
|
"sinon": "^13.0.2"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "0dbb118320203ab6c0c07450a3e718815367589f"
|
|
44
44
|
}
|
|
@@ -15,6 +15,12 @@ export class AriaModalController implements ReactiveController {
|
|
|
15
15
|
*/
|
|
16
16
|
host: HTMLElement;
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* The callback used to detect which element
|
|
20
|
+
* to use as a target. Defaults to the host.
|
|
21
|
+
*/
|
|
22
|
+
callback: () => HTMLElement | HTMLElement[];
|
|
23
|
+
|
|
18
24
|
constructor(node: HTMLElement);
|
|
19
25
|
|
|
20
26
|
/**
|
|
@@ -16,13 +16,21 @@ export class AriaModalController {
|
|
|
16
16
|
/**
|
|
17
17
|
* @param {HTMLElement} host
|
|
18
18
|
*/
|
|
19
|
-
constructor(host) {
|
|
19
|
+
constructor(host, callback) {
|
|
20
20
|
/**
|
|
21
21
|
* The controller host element.
|
|
22
22
|
*
|
|
23
23
|
* @type {HTMLElement}
|
|
24
24
|
*/
|
|
25
25
|
this.host = host;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The callback used to detect which element
|
|
29
|
+
* to use as a target. Defaults to the host.
|
|
30
|
+
*
|
|
31
|
+
* @type {Function}
|
|
32
|
+
*/
|
|
33
|
+
this.callback = typeof callback === 'function' ? callback : () => host;
|
|
26
34
|
}
|
|
27
35
|
|
|
28
36
|
/**
|
|
@@ -33,7 +41,8 @@ export class AriaModalController {
|
|
|
33
41
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/showModal
|
|
34
42
|
*/
|
|
35
43
|
showModal() {
|
|
36
|
-
|
|
44
|
+
const targets = this.callback();
|
|
45
|
+
this.__showOthers = hideOthers(targets);
|
|
37
46
|
}
|
|
38
47
|
|
|
39
48
|
/**
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 - 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A controller for saving a focused node and restoring focus to it later.
|
|
10
|
+
*/
|
|
11
|
+
export declare function FocusRestorationController<T extends Constructor<HTMLElement>>(
|
|
12
|
+
base: T,
|
|
13
|
+
): Constructor<FocusRestorationControllerClass> & T;
|
|
14
|
+
|
|
15
|
+
export declare class FocusRestorationControllerClass {
|
|
16
|
+
/**
|
|
17
|
+
* Saves the given node as a target for restoring focus to
|
|
18
|
+
* when `restoreFocus()` is called. If no node is provided,
|
|
19
|
+
* the currently focused node in the DOM is saved as a target.
|
|
20
|
+
*/
|
|
21
|
+
saveFocus(node: Node | null | undefined): void;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Restores focus to the target node that was saved previously with `saveFocus()`.
|
|
25
|
+
*/
|
|
26
|
+
restoreFocus(): void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 - 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { getDeepActiveElement } from './focus-utils.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A controller for saving a focused node and restoring focus to it later.
|
|
10
|
+
*/
|
|
11
|
+
export class FocusRestorationController {
|
|
12
|
+
/**
|
|
13
|
+
* Saves the given node as a target for restoring focus to
|
|
14
|
+
* when `restoreFocus()` is called. If no node is provided,
|
|
15
|
+
* the currently focused node in the DOM is saved as a target.
|
|
16
|
+
*
|
|
17
|
+
* @param {Node | null | undefined} focusNode
|
|
18
|
+
*/
|
|
19
|
+
saveFocus(focusNode) {
|
|
20
|
+
this.focusNode = focusNode || getDeepActiveElement();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Restores focus to the target node that was saved previously with `saveFocus()`.
|
|
25
|
+
*/
|
|
26
|
+
restoreFocus() {
|
|
27
|
+
const focusNode = this.focusNode;
|
|
28
|
+
if (!focusNode) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (getDeepActiveElement() === document.body) {
|
|
33
|
+
// In Firefox and Safari, focusing the node synchronously
|
|
34
|
+
// doesn't work as expected when the overlay is closing on outside click.
|
|
35
|
+
// These browsers force focus to move to the body element and retain it
|
|
36
|
+
// there until the next event loop iteration.
|
|
37
|
+
setTimeout(() => focusNode.focus());
|
|
38
|
+
} else {
|
|
39
|
+
focusNode.focus();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
this.focusNode = null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 - 2023 Vaadin Ltd..
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @note Taken from Gaël Poupard gist
|
|
9
|
+
* @author Gaël Poupard
|
|
10
|
+
* @see https://gist.github.com/ffoodd/000b59f431e3e64e4ce1a24d5bb36034
|
|
11
|
+
*/
|
|
12
|
+
import { css } from 'lit';
|
|
13
|
+
|
|
14
|
+
export const screenReaderOnly = css`
|
|
15
|
+
.sr-only {
|
|
16
|
+
border: 0 !important;
|
|
17
|
+
clip: rect(1px, 1px, 1px, 1px) !important;
|
|
18
|
+
-webkit-clip-path: inset(50%) !important;
|
|
19
|
+
clip-path: inset(50%) !important;
|
|
20
|
+
height: 1px !important;
|
|
21
|
+
margin: -1px !important;
|
|
22
|
+
overflow: hidden !important;
|
|
23
|
+
padding: 0 !important;
|
|
24
|
+
position: absolute !important;
|
|
25
|
+
width: 1px !important;
|
|
26
|
+
white-space: nowrap !important;
|
|
27
|
+
}
|
|
28
|
+
`;
|