@vaadin/field-base 23.2.16 → 23.2.17

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.
Files changed (55) hide show
  1. package/index.d.ts +3 -0
  2. package/index.js +3 -0
  3. package/package.json +4 -4
  4. package/src/checked-mixin.d.ts +2 -2
  5. package/src/checked-mixin.js +2 -2
  6. package/src/delegate-focus-mixin.d.ts +48 -0
  7. package/src/delegate-focus-mixin.js +228 -0
  8. package/src/delegate-state-mixin.d.ts +20 -0
  9. package/src/delegate-state-mixin.js +125 -0
  10. package/src/error-controller.d.ts +8 -3
  11. package/src/error-controller.js +65 -53
  12. package/src/field-aria-controller.d.ts +1 -1
  13. package/src/field-aria-controller.js +11 -11
  14. package/src/field-mixin.d.ts +1 -1
  15. package/src/field-mixin.js +28 -24
  16. package/src/helper-controller.d.ts +5 -3
  17. package/src/helper-controller.js +147 -47
  18. package/src/input-constraints-mixin.d.ts +4 -2
  19. package/src/input-constraints-mixin.js +2 -2
  20. package/src/input-control-mixin.d.ts +3 -3
  21. package/src/input-control-mixin.js +4 -4
  22. package/src/input-controller.d.ts +1 -1
  23. package/src/input-controller.js +8 -5
  24. package/src/input-field-mixin.d.ts +3 -3
  25. package/src/input-field-mixin.js +10 -10
  26. package/src/input-mixin.d.ts +3 -5
  27. package/src/input-mixin.js +10 -26
  28. package/src/label-controller.d.ts +8 -3
  29. package/src/label-controller.js +149 -45
  30. package/src/label-mixin.d.ts +1 -1
  31. package/src/label-mixin.js +8 -13
  32. package/src/labelled-input-controller.d.ts +1 -1
  33. package/src/labelled-input-controller.js +2 -2
  34. package/src/pattern-mixin.d.ts +13 -3
  35. package/src/pattern-mixin.js +50 -2
  36. package/src/shadow-focus-mixin.d.ts +23 -0
  37. package/src/shadow-focus-mixin.js +97 -0
  38. package/src/slot-styles-mixin.d.ts +1 -1
  39. package/src/slot-styles-mixin.js +1 -1
  40. package/src/slot-target-controller.d.ts +31 -0
  41. package/src/slot-target-controller.js +123 -0
  42. package/src/styles/clear-button-styles.d.ts +1 -1
  43. package/src/styles/clear-button-styles.js +2 -2
  44. package/src/styles/field-shared-styles.d.ts +1 -1
  45. package/src/styles/field-shared-styles.js +1 -1
  46. package/src/styles/input-field-container-styles.d.ts +1 -1
  47. package/src/styles/input-field-container-styles.js +1 -1
  48. package/src/styles/input-field-shared-styles.d.ts +1 -1
  49. package/src/styles/input-field-shared-styles.js +1 -1
  50. package/src/text-area-controller.d.ts +1 -1
  51. package/src/text-area-controller.js +8 -5
  52. package/src/validate-mixin.d.ts +1 -1
  53. package/src/validate-mixin.js +1 -1
  54. package/src/virtual-keyboard-controller.d.ts +1 -1
  55. package/src/virtual-keyboard-controller.js +1 -1
