@vaadin/component-base 23.2.14 → 23.2.16
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/custom_typings/vaadin-usage-statistics.d.ts +2 -2
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/package.json +3 -3
- package/src/a11y-announcer.d.ts +1 -1
- package/src/a11y-announcer.js +1 -1
- package/src/active-mixin.d.ts +1 -1
- package/src/active-mixin.js +1 -1
- package/src/async.d.ts +3 -0
- package/src/async.js +2 -1
- package/src/browser-utils.js +7 -7
- package/src/controller-mixin.d.ts +1 -1
- package/src/controller-mixin.js +1 -1
- package/src/debounce.js +2 -2
- package/src/delegate-focus-mixin.d.ts +48 -0
- package/src/delegate-focus-mixin.js +228 -0
- package/src/delegate-state-mixin.d.ts +20 -0
- package/src/delegate-state-mixin.js +125 -0
- package/src/dir-mixin.d.ts +2 -4
- package/src/dir-mixin.js +17 -39
- package/src/dir-utils.d.ts +19 -0
- package/src/dir-utils.js +36 -0
- package/src/disabled-mixin.d.ts +1 -1
- package/src/disabled-mixin.js +1 -1
- package/src/dom-utils.d.ts +6 -1
- package/src/dom-utils.js +11 -1
- package/src/element-mixin.d.ts +1 -1
- package/src/element-mixin.js +11 -5
- package/src/focus-mixin.d.ts +1 -1
- package/src/focus-mixin.js +2 -2
- package/src/focus-trap-controller.d.ts +1 -1
- package/src/focus-trap-controller.js +22 -22
- package/src/focus-utils.d.ts +1 -1
- package/src/focus-utils.js +57 -57
- package/src/gestures.d.ts +6 -12
- package/src/gestures.js +6 -4
- package/src/iron-list-core.js +22 -44
- package/src/keyboard-direction-mixin.d.ts +41 -0
- package/src/keyboard-direction-mixin.js +192 -0
- package/src/keyboard-mixin.d.ts +1 -1
- package/src/keyboard-mixin.js +1 -1
- package/src/list-mixin.d.ts +57 -0
- package/src/list-mixin.js +354 -0
- package/src/media-query-controller.d.ts +1 -1
- package/src/media-query-controller.js +1 -1
- package/src/overflow-controller.d.ts +1 -1
- package/src/overflow-controller.js +3 -3
- package/src/overlay-class-mixin.d.ts +33 -0
- package/src/overlay-class-mixin.js +79 -0
- package/src/polylit-mixin.d.ts +3 -3
- package/src/polylit-mixin.js +9 -4
- package/src/resize-mixin.d.ts +1 -1
- package/src/resize-mixin.js +11 -21
- package/src/slot-child-observe-controller.d.ts +28 -0
- package/src/slot-child-observe-controller.js +176 -0
- package/src/slot-controller.d.ts +33 -5
- package/src/slot-controller.js +103 -40
- package/src/tabindex-mixin.d.ts +1 -1
- package/src/tabindex-mixin.js +1 -1
- package/src/templates.js +1 -1
- package/src/tooltip-controller.d.ts +86 -0
- package/src/tooltip-controller.js +130 -0
- package/src/unique-id-utils.d.ts +1 -1
- package/src/unique-id-utils.js +1 -1
- package/src/virtualizer-iron-list-adapter.js +56 -2
- package/src/virtualizer.js +18 -18
- package/src/dir-helper.d.ts +0 -42
- package/src/dir-helper.js +0 -93
- package/src/slot-mixin.d.ts +0 -18
- package/src/slot-mixin.js +0 -60
package/index.d.ts
CHANGED
|
@@ -8,5 +8,4 @@ export { FocusTrapController } from './src/focus-trap-controller.js';
|
|
|
8
8
|
export { KeyboardMixin } from './src/keyboard-mixin.js';
|
|
9
9
|
export { ResizeMixin } from './src/resize-mixin.js';
|
|
10
10
|
export { SlotController } from './src/slot-controller.js';
|
|
11
|
-
export { SlotMixin } from './src/slot-mixin.js';
|
|
12
11
|
export { TabindexMixin } from './src/tabindex-mixin.js';
|
package/index.js
CHANGED
|
@@ -7,5 +7,4 @@ 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
9
|
export { SlotController } from './src/slot-controller.js';
|
|
10
|
-
export { SlotMixin } from './src/slot-mixin.js';
|
|
11
10
|
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.2.
|
|
3
|
+
"version": "23.2.16",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@esm-bundle/chai": "^4.3.4",
|
|
42
|
-
"@vaadin/testing-helpers": "^0.
|
|
42
|
+
"@vaadin/testing-helpers": "^0.4.0",
|
|
43
43
|
"sinon": "^13.0.2"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "57010013e59a3ecdc70ceef4377dbc3b1ac03fb3"
|
|
46
46
|
}
|
package/src/a11y-announcer.d.ts
CHANGED
package/src/a11y-announcer.js
CHANGED
package/src/active-mixin.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2023 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import type { Constructor } from '@open-wc/dedupe-mixin';
|
package/src/active-mixin.js
CHANGED
package/src/async.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
export interface AsyncInterface {
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
12
13
|
run(fn: Function, delay?: number): number;
|
|
13
14
|
cancel(handle: number): void;
|
|
14
15
|
}
|
|
@@ -39,6 +40,7 @@ declare namespace timeOut {
|
|
|
39
40
|
*
|
|
40
41
|
* @returns Handle used for canceling task
|
|
41
42
|
*/
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
42
44
|
function run(fn: Function, delay?: number): number;
|
|
43
45
|
|
|
44
46
|
/**
|
|
@@ -103,6 +105,7 @@ declare namespace microTask {
|
|
|
103
105
|
*
|
|
104
106
|
* @returns Handle used for canceling task
|
|
105
107
|
*/
|
|
108
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
106
109
|
function run(callback?: Function): number;
|
|
107
110
|
|
|
108
111
|
/**
|
package/src/async.js
CHANGED
|
@@ -27,7 +27,6 @@ const microtaskCallbacks = [];
|
|
|
27
27
|
let microtaskNodeContent = 0;
|
|
28
28
|
let microtaskScheduled = false;
|
|
29
29
|
const microtaskNode = document.createTextNode('');
|
|
30
|
-
new window.MutationObserver(microtaskFlush).observe(microtaskNode, { characterData: true });
|
|
31
30
|
|
|
32
31
|
function microtaskFlush() {
|
|
33
32
|
microtaskScheduled = false;
|
|
@@ -48,6 +47,8 @@ function microtaskFlush() {
|
|
|
48
47
|
microtaskLastHandle += len;
|
|
49
48
|
}
|
|
50
49
|
|
|
50
|
+
new window.MutationObserver(microtaskFlush).observe(microtaskNode, { characterData: true });
|
|
51
|
+
|
|
51
52
|
/**
|
|
52
53
|
* Async interface wrapper around `setTimeout`.
|
|
53
54
|
*
|
package/src/browser-utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2023 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -10,20 +10,20 @@ const testPlatform = (regexp) => regexp.test(navigator.platform);
|
|
|
10
10
|
|
|
11
11
|
const testVendor = (regexp) => regexp.test(navigator.vendor);
|
|
12
12
|
|
|
13
|
-
export const isAndroid = testUserAgent(/Android/);
|
|
13
|
+
export const isAndroid = testUserAgent(/Android/u);
|
|
14
14
|
|
|
15
|
-
export const isChrome = testUserAgent(/Chrome/) && testVendor(/Google Inc/);
|
|
15
|
+
export const isChrome = testUserAgent(/Chrome/u) && testVendor(/Google Inc/u);
|
|
16
16
|
|
|
17
|
-
export const isFirefox = testUserAgent(/Firefox/);
|
|
17
|
+
export const isFirefox = testUserAgent(/Firefox/u);
|
|
18
18
|
|
|
19
19
|
// IPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.
|
|
20
|
-
export const isIPad = testPlatform(/^iPad/) || (testPlatform(/^Mac/) && navigator.maxTouchPoints > 1);
|
|
20
|
+
export const isIPad = testPlatform(/^iPad/u) || (testPlatform(/^Mac/u) && navigator.maxTouchPoints > 1);
|
|
21
21
|
|
|
22
|
-
export const isIPhone = testPlatform(/^iPhone/);
|
|
22
|
+
export const isIPhone = testPlatform(/^iPhone/u);
|
|
23
23
|
|
|
24
24
|
export const isIOS = isIPhone || isIPad;
|
|
25
25
|
|
|
26
|
-
export const isSafari = testUserAgent(/^((?!chrome|android).)*safari/
|
|
26
|
+
export const isSafari = testUserAgent(/^((?!chrome|android).)*safari/iu);
|
|
27
27
|
|
|
28
28
|
export const isTouch = (() => {
|
|
29
29
|
try {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2023 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import type { Constructor } from '@open-wc/dedupe-mixin';
|
package/src/controller-mixin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2023 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
package/src/debounce.js
CHANGED
|
@@ -8,6 +8,8 @@ Code distributed by Google as part of the polymer project is also
|
|
|
8
8
|
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
const debouncerQueue = new Set();
|
|
12
|
+
|
|
11
13
|
/**
|
|
12
14
|
* @summary Collapse multiple callbacks into one invocation after a timer.
|
|
13
15
|
*/
|
|
@@ -133,8 +135,6 @@ export class Debouncer {
|
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
137
|
|
|
136
|
-
let debouncerQueue = new Set();
|
|
137
|
-
|
|
138
138
|
/**
|
|
139
139
|
* Adds a `Debouncer` to a list of globally flushable tasks.
|
|
140
140
|
*
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
import type { DisabledMixinClass } from './disabled-mixin.js';
|
|
8
|
+
import type { FocusMixinClass } from './focus-mixin.js';
|
|
9
|
+
import type { TabindexMixinClass } from './tabindex-mixin.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A mixin to forward focus to an element in the light DOM.
|
|
13
|
+
*/
|
|
14
|
+
export declare function DelegateFocusMixin<T extends Constructor<HTMLElement>>(
|
|
15
|
+
base: T,
|
|
16
|
+
): Constructor<DelegateFocusMixinClass> &
|
|
17
|
+
Constructor<DisabledMixinClass> &
|
|
18
|
+
Constructor<FocusMixinClass> &
|
|
19
|
+
Constructor<TabindexMixinClass> &
|
|
20
|
+
T;
|
|
21
|
+
|
|
22
|
+
export declare class DelegateFocusMixinClass {
|
|
23
|
+
/**
|
|
24
|
+
* Specify that this control should have input focus when the page loads.
|
|
25
|
+
*/
|
|
26
|
+
autofocus: boolean;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A reference to the focusable element controlled by the mixin.
|
|
30
|
+
* It can be an input, textarea, button or any element with tabindex > -1.
|
|
31
|
+
*
|
|
32
|
+
* Any component implementing this mixin is expected to provide it
|
|
33
|
+
* by using `this._setFocusElement(input)` Polymer API.
|
|
34
|
+
*/
|
|
35
|
+
readonly focusElement: HTMLElement | null | undefined;
|
|
36
|
+
|
|
37
|
+
protected _addFocusListeners(element: HTMLElement): void;
|
|
38
|
+
|
|
39
|
+
protected _removeFocusListeners(element: HTMLElement): void;
|
|
40
|
+
|
|
41
|
+
protected _focusElementChanged(element: HTMLElement, oldElement: HTMLElement): void;
|
|
42
|
+
|
|
43
|
+
protected _onBlur(event: FocusEvent): void;
|
|
44
|
+
|
|
45
|
+
protected _onFocus(event: FocusEvent): void;
|
|
46
|
+
|
|
47
|
+
protected _setFocusElement(element: HTMLElement): void;
|
|
48
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
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 { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
7
|
+
import { FocusMixin } from './focus-mixin.js';
|
|
8
|
+
import { TabindexMixin } from './tabindex-mixin.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A mixin to forward focus to an element in the light DOM.
|
|
12
|
+
*
|
|
13
|
+
* @polymerMixin
|
|
14
|
+
* @mixes FocusMixin
|
|
15
|
+
* @mixes TabindexMixin
|
|
16
|
+
*/
|
|
17
|
+
export const DelegateFocusMixin = dedupingMixin(
|
|
18
|
+
(superclass) =>
|
|
19
|
+
class DelegateFocusMixinClass extends FocusMixin(TabindexMixin(superclass)) {
|
|
20
|
+
static get properties() {
|
|
21
|
+
return {
|
|
22
|
+
/**
|
|
23
|
+
* Specify that this control should have input focus when the page loads.
|
|
24
|
+
*/
|
|
25
|
+
autofocus: {
|
|
26
|
+
type: Boolean,
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A reference to the focusable element controlled by the mixin.
|
|
31
|
+
* It can be an input, textarea, button or any element with tabindex > -1.
|
|
32
|
+
*
|
|
33
|
+
* Any component implementing this mixin is expected to provide it
|
|
34
|
+
* by using `this._setFocusElement(input)` Polymer API.
|
|
35
|
+
*
|
|
36
|
+
* Toggling `tabindex` attribute on the host element propagates its value to `focusElement`.
|
|
37
|
+
*
|
|
38
|
+
* @protected
|
|
39
|
+
* @type {!HTMLElement}
|
|
40
|
+
*/
|
|
41
|
+
focusElement: {
|
|
42
|
+
type: Object,
|
|
43
|
+
readOnly: true,
|
|
44
|
+
observer: '_focusElementChanged',
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Override the property from `TabIndexMixin`
|
|
49
|
+
* to ensure the `tabindex` attribute of the focus element
|
|
50
|
+
* will be restored to `0` after re-enabling the element.
|
|
51
|
+
*
|
|
52
|
+
* @protected
|
|
53
|
+
* @override
|
|
54
|
+
*/
|
|
55
|
+
_lastTabIndex: {
|
|
56
|
+
value: 0,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
constructor() {
|
|
62
|
+
super();
|
|
63
|
+
|
|
64
|
+
this._boundOnBlur = this._onBlur.bind(this);
|
|
65
|
+
this._boundOnFocus = this._onFocus.bind(this);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** @protected */
|
|
69
|
+
ready() {
|
|
70
|
+
super.ready();
|
|
71
|
+
|
|
72
|
+
if (this.autofocus && !this.disabled) {
|
|
73
|
+
requestAnimationFrame(() => {
|
|
74
|
+
this.focus();
|
|
75
|
+
this.setAttribute('focus-ring', '');
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @protected
|
|
82
|
+
* @override
|
|
83
|
+
*/
|
|
84
|
+
focus() {
|
|
85
|
+
if (!this.focusElement || this.disabled) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
this.focusElement.focus();
|
|
90
|
+
this._setFocused(true);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @protected
|
|
95
|
+
* @override
|
|
96
|
+
*/
|
|
97
|
+
blur() {
|
|
98
|
+
if (!this.focusElement) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.focusElement.blur();
|
|
102
|
+
this._setFocused(false);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @protected
|
|
107
|
+
* @override
|
|
108
|
+
*/
|
|
109
|
+
click() {
|
|
110
|
+
if (this.focusElement && !this.disabled) {
|
|
111
|
+
this.focusElement.click();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** @protected */
|
|
116
|
+
_focusElementChanged(element, oldElement) {
|
|
117
|
+
if (element) {
|
|
118
|
+
element.disabled = this.disabled;
|
|
119
|
+
this._addFocusListeners(element);
|
|
120
|
+
this.__forwardTabIndex(this.tabindex);
|
|
121
|
+
} else if (oldElement) {
|
|
122
|
+
this._removeFocusListeners(oldElement);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @param {HTMLElement} element
|
|
128
|
+
* @protected
|
|
129
|
+
*/
|
|
130
|
+
_addFocusListeners(element) {
|
|
131
|
+
element.addEventListener('blur', this._boundOnBlur);
|
|
132
|
+
element.addEventListener('focus', this._boundOnFocus);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @param {HTMLElement} element
|
|
137
|
+
* @protected
|
|
138
|
+
*/
|
|
139
|
+
_removeFocusListeners(element) {
|
|
140
|
+
element.removeEventListener('blur', this._boundOnBlur);
|
|
141
|
+
element.removeEventListener('focus', this._boundOnFocus);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Focus event does not bubble, so we dispatch it manually
|
|
146
|
+
* on the host element to support adding focus listeners
|
|
147
|
+
* when the focusable element is placed in light DOM.
|
|
148
|
+
* @param {FocusEvent} event
|
|
149
|
+
* @protected
|
|
150
|
+
*/
|
|
151
|
+
_onFocus(event) {
|
|
152
|
+
event.stopPropagation();
|
|
153
|
+
this.dispatchEvent(new Event('focus'));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Blur event does not bubble, so we dispatch it manually
|
|
158
|
+
* on the host element to support adding blur listeners
|
|
159
|
+
* when the focusable element is placed in light DOM.
|
|
160
|
+
* @param {FocusEvent} event
|
|
161
|
+
* @protected
|
|
162
|
+
*/
|
|
163
|
+
_onBlur(event) {
|
|
164
|
+
event.stopPropagation();
|
|
165
|
+
this.dispatchEvent(new Event('blur'));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @param {Event} event
|
|
170
|
+
* @return {boolean}
|
|
171
|
+
* @protected
|
|
172
|
+
* @override
|
|
173
|
+
*/
|
|
174
|
+
_shouldSetFocus(event) {
|
|
175
|
+
return event.target === this.focusElement;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @param {boolean} disabled
|
|
180
|
+
* @param {boolean} oldDisabled
|
|
181
|
+
* @protected
|
|
182
|
+
* @override
|
|
183
|
+
*/
|
|
184
|
+
_disabledChanged(disabled, oldDisabled) {
|
|
185
|
+
super._disabledChanged(disabled, oldDisabled);
|
|
186
|
+
|
|
187
|
+
if (this.focusElement) {
|
|
188
|
+
this.focusElement.disabled = disabled;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (disabled) {
|
|
192
|
+
this.blur();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Override an observer from `TabindexMixin`.
|
|
198
|
+
* Do not call super to remove tabindex attribute
|
|
199
|
+
* from the host after it has been forwarded.
|
|
200
|
+
* @param {string} tabindex
|
|
201
|
+
* @protected
|
|
202
|
+
* @override
|
|
203
|
+
*/
|
|
204
|
+
_tabindexChanged(tabindex) {
|
|
205
|
+
this.__forwardTabIndex(tabindex);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** @private */
|
|
209
|
+
__forwardTabIndex(tabindex) {
|
|
210
|
+
if (tabindex !== undefined && this.focusElement) {
|
|
211
|
+
this.focusElement.tabIndex = tabindex;
|
|
212
|
+
|
|
213
|
+
// Preserve tabindex="-1" on the host element
|
|
214
|
+
if (tabindex !== -1) {
|
|
215
|
+
this.tabindex = undefined;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (this.disabled && tabindex) {
|
|
220
|
+
// If tabindex attribute was changed while component was disabled
|
|
221
|
+
if (tabindex !== -1) {
|
|
222
|
+
this._lastTabIndex = tabindex;
|
|
223
|
+
}
|
|
224
|
+
this.tabindex = undefined;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
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 mixin to delegate properties and attributes to a target element.
|
|
10
|
+
*/
|
|
11
|
+
export declare function DelegateStateMixin<T extends Constructor<HTMLElement>>(
|
|
12
|
+
base: T,
|
|
13
|
+
): Constructor<DelegateStateMixinClass> & T;
|
|
14
|
+
|
|
15
|
+
export declare class DelegateStateMixinClass {
|
|
16
|
+
/**
|
|
17
|
+
* A target element to which attributes and properties are delegated.
|
|
18
|
+
*/
|
|
19
|
+
stateTarget: HTMLElement | null;
|
|
20
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
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 { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A mixin to delegate properties and attributes to a target element.
|
|
10
|
+
*
|
|
11
|
+
* @polymerMixin
|
|
12
|
+
*/
|
|
13
|
+
export const DelegateStateMixin = dedupingMixin(
|
|
14
|
+
(superclass) =>
|
|
15
|
+
class DelegateStateMixinClass extends superclass {
|
|
16
|
+
static get properties() {
|
|
17
|
+
return {
|
|
18
|
+
/**
|
|
19
|
+
* A target element to which attributes and properties are delegated.
|
|
20
|
+
* @protected
|
|
21
|
+
*/
|
|
22
|
+
stateTarget: {
|
|
23
|
+
type: Object,
|
|
24
|
+
observer: '_stateTargetChanged',
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* An array of the host attributes to delegate to the target element.
|
|
31
|
+
*/
|
|
32
|
+
static get delegateAttrs() {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* An array of the host properties to delegate to the target element.
|
|
38
|
+
*/
|
|
39
|
+
static get delegateProps() {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @protected */
|
|
44
|
+
ready() {
|
|
45
|
+
super.ready();
|
|
46
|
+
|
|
47
|
+
this._createDelegateAttrsObserver();
|
|
48
|
+
this._createDelegatePropsObserver();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** @protected */
|
|
52
|
+
_stateTargetChanged(target) {
|
|
53
|
+
if (target) {
|
|
54
|
+
this._ensureAttrsDelegated();
|
|
55
|
+
this._ensurePropsDelegated();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @protected */
|
|
60
|
+
_createDelegateAttrsObserver() {
|
|
61
|
+
this._createMethodObserver(`_delegateAttrsChanged(${this.constructor.delegateAttrs.join(', ')})`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** @protected */
|
|
65
|
+
_createDelegatePropsObserver() {
|
|
66
|
+
this._createMethodObserver(`_delegatePropsChanged(${this.constructor.delegateProps.join(', ')})`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** @protected */
|
|
70
|
+
_ensureAttrsDelegated() {
|
|
71
|
+
this.constructor.delegateAttrs.forEach((name) => {
|
|
72
|
+
this._delegateAttribute(name, this[name]);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** @protected */
|
|
77
|
+
_ensurePropsDelegated() {
|
|
78
|
+
this.constructor.delegateProps.forEach((name) => {
|
|
79
|
+
this._delegateProperty(name, this[name]);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** @protected */
|
|
84
|
+
_delegateAttrsChanged(...values) {
|
|
85
|
+
this.constructor.delegateAttrs.forEach((name, index) => {
|
|
86
|
+
this._delegateAttribute(name, values[index]);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** @protected */
|
|
91
|
+
_delegatePropsChanged(...values) {
|
|
92
|
+
this.constructor.delegateProps.forEach((name, index) => {
|
|
93
|
+
this._delegateProperty(name, values[index]);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** @protected */
|
|
98
|
+
_delegateAttribute(name, value) {
|
|
99
|
+
if (!this.stateTarget) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (name === 'invalid') {
|
|
104
|
+
this._delegateAttribute('aria-invalid', value ? 'true' : false);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (typeof value === 'boolean') {
|
|
108
|
+
this.stateTarget.toggleAttribute(name, value);
|
|
109
|
+
} else if (value) {
|
|
110
|
+
this.stateTarget.setAttribute(name, value);
|
|
111
|
+
} else {
|
|
112
|
+
this.stateTarget.removeAttribute(name);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** @protected */
|
|
117
|
+
_delegateProperty(name, value) {
|
|
118
|
+
if (!this.stateTarget) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
this.stateTarget[name] = value;
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
);
|
package/src/dir-mixin.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2023 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
@@ -11,7 +11,5 @@ import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
|
11
11
|
export declare function DirMixin<T extends Constructor<HTMLElement>>(base: T): Constructor<DirMixinClass> & T;
|
|
12
12
|
|
|
13
13
|
export declare class DirMixinClass {
|
|
14
|
-
protected
|
|
15
|
-
|
|
16
|
-
protected __setNormalizedScrollLeft(element: Element | null, scrollLeft: number): void;
|
|
14
|
+
protected readonly __isRTL: boolean;
|
|
17
15
|
}
|