@vaadin/field-base 22.0.0-alpha1 → 22.0.0-alpha10
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 +10 -9
- package/index.js +10 -9
- package/package.json +25 -19
- package/src/aria-label-controller.d.ts +11 -0
- package/src/aria-label-controller.js +58 -0
- package/src/checked-mixin.d.ts +26 -0
- package/src/checked-mixin.js +54 -0
- package/src/delegate-focus-mixin.d.ts +7 -4
- package/src/delegate-focus-mixin.js +154 -72
- package/src/delegate-state-mixin.d.ts +23 -0
- package/src/delegate-state-mixin.js +125 -0
- package/src/field-mixin.d.ts +39 -0
- package/src/field-mixin.js +317 -0
- package/src/input-constraints-mixin.d.ts +28 -0
- package/src/input-constraints-mixin.js +126 -0
- package/src/input-control-mixin.d.ts +52 -0
- package/src/input-control-mixin.js +170 -0
- package/src/input-controller.d.ts +11 -0
- package/src/input-controller.js +35 -0
- package/src/input-field-mixin.d.ts +2 -22
- package/src/input-field-mixin.js +117 -168
- package/src/input-mixin.d.ts +22 -6
- package/src/input-mixin.js +161 -51
- package/src/label-mixin.d.ts +2 -2
- package/src/label-mixin.js +74 -60
- package/src/pattern-mixin.d.ts +32 -0
- package/src/pattern-mixin.js +72 -0
- package/src/shadow-focus-mixin.d.ts +21 -0
- package/src/shadow-focus-mixin.js +87 -0
- package/src/slot-controller.d.ts +8 -0
- package/src/slot-controller.js +36 -0
- package/src/slot-label-mixin.d.ts +20 -0
- package/src/slot-label-mixin.js +38 -0
- package/src/slot-styles-mixin.d.ts +24 -0
- package/src/slot-styles-mixin.js +76 -0
- package/src/slot-target-mixin.d.ts +32 -0
- package/src/slot-target-mixin.js +110 -0
- package/src/styles/clear-button-styles.d.ts +8 -0
- package/src/styles/clear-button-styles.js +21 -0
- package/src/styles/field-shared-styles.d.ts +8 -0
- package/src/styles/field-shared-styles.js +29 -0
- package/src/styles/input-field-container-styles.d.ts +8 -0
- package/src/styles/input-field-container-styles.js +16 -0
- package/src/styles/input-field-shared-styles.d.ts +8 -0
- package/src/styles/input-field-shared-styles.js +10 -0
- package/src/text-area-controller.d.ts +11 -0
- package/src/text-area-controller.js +38 -0
- package/src/validate-mixin.d.ts +1 -9
- package/src/validate-mixin.js +43 -118
- package/src/clear-button-mixin.d.ts +0 -32
- package/src/clear-button-mixin.js +0 -87
- package/src/disabled-mixin.d.ts +0 -23
- package/src/disabled-mixin.js +0 -48
- package/src/field-aria-mixin.d.ts +0 -24
- package/src/field-aria-mixin.js +0 -61
- package/src/focus-mixin.d.ts +0 -33
- package/src/focus-mixin.js +0 -104
- package/src/helper-text-mixin.d.ts +0 -24
- package/src/helper-text-mixin.js +0 -109
- package/src/input-aria-mixin.d.ts +0 -20
- package/src/input-aria-mixin.js +0 -69
- package/src/input-props-mixin.d.ts +0 -40
- package/src/input-props-mixin.js +0 -106
- package/src/slot-mixin.d.ts +0 -23
- package/src/slot-mixin.js +0 -55
- package/src/text-field-mixin.d.ts +0 -47
- package/src/text-field-mixin.js +0 -125
package/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { AriaLabelController } from './src/aria-label-controller.js';
|
|
2
|
+
export { CheckedMixin } from './src/checked-mixin.js';
|
|
2
3
|
export { DelegateFocusMixin } from './src/delegate-focus-mixin.js';
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export { InputAriaMixin } from './src/input-aria-mixin.js';
|
|
4
|
+
export { DelegateStateMixin } from './src/delegate-state-mixin.js';
|
|
5
|
+
export { FieldMixin } from './src/field-mixin.js';
|
|
6
|
+
export { InputController } from './src/input-controller.js';
|
|
7
|
+
export { InputControlMixin } from './src/input-control-mixin.js';
|
|
8
8
|
export { InputFieldMixin } from './src/input-field-mixin.js';
|
|
9
9
|
export { InputMixin } from './src/input-mixin.js';
|
|
10
|
-
export { InputPropsMixin } from './src/input-props-mixin.js';
|
|
11
10
|
export { LabelMixin } from './src/label-mixin.js';
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
11
|
+
export { PatternMixin } from './src/pattern-mixin.js';
|
|
12
|
+
export { ShadowFocusMixin } from './src/shadow-focus-mixin.js';
|
|
13
|
+
export { SlotStylesMixin } from './src/slot-styles-mixin.js';
|
|
14
|
+
export { TextAreaController } from './src/text-area-controller.js';
|
|
14
15
|
export { ValidateMixin } from './src/validate-mixin.js';
|
package/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { AriaLabelController } from './src/aria-label-controller.js';
|
|
2
|
+
export { CheckedMixin } from './src/checked-mixin.js';
|
|
2
3
|
export { DelegateFocusMixin } from './src/delegate-focus-mixin.js';
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export { InputAriaMixin } from './src/input-aria-mixin.js';
|
|
4
|
+
export { DelegateStateMixin } from './src/delegate-state-mixin.js';
|
|
5
|
+
export { FieldMixin } from './src/field-mixin.js';
|
|
6
|
+
export { InputController } from './src/input-controller.js';
|
|
7
|
+
export { InputControlMixin } from './src/input-control-mixin.js';
|
|
8
8
|
export { InputFieldMixin } from './src/input-field-mixin.js';
|
|
9
9
|
export { InputMixin } from './src/input-mixin.js';
|
|
10
|
-
export { InputPropsMixin } from './src/input-props-mixin.js';
|
|
11
10
|
export { LabelMixin } from './src/label-mixin.js';
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
11
|
+
export { PatternMixin } from './src/pattern-mixin.js';
|
|
12
|
+
export { ShadowFocusMixin } from './src/shadow-focus-mixin.js';
|
|
13
|
+
export { SlotStylesMixin } from './src/slot-styles-mixin.js';
|
|
14
|
+
export { TextAreaController } from './src/text-area-controller.js';
|
|
14
15
|
export { ValidateMixin } from './src/validate-mixin.js';
|
package/package.json
CHANGED
|
@@ -1,36 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/field-base",
|
|
3
|
-
"version": "22.0.0-
|
|
3
|
+
"version": "22.0.0-alpha10",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
4
7
|
"description": "Vaadin field base mixins",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"module": "index.js",
|
|
7
|
-
"repository": "vaadin/web-components",
|
|
8
|
-
"keywords": [
|
|
9
|
-
"Vaadin",
|
|
10
|
-
"web-components",
|
|
11
|
-
"web-component"
|
|
12
|
-
],
|
|
13
|
-
"author": "Vaadin Ltd",
|
|
14
8
|
"license": "Apache-2.0",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/vaadin/web-components.git",
|
|
12
|
+
"directory": "packages/field-base"
|
|
13
|
+
},
|
|
14
|
+
"author": "Vaadin Ltd",
|
|
15
|
+
"homepage": "https://vaadin.com/components",
|
|
15
16
|
"bugs": {
|
|
16
17
|
"url": "https://github.com/vaadin/web-components"
|
|
17
18
|
},
|
|
18
|
-
"
|
|
19
|
+
"main": "index.js",
|
|
20
|
+
"module": "index.js",
|
|
19
21
|
"files": [
|
|
20
|
-
"index.js",
|
|
21
22
|
"index.d.ts",
|
|
23
|
+
"index.js",
|
|
22
24
|
"src"
|
|
23
25
|
],
|
|
26
|
+
"keywords": [
|
|
27
|
+
"Vaadin",
|
|
28
|
+
"web-components",
|
|
29
|
+
"web-component"
|
|
30
|
+
],
|
|
24
31
|
"dependencies": {
|
|
25
|
-
"@polymer/polymer": "^3.0.0"
|
|
32
|
+
"@polymer/polymer": "^3.0.0",
|
|
33
|
+
"@vaadin/component-base": "22.0.0-alpha10",
|
|
34
|
+
"lit": "^2.0.0"
|
|
26
35
|
},
|
|
27
36
|
"devDependencies": {
|
|
28
|
-
"@esm-bundle/chai": "^4.
|
|
29
|
-
"@vaadin/testing-helpers": "^0.
|
|
37
|
+
"@esm-bundle/chai": "^4.3.4",
|
|
38
|
+
"@vaadin/testing-helpers": "^0.3.0",
|
|
30
39
|
"sinon": "^9.2.1"
|
|
31
40
|
},
|
|
32
|
-
"
|
|
33
|
-
"access": "public"
|
|
34
|
-
},
|
|
35
|
-
"gitHead": "c9694d6549bff1f7fffb9ece26178e57fc228a51"
|
|
41
|
+
"gitHead": "6d3055383b9c3c8306ea34c6f2e2087e63c49348"
|
|
36
42
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 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 to link an input element with a slotted `<label>` element.
|
|
10
|
+
*/
|
|
11
|
+
export class AriaLabelController implements ReactiveController {}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 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 to link an input element with a slotted `<label>` element.
|
|
9
|
+
*/
|
|
10
|
+
export class AriaLabelController {
|
|
11
|
+
constructor(host, input, label) {
|
|
12
|
+
this.input = input;
|
|
13
|
+
this.__preventDuplicateLabelClick = this.__preventDuplicateLabelClick.bind(this);
|
|
14
|
+
|
|
15
|
+
if (label) {
|
|
16
|
+
label.addEventListener('click', this.__preventDuplicateLabelClick);
|
|
17
|
+
|
|
18
|
+
if (input) {
|
|
19
|
+
label.setAttribute('for', input.id);
|
|
20
|
+
|
|
21
|
+
this.__setAriaLabelledBy(input, host.hasAttribute('has-label') ? label.id : null);
|
|
22
|
+
host.addEventListener('has-label-changed', (event) =>
|
|
23
|
+
this.__setAriaLabelledBy(input, event.detail.value ? label.id : null)
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The native platform fires an event for both the click on the label, and also
|
|
31
|
+
* the subsequent click on the native input element caused by label click.
|
|
32
|
+
* This results in two click events arriving at the host, but we only want one.
|
|
33
|
+
* This method prevents the duplicate click and ensures the correct isTrusted event
|
|
34
|
+
* with the correct event.target arrives at the host.
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
__preventDuplicateLabelClick() {
|
|
38
|
+
const inputClickHandler = (e) => {
|
|
39
|
+
e.stopImmediatePropagation();
|
|
40
|
+
this.input.removeEventListener('click', inputClickHandler);
|
|
41
|
+
};
|
|
42
|
+
this.input.addEventListener('click', inputClickHandler);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Sets or removes the `aria-labelledby` attribute on the input element.
|
|
47
|
+
* @param {HTMLElement} input
|
|
48
|
+
* @param {string | null | undefined} value
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
__setAriaLabelledBy(input, value) {
|
|
52
|
+
if (value) {
|
|
53
|
+
input.setAttribute('aria-labelledby', value);
|
|
54
|
+
} else {
|
|
55
|
+
input.removeAttribute('aria-labelledby');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { DisabledMixin } from '@vaadin/component-base/src/disabled-mixin.js';
|
|
7
|
+
import { DelegateStateMixin } from './delegate-state-mixin.js';
|
|
8
|
+
import { InputMixin } from './input-mixin.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A mixin to manage the checked state.
|
|
12
|
+
*/
|
|
13
|
+
declare function CheckedMixin<T extends new (...args: any[]) => {}>(base: T): T & CheckedMixinConstructor;
|
|
14
|
+
|
|
15
|
+
interface CheckedMixinConstructor {
|
|
16
|
+
new (...args: any[]): CheckedMixin;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface CheckedMixin extends DelegateStateMixin, DisabledMixin, InputMixin {
|
|
20
|
+
/**
|
|
21
|
+
* True if the element is checked.
|
|
22
|
+
*/
|
|
23
|
+
checked: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { CheckedMixinConstructor, CheckedMixin };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 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 { DisabledMixin } from '@vaadin/component-base/src/disabled-mixin.js';
|
|
8
|
+
import { DelegateStateMixin } from './delegate-state-mixin.js';
|
|
9
|
+
import { InputMixin } from './input-mixin.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A mixin to manage the checked state.
|
|
13
|
+
*
|
|
14
|
+
* @polymerMixin
|
|
15
|
+
* @mixes DelegateStateMixin
|
|
16
|
+
* @mixes DisabledMixin
|
|
17
|
+
* @mixes InputMixin
|
|
18
|
+
*/
|
|
19
|
+
export const CheckedMixin = dedupingMixin(
|
|
20
|
+
(superclass) =>
|
|
21
|
+
class CheckedMixinClass extends DelegateStateMixin(DisabledMixin(InputMixin(superclass))) {
|
|
22
|
+
static get properties() {
|
|
23
|
+
return {
|
|
24
|
+
/**
|
|
25
|
+
* True if the element is checked.
|
|
26
|
+
* @type {boolean}
|
|
27
|
+
*/
|
|
28
|
+
checked: {
|
|
29
|
+
type: Boolean,
|
|
30
|
+
value: false,
|
|
31
|
+
notify: true,
|
|
32
|
+
reflectToAttribute: true
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static get delegateProps() {
|
|
38
|
+
return [...super.delegateProps, 'checked'];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @protected
|
|
43
|
+
* @override
|
|
44
|
+
*/
|
|
45
|
+
_onChange(event) {
|
|
46
|
+
this._toggleChecked(event.target.checked);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @protected */
|
|
50
|
+
_toggleChecked(checked) {
|
|
51
|
+
this.checked = checked;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
);
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Copyright (c) 2021 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { DisabledMixin } from '@vaadin/component-base/src/disabled-mixin.js';
|
|
7
|
+
import { FocusMixin } from '@vaadin/component-base/src/focus-mixin.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* A mixin to forward focus to an element in the light DOM.
|
|
@@ -22,8 +22,11 @@ interface DelegateFocusMixin extends DisabledMixin, FocusMixin {
|
|
|
22
22
|
autofocus: boolean;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
26
|
-
* It
|
|
25
|
+
* A reference to the focusable element controlled by the mixin.
|
|
26
|
+
* It can be an input, textarea, button or any element with tabindex > -1.
|
|
27
|
+
*
|
|
28
|
+
* Any component implementing this mixin is expected to provide it
|
|
29
|
+
* by using `this._setFocusElement(input)` Polymer API.
|
|
27
30
|
*/
|
|
28
31
|
readonly focusElement: Element | null | undefined;
|
|
29
32
|
}
|
|
@@ -4,94 +4,176 @@
|
|
|
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';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
import { DisabledMixin } from '@vaadin/component-base/src/disabled-mixin.js';
|
|
8
|
+
import { FocusMixin } from '@vaadin/component-base/src/focus-mixin.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A mixin to forward focus to an element in the light DOM.
|
|
12
|
+
*
|
|
13
|
+
* @polymerMixin
|
|
14
|
+
* @mixes DisabledMixin
|
|
15
|
+
* @mixes FocusMixin
|
|
16
|
+
*/
|
|
17
|
+
export const DelegateFocusMixin = dedupingMixin(
|
|
18
|
+
(superclass) =>
|
|
19
|
+
class DelegateFocusMixinClass extends FocusMixin(DisabledMixin(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
|
+
* @protected
|
|
37
|
+
* @type {!HTMLElement}
|
|
38
|
+
*/
|
|
39
|
+
focusElement: {
|
|
40
|
+
type: Object,
|
|
41
|
+
readOnly: true,
|
|
42
|
+
observer: '_focusElementChanged'
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
constructor() {
|
|
48
|
+
super();
|
|
49
|
+
|
|
50
|
+
this._boundOnBlur = this._onBlur.bind(this);
|
|
51
|
+
this._boundOnFocus = this._onFocus.bind(this);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** @protected */
|
|
55
|
+
ready() {
|
|
56
|
+
super.ready();
|
|
57
|
+
|
|
58
|
+
if (this.autofocus && !this.disabled) {
|
|
59
|
+
requestAnimationFrame(() => {
|
|
60
|
+
this.focus();
|
|
61
|
+
this.setAttribute('focus-ring', '');
|
|
62
|
+
});
|
|
19
63
|
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
64
|
+
}
|
|
22
65
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
66
|
+
/**
|
|
67
|
+
* @protected
|
|
68
|
+
* @override
|
|
69
|
+
*/
|
|
70
|
+
focus() {
|
|
71
|
+
if (!this.focusElement || this.disabled) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
32
74
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
75
|
+
this.focusElement.focus();
|
|
76
|
+
this._setFocused(true);
|
|
77
|
+
}
|
|
36
78
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
79
|
+
/**
|
|
80
|
+
* @protected
|
|
81
|
+
* @override
|
|
82
|
+
*/
|
|
83
|
+
blur() {
|
|
84
|
+
if (!this.focusElement) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
this.focusElement.blur();
|
|
88
|
+
this._setFocused(false);
|
|
42
89
|
}
|
|
43
|
-
}
|
|
44
90
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
91
|
+
/**
|
|
92
|
+
* @protected
|
|
93
|
+
* @override
|
|
94
|
+
*/
|
|
95
|
+
click() {
|
|
96
|
+
if (this.focusElement && !this.disabled) {
|
|
97
|
+
this.focusElement.click();
|
|
98
|
+
}
|
|
48
99
|
}
|
|
49
100
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
101
|
+
/** @protected */
|
|
102
|
+
_focusElementChanged(element, oldElement) {
|
|
103
|
+
if (element) {
|
|
104
|
+
element.disabled = this.disabled;
|
|
105
|
+
this._addFocusListeners(element);
|
|
106
|
+
} else if (oldElement) {
|
|
107
|
+
this._removeFocusListeners(oldElement);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
53
110
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
111
|
+
/**
|
|
112
|
+
* @param {HTMLElement} element
|
|
113
|
+
* @protected
|
|
114
|
+
*/
|
|
115
|
+
_addFocusListeners(element) {
|
|
116
|
+
element.addEventListener('blur', this._boundOnBlur);
|
|
117
|
+
element.addEventListener('focus', this._boundOnFocus);
|
|
57
118
|
}
|
|
58
|
-
this.focusElement.blur();
|
|
59
|
-
this._setFocused(false);
|
|
60
|
-
}
|
|
61
119
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
120
|
+
/**
|
|
121
|
+
* @param {HTMLElement} element
|
|
122
|
+
* @protected
|
|
123
|
+
*/
|
|
124
|
+
_removeFocusListeners(element) {
|
|
125
|
+
element.removeEventListener('blur', this._boundOnBlur);
|
|
126
|
+
element.removeEventListener('focus', this._boundOnFocus);
|
|
65
127
|
}
|
|
66
|
-
}
|
|
67
128
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Focus event does not bubble, so we dispatch it manually
|
|
131
|
+
* on the host element to support adding focus listeners
|
|
132
|
+
* when the focusable element is placed in light DOM.
|
|
133
|
+
* @param {FocusEvent} event
|
|
134
|
+
* @protected
|
|
135
|
+
*/
|
|
136
|
+
_onFocus(event) {
|
|
137
|
+
event.stopPropagation();
|
|
138
|
+
this.dispatchEvent(new Event('focus'));
|
|
139
|
+
}
|
|
76
140
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Blur event does not bubble, so we dispatch it manually
|
|
143
|
+
* on the host element to support adding blur listeners
|
|
144
|
+
* when the focusable element is placed in light DOM.
|
|
145
|
+
* @param {FocusEvent} event
|
|
146
|
+
* @protected
|
|
147
|
+
*/
|
|
148
|
+
_onBlur(event) {
|
|
149
|
+
event.stopPropagation();
|
|
150
|
+
this.dispatchEvent(new Event('blur'));
|
|
151
|
+
}
|
|
83
152
|
|
|
84
|
-
|
|
85
|
-
|
|
153
|
+
/**
|
|
154
|
+
* @param {Event} event
|
|
155
|
+
* @return {boolean}
|
|
156
|
+
* @protected
|
|
157
|
+
* @override
|
|
158
|
+
*/
|
|
159
|
+
_shouldSetFocus(event) {
|
|
160
|
+
return event.target === this.focusElement;
|
|
86
161
|
}
|
|
87
162
|
|
|
88
|
-
|
|
89
|
-
|
|
163
|
+
/**
|
|
164
|
+
* @param {boolean} disabled
|
|
165
|
+
* @protected
|
|
166
|
+
*/
|
|
167
|
+
_disabledChanged(disabled) {
|
|
168
|
+
super._disabledChanged(disabled);
|
|
169
|
+
|
|
170
|
+
if (this.focusElement) {
|
|
171
|
+
this.focusElement.disabled = disabled;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (disabled) {
|
|
175
|
+
this.blur();
|
|
176
|
+
}
|
|
90
177
|
}
|
|
91
178
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* A mixin to forward focus to an element in the light DOM.
|
|
96
|
-
*/
|
|
97
|
-
export const DelegateFocusMixin = dedupingMixin(DelegateFocusMixinImplementation);
|
|
179
|
+
);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2021 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A mixin to delegate properties and attributes to a target element.
|
|
9
|
+
*/
|
|
10
|
+
declare function DelegateStateMixin<T extends new (...args: any[]) => {}>(base: T): T & DelegateStateMixinConstructor;
|
|
11
|
+
|
|
12
|
+
interface DelegateStateMixinConstructor {
|
|
13
|
+
new (...args: any[]): DelegateStateMixin;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface DelegateStateMixin {
|
|
17
|
+
/**
|
|
18
|
+
* A target element to which attributes and properties are delegated.
|
|
19
|
+
*/
|
|
20
|
+
stateTarget: HTMLElement | null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { DelegateStateMixinConstructor, DelegateStateMixin };
|