@@ -0,0 +1,97 @@
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 { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js';
7
+ import { DelegateFocusMixin } from './delegate-focus-mixin.js';
8
+
9
+ /**
10
+ * A mixin to forward focus to an element in the shadow DOM.
11
+ *
12
+ * @polymerMixin
13
+ * @mixes DelegateFocusMixin
14
+ * @mixes KeyboardMixin
15
+ */
16
+ export const ShadowFocusMixin = (superClass) =>
17
+ class ShadowFocusMixinClass extends DelegateFocusMixin(KeyboardMixin(superClass)) {
18
+ static get properties() {
19
+ return {
20
+ /**
21
+ * Indicates whether the element can be focused and where it participates in sequential keyboard navigation.
22
+ *
23
+ * @override
24
+ * @protected
25
+ */
26
+ tabindex: {
27
+ type: Number,
28
+ value: 0,
29
+ },
30
+ };
31
+ }
32
+
33
+ /**
34
+ * Override an event listener from `KeyboardMixin`
35
+ * to prevent focusing the host element on Shift Tab.
36
+ * @param {KeyboardEvent} event
37
+ * @protected
38
+ * @override
39
+ */
40
+ _onKeyDown(event) {
41
+ super._onKeyDown(event);
42
+
43
+ // When focus moves with Shift + Tab, skip focusing the host element
44
+ // by focusing it before the default browser focus handling runs
45
+ if (!event.defaultPrevented && event.keyCode === 9 && event.shiftKey) {
46
+ HTMLElement.prototype.focus.apply(this);
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Override method inherited from `FocusMixin`
52
+ * to support focusElement in Shadow DOM.
53
+ * @param {Event} event
54
+ * @return {boolean}
55
+ * @protected
56
+ * @override
57
+ */
58
+ _shouldSetFocus(event) {
59
+ if (!this.disabled && this.focusElement) {
60
+ const path = event.composedPath();
61
+
62
+ // When focus moves to the host element itself, then delegate it to the focusElement
63
+ // This should only move focus when using keyboard navigation, for clicks we don't want to interfere,
64
+ // for example when the user tries to select some text
65
+ if (path[0] === this && this._keyboardActive) {
66
+ this.focusElement.focus();
67
+ }
68
+ if (path[0] === this || path.includes(this.focusElement)) {
69
+ return true;
70
+ }
71
+ }
72
+
73
+ return false;
74
+ }
75
+
76
+ /**
77
+ * Override an observer from `TabindexMixin`.
78
+ * Do not call super to remove tabindex attribute
79
+ * from host when disabled by setting undefined.
80
+ * @param {string} tabindex
81
+ * @protected
82
+ * @override
83
+ */
84
+ _tabindexChanged(tabindex) {
85
+ if (tabindex !== undefined) {
86
+ this.focusElement.tabIndex = tabindex;
87
+ }
88
+
89
+ if (this.disabled && tabindex) {
90
+ // If tabindex attribute was changed while component was disabled
91
+ if (tabindex !== -1) {
92
+ this._lastTabIndex = tabindex;
93
+ }
94
+ this.tabindex = undefined;
95
+ }
96
+ }
97
+ };
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2023 Vaadin Ltd.
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
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2023 Vaadin Ltd.
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
6
  import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
@@ -0,0 +1,31 @@
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 type { ReactiveController } from 'lit';
7
+
8
+ export class SlotTargetController implements ReactiveController {
9
+ /**
10
+ * The source `<slot>` element to copy nodes from.
11
+ */
12
+ protected sourceSlot: HTMLSlotElement;
13
+
14
+ /**
15
+ * Function used to get a reference to slot target.
16
+ */
17
+ protected targetFactory: () => HTMLElement;
18
+
19
+ /**
20
+ * Function called after copying nodes to target.
21
+ */
22
+ protected copyCallback?: (nodes: HTMLElement[]) => void;
23
+
24
+ constructor(
25
+ sourceSlot: HTMLSlotElement,
26
+ targetFactory: () => HTMLElement,
27
+ copyCallback?: (nodes: HTMLElement[]) => void,
28
+ );
29
+
30
+ hostConnected(): void;
31
+ }
@@ -0,0 +1,123 @@
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 to copy the content from a source slot to a target element.
9
+ */
10
+ export class SlotTargetController {
11
+ constructor(sourceSlot, targetFactory, callback) {
12
+ /**
13
+ * The source `<slot>` element to copy nodes from.
14
+ */
15
+ this.sourceSlot = sourceSlot;
16
+
17
+ /**
18
+ * Function used to get a reference to slot target.
19
+ */
20
+ this.targetFactory = targetFactory;
21
+
22
+ /**
23
+ * Function called after copying nodes to target.
24
+ */
25
+ this.copyCallback = callback;
26
+
27
+ if (sourceSlot) {
28
+ sourceSlot.addEventListener('slotchange', () => {
29
+ // Copy in progress, ignore this event.
30
+ if (this.__copying) {
31
+ this.__copying = false;
32
+ } else {
33
+ this.__checkAndCopyNodesToSlotTarget();
34
+ }
35
+ });
36
+ }
37
+ }
38
+
39
+ hostConnected() {
40
+ this.__sourceSlotObserver = new MutationObserver(() => this.__checkAndCopyNodesToSlotTarget());
41
+
42
+ // Ensure the content is up to date when host is connected
43
+ // to handle e.g. mutating text content while disconnected.
44
+ // Note, `hostConnected()` is called twice if the controller
45
+ // is initialized in `ready()` when using `ControllerMixin`.
46
+ if (!this.__copying) {
47
+ this.__checkAndCopyNodesToSlotTarget();
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Copies every node from the source slot to the target element
53
+ * once the source slot' content is changed.
54
+ *
55
+ * @private
56
+ */
57
+ __checkAndCopyNodesToSlotTarget() {
58
+ this.__sourceSlotObserver.disconnect();
59
+
60
+ // Ensure slot target element is up to date.
61
+ const slotTarget = this.targetFactory();
62
+
63
+ if (!slotTarget) {
64
+ return;
65
+ }
66
+
67
+ // Remove any existing clones from the slot target
68
+ if (this.__slotTargetClones) {
69
+ this.__slotTargetClones.forEach((node) => {
70
+ if (node.parentElement === slotTarget) {
71
+ slotTarget.removeChild(node);
72
+ }
73
+ });
74
+ delete this.__slotTargetClones;
75
+ }
76
+
77
+ // Exclude whitespace text nodes
78
+ const nodes = this.sourceSlot
79
+ .assignedNodes({ flatten: true })
80
+ .filter((node) => !(node.nodeType === Node.TEXT_NODE && node.textContent.trim() === ''));
81
+
82
+ if (nodes.length > 0) {
83
+ slotTarget.innerHTML = '';
84
+
85
+ // Ignore next slotchange
86
+ this.__copying = true;
87
+
88
+ this.__copyNodesToSlotTarget(nodes, slotTarget);
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Copies the nodes to the target element.
94
+ *
95
+ * @param {!Array<!Node>} nodes
96
+ * @param {HTMLElement} slotTarget
97
+ * @private
98
+ */
99
+ __copyNodesToSlotTarget(nodes, slotTarget) {
100
+ this.__slotTargetClones = this.__slotTargetClones || [];
101
+
102
+ nodes.forEach((node) => {
103
+ // Clone the nodes and append the clones to the target
104
+ const clone = node.cloneNode(true);
105
+ this.__slotTargetClones.push(clone);
106
+
107
+ slotTarget.appendChild(clone);
108
+
109
+ // Observe all changes to the source node to have the clones updated
110
+ this.__sourceSlotObserver.observe(node, {
111
+ attributes: true,
112
+ childList: true,
113
+ subtree: true,
114
+ characterData: true,
115
+ });
116
+ });
117
+
118
+ // Run callback e.g. to show a deprecation warning
119
+ if (typeof this.copyCallback === 'function') {
120
+ this.copyCallback(nodes);
121
+ }
122
+ }
123
+ }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2023 Vaadin Ltd..
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
6
  import type { CSSResult } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2023 Vaadin Ltd..
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
6
  import { css } from 'lit';
@@ -12,7 +12,7 @@ export const clearButton = css`
12
12
  }
13
13
 
14
14
  [part='clear-button']::before {
15
- content: '\\2715';
15
+ content: '';
16
16
  }
17
17
 
18
18
  :host([clear-button-visible][has-value]:not([disabled]):not([readonly])) [part='clear-button'] {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2023 Vaadin Ltd..
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
6
  import type { CSSResult } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2023 Vaadin Ltd..
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
6
  import { css } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2023 Vaadin Ltd..
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
6
  import type { CSSResult } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2023 Vaadin Ltd..
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
6
  import { css } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2023 Vaadin Ltd..
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
6
  import type { CSSResult } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2023 Vaadin Ltd..
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
6
  import { clearButton } from './clear-button-styles.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2023 Vaadin Ltd.
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
6
  import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2023 Vaadin Ltd.
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
6
  import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
@@ -10,8 +10,11 @@ import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
10
10
  */
11
11
  export class TextAreaController extends SlotController {
12
12
  constructor(host, callback) {
13
- super(host, 'textarea', 'textarea', {
14
- initializer: (node, host) => {
13
+ super(
14
+ host,
15
+ 'textarea',
16
+ () => document.createElement('textarea'),
17
+ (host, node) => {
15
18
  const value = host.getAttribute('value');
16
19
  if (value) {
17
20
  node.value = value;
@@ -28,7 +31,7 @@ export class TextAreaController extends SlotController {
28
31
  callback(node);
29
32
  }
30
33
  },
31
- useUniqueId: true,
32
- });
34
+ true,
35
+ );
33
36
  }
34
37
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2023 Vaadin Ltd.
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
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2023 Vaadin Ltd.
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
6
  import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2023 Vaadin Ltd.
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
6
  import type { ReactiveController } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2023 Vaadin Ltd.
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
6