@vaadin/component-base 23.0.0-alpha4 → 23.0.0-beta3
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/package.json +2 -2
- package/src/a11y-announcer.d.ts +1 -1
- package/src/a11y-announcer.js +17 -1
- package/src/element-mixin.js +1 -1
- package/src/focus-trap-controller.js +2 -1
- package/src/focus-utils.js +3 -3
- package/src/media-query-controller.d.ts +30 -0
- package/src/media-query-controller.js +67 -0
- package/src/slot-controller.js +6 -2
- package/src/tabindex-mixin.js +3 -1
package/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { ElementMixin } from './src/element-mixin.js';
|
|
|
6
6
|
export { FocusMixin } from './src/focus-mixin.js';
|
|
7
7
|
export { FocusTrapController } from './src/focus-trap-controller.js';
|
|
8
8
|
export { KeyboardMixin } from './src/keyboard-mixin.js';
|
|
9
|
+
export { ResizeMixin } from './src/resize-mixin.js';
|
|
9
10
|
export { SlotController } from './src/slot-controller.js';
|
|
10
11
|
export { SlotMixin } from './src/slot-mixin.js';
|
|
11
12
|
export { TabindexMixin } from './src/tabindex-mixin.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/component-base",
|
|
3
|
-
"version": "23.0.0-
|
|
3
|
+
"version": "23.0.0-beta3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"@vaadin/testing-helpers": "^0.3.2",
|
|
43
43
|
"sinon": "^9.2.4"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "4c87216666541f9eb58f56c475964727822aad53"
|
|
46
46
|
}
|
package/src/a11y-announcer.d.ts
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* Cause a text string to be announced by screen readers.
|
|
9
9
|
*/
|
|
10
|
-
export function announce(text: string, options?: { mode?: 'polite' | 'assertive'; timeout?: number }): void;
|
|
10
|
+
export function announce(text: string, options?: { mode?: 'polite' | 'assertive' | 'alert'; timeout?: number }): void;
|
package/src/a11y-announcer.js
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { animationFrame } from '@vaadin/component-base/src/async.js';
|
|
8
|
+
import { Debouncer } from '@vaadin/component-base/src/debounce.js';
|
|
9
|
+
|
|
7
10
|
const region = document.createElement('div');
|
|
8
11
|
|
|
9
12
|
region.style.position = 'fixed';
|
|
@@ -12,6 +15,7 @@ region.setAttribute('aria-live', 'polite');
|
|
|
12
15
|
|
|
13
16
|
document.body.appendChild(region);
|
|
14
17
|
|
|
18
|
+
let alertDebouncer;
|
|
15
19
|
/**
|
|
16
20
|
* Cause a text string to be announced by screen readers.
|
|
17
21
|
*
|
|
@@ -22,7 +26,19 @@ export function announce(text, options = {}) {
|
|
|
22
26
|
const mode = options.mode || 'polite';
|
|
23
27
|
const timeout = options.timeout === undefined ? 150 : options.timeout;
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
if (mode === 'alert') {
|
|
30
|
+
region.removeAttribute('aria-live');
|
|
31
|
+
region.removeAttribute('role');
|
|
32
|
+
alertDebouncer = Debouncer.debounce(alertDebouncer, animationFrame, () => {
|
|
33
|
+
region.setAttribute('role', 'alert');
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
if (alertDebouncer) {
|
|
37
|
+
alertDebouncer.cancel();
|
|
38
|
+
}
|
|
39
|
+
region.removeAttribute('role');
|
|
40
|
+
region.setAttribute('aria-live', mode);
|
|
41
|
+
}
|
|
26
42
|
|
|
27
43
|
region.textContent = '';
|
|
28
44
|
|
package/src/element-mixin.js
CHANGED
|
@@ -134,6 +134,7 @@ export class FocusTrapController {
|
|
|
134
134
|
* @private
|
|
135
135
|
*/
|
|
136
136
|
get __focusedElementIndex() {
|
|
137
|
-
|
|
137
|
+
const focusableElements = this.__focusableElements;
|
|
138
|
+
return focusableElements.indexOf(focusableElements.filter(isElementFocused).pop());
|
|
138
139
|
}
|
|
139
140
|
}
|
package/src/focus-utils.js
CHANGED
|
@@ -39,7 +39,7 @@ function isElementHiddenDirectly(element) {
|
|
|
39
39
|
* @return {number}
|
|
40
40
|
*/
|
|
41
41
|
function normalizeTabIndex(element) {
|
|
42
|
-
if (!isElementFocusable(element)
|
|
42
|
+
if (!isElementFocusable(element)) {
|
|
43
43
|
return -1;
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -116,8 +116,8 @@ function sortElementsByTabIndex(elements) {
|
|
|
116
116
|
* @private
|
|
117
117
|
*/
|
|
118
118
|
function collectFocusableNodes(node, result) {
|
|
119
|
-
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
120
|
-
// Don't traverse children if the node is not an HTML element.
|
|
119
|
+
if (node.nodeType !== Node.ELEMENT_NODE || isElementHiddenDirectly(node)) {
|
|
120
|
+
// Don't traverse children if the node is not an HTML element or not visible.
|
|
121
121
|
return false;
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { ReactiveController } from 'lit';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A controller for listening on media query changes.
|
|
10
|
+
*/
|
|
11
|
+
export class MediaQueryController implements ReactiveController {
|
|
12
|
+
/**
|
|
13
|
+
* @param {HTMLElement} host
|
|
14
|
+
*/
|
|
15
|
+
constructor(query: string, callback: (matches: boolean) => void);
|
|
16
|
+
|
|
17
|
+
hostConnected(): void;
|
|
18
|
+
|
|
19
|
+
hostDisconnected(): void;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The CSS media query to evaluate.
|
|
23
|
+
*/
|
|
24
|
+
protected query: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Function to call when media query changes.
|
|
28
|
+
*/
|
|
29
|
+
protected callback: (matches: boolean) => void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A controller for listening on media query changes.
|
|
9
|
+
*/
|
|
10
|
+
export class MediaQueryController {
|
|
11
|
+
constructor(query, callback) {
|
|
12
|
+
/**
|
|
13
|
+
* The CSS media query to evaluate.
|
|
14
|
+
*
|
|
15
|
+
* @type {string}
|
|
16
|
+
* @protected
|
|
17
|
+
*/
|
|
18
|
+
this.query = query;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Function to call when media query changes.
|
|
22
|
+
*
|
|
23
|
+
* @type {Function}
|
|
24
|
+
* @protected
|
|
25
|
+
*/
|
|
26
|
+
this.callback = callback;
|
|
27
|
+
|
|
28
|
+
this._boundQueryHandler = this._queryHandler.bind(this);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
hostConnected() {
|
|
32
|
+
this._removeListener();
|
|
33
|
+
|
|
34
|
+
this._mediaQuery = window.matchMedia(this.query);
|
|
35
|
+
|
|
36
|
+
this._addListener();
|
|
37
|
+
|
|
38
|
+
this._queryHandler(this._mediaQuery);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
hostDisconnected() {
|
|
42
|
+
this._removeListener();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** @private */
|
|
46
|
+
_addListener() {
|
|
47
|
+
if (this._mediaQuery) {
|
|
48
|
+
this._mediaQuery.addListener(this._boundQueryHandler);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @private */
|
|
53
|
+
_removeListener() {
|
|
54
|
+
if (this._mediaQuery) {
|
|
55
|
+
this._mediaQuery.removeListener(this._boundQueryHandler);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this._mediaQuery = null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @private */
|
|
62
|
+
_queryHandler(mediaQuery) {
|
|
63
|
+
if (typeof this.callback === 'function') {
|
|
64
|
+
this.callback(mediaQuery.matches);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
package/src/slot-controller.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
+
import { dashToCamelCase } from '@polymer/polymer/lib/utils/case-map.js';
|
|
6
7
|
import { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -30,10 +31,13 @@ export class SlotController extends EventTarget {
|
|
|
30
31
|
static generateId(slotName, host) {
|
|
31
32
|
const prefix = slotName || 'default';
|
|
32
33
|
|
|
34
|
+
// Support dash-case slot names e.g. "error-message"
|
|
35
|
+
const field = `${dashToCamelCase(prefix)}Id`;
|
|
36
|
+
|
|
33
37
|
// Maintain the unique ID counter for a given prefix.
|
|
34
|
-
this[
|
|
38
|
+
this[field] = 1 + this[field] || 0;
|
|
35
39
|
|
|
36
|
-
return `${prefix}-${host.localName}-${this[
|
|
40
|
+
return `${prefix}-${host.localName}-${this[field]}`;
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
hostConnected() {
|
package/src/tabindex-mixin.js
CHANGED
|
@@ -56,7 +56,9 @@ export const TabindexMixin = (superclass) =>
|
|
|
56
56
|
super._disabledChanged(disabled, oldDisabled);
|
|
57
57
|
|
|
58
58
|
if (disabled) {
|
|
59
|
-
this.
|
|
59
|
+
if (this.tabindex !== undefined) {
|
|
60
|
+
this.__lastTabIndex = this.tabindex;
|
|
61
|
+
}
|
|
60
62
|
this.tabindex = -1;
|
|
61
63
|
} else if (oldDisabled) {
|
|
62
64
|
this.tabindex = this.__lastTabIndex;
|