@api-client/ui 0.2.4 → 0.2.6
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/.aiexclude +3 -0
- package/.vscode/settings.json +4 -1
- package/build/src/elements/autocomplete/internals/autocomplete.d.ts +53 -5
- package/build/src/elements/autocomplete/internals/autocomplete.d.ts.map +1 -1
- package/build/src/elements/autocomplete/internals/autocomplete.js +156 -33
- package/build/src/elements/autocomplete/internals/autocomplete.js.map +1 -1
- package/build/src/elements/highlight/MarkedHighlight.d.ts +2 -1
- package/build/src/elements/highlight/MarkedHighlight.d.ts.map +1 -1
- package/build/src/elements/highlight/MarkedHighlight.js +14 -11
- package/build/src/elements/highlight/MarkedHighlight.js.map +1 -1
- package/demo/elements/autocomplete/index.html +40 -0
- package/demo/elements/autocomplete/index.ts +52 -4
- package/package.json +1 -1
- package/src/elements/autocomplete/internals/autocomplete.ts +136 -32
- package/src/elements/highlight/MarkedHighlight.ts +16 -13
- package/test/elements/autocomplete/autocomplete-input.spec.ts +210 -13
package/.aiexclude
ADDED
package/.vscode/settings.json
CHANGED
|
@@ -9,5 +9,8 @@
|
|
|
9
9
|
"startactivityforresult",
|
|
10
10
|
"typescale"
|
|
11
11
|
],
|
|
12
|
-
"vscode-wtr-runner.testRunnerCommand": "npm run tsc:all && npx wtr --playwright --browsers \"chromium\""
|
|
12
|
+
"vscode-wtr-runner.testRunnerCommand": "npm run tsc:all && npx wtr --playwright --browsers \"chromium\"",
|
|
13
|
+
"geminicodeassist.customCommands": {
|
|
14
|
+
"add-comments": "add comments to my code. add examples whenever reasonable. focus on another developer understanding what the function is about. don't forget about class fields."
|
|
15
|
+
}
|
|
13
16
|
}
|
|
@@ -20,10 +20,20 @@ import type UiListbox from '../../../md/listbox/internals/Listbox.js';
|
|
|
20
20
|
* - If a `ui-list-item` has a `data-index` attribute (e.g., `data-index="name email"`), filtering will search
|
|
21
21
|
* within the specified `data-*` attributes (e.g., `data-name`, `data-email`).
|
|
22
22
|
* - **Mutation Awareness**: Reacts to changes in slotted suggestions, re-filtering them if necessary.
|
|
23
|
-
* - **Event-Driven**: Notifies the
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
23
|
+
* - **Event-Driven**: Notifies the application via an `autocomplete` event when a suggestion is selected.
|
|
24
|
+
* The component itself does not modify the input's value, giving the application author full control.
|
|
25
|
+
*
|
|
26
|
+
* ### Accessibility
|
|
27
|
+
*
|
|
28
|
+
* The `autocomplete-input` component is designed with accessibility at its core:
|
|
29
|
+
* - **Keyboard Navigation**: Full keyboard support for navigating suggestions (ArrowUp, ArrowDown),
|
|
30
|
+
* selecting (Enter), and closing (Escape), all while focus remains on the input field.
|
|
31
|
+
* - **ARIA Attributes**: While the `autocomplete-input` manages ARIA attributes related to the popover's
|
|
32
|
+
* state, the slotted `ui-listbox` is responsible for its internal ARIA roles and states
|
|
33
|
+
* (e.g., `role="listbox"`, `aria-activedescendant`).
|
|
34
|
+
* - **Labeling Suggestions**: It is **crucial** for accessibility that the slotted `ui-listbox`
|
|
35
|
+
* has an `aria-label` attribute. This provides a descriptive name for the list of suggestions,
|
|
36
|
+
* which is announced by screen readers.
|
|
27
37
|
*
|
|
28
38
|
* The component uses CSS anchor positioning to place the suggestions popover relative to the input.
|
|
29
39
|
* Ensure your `ui-listbox` is styled appropriately for popover display (e.g., `popover="manual"`, `position-anchor`).
|
|
@@ -33,6 +43,10 @@ import type UiListbox from '../../../md/listbox/internals/Listbox.js';
|
|
|
33
43
|
* or behave like one (have a `value` property and dispatch `input`, `focus`, `blur`, and `keydown`
|
|
34
44
|
* events).
|
|
35
45
|
* @slot suggestions - The `ui-listbox` element containing `ui-list-item` elements as suggestions.
|
|
46
|
+
* @slot anchor - An optional element that points to element that will be used as the anchor for the popover.
|
|
47
|
+
* This is useful if you want to position the suggestions relative to a different element than the input.
|
|
48
|
+
* If not provided, the input element will be used as the anchor.
|
|
49
|
+
* @slot Any additional content that should be rendered inside the component.
|
|
36
50
|
*
|
|
37
51
|
* @fires autocomplete - Dispatched when a suggestion is selected by the user (e.g., via click or Enter key).
|
|
38
52
|
* The `event.detail` object contains:
|
|
@@ -47,6 +61,12 @@ import type UiListbox from '../../../md/listbox/internals/Listbox.js';
|
|
|
47
61
|
* <ui-list-item data-value="banana">Banana</ui-list-item>
|
|
48
62
|
* <ui-list-item data-value="cherry">Cherry</ui-list-item>
|
|
49
63
|
* </ui-listbox>
|
|
64
|
+
* <!-- With aria-label for accessibility -->
|
|
65
|
+
* <ui-listbox slot="suggestions" aria-label="Fruit suggestions">
|
|
66
|
+
* <ui-list-item data-value="apple">Apple</ui-list-item>
|
|
67
|
+
* <ui-list-item data-value="banana">Banana</ui-list-item>
|
|
68
|
+
* <ui-list-item data-value="cherry">Cherry</ui-list-item>
|
|
69
|
+
* </ui-listbox>
|
|
50
70
|
* </autocomplete-input>
|
|
51
71
|
*
|
|
52
72
|
* <script>
|
|
@@ -66,7 +86,7 @@ import type UiListbox from '../../../md/listbox/internals/Listbox.js';
|
|
|
66
86
|
* ```html
|
|
67
87
|
* <autocomplete-input @autocomplete="${this.handleUserSelection}">
|
|
68
88
|
* <input slot="input" type="text" placeholder="Search users..." />
|
|
69
|
-
* <ui-listbox slot="suggestions">
|
|
89
|
+
* <ui-listbox slot="suggestions" aria-label="User suggestions">
|
|
70
90
|
* <ui-list-item data-id="1" data-name="Alice Wonderland" data-email="alice@example.com" data-index="name email">
|
|
71
91
|
* Alice Wonderland
|
|
72
92
|
* <span slot="supporting-text">alice@example.com</span>
|
|
@@ -93,6 +113,7 @@ import type UiListbox from '../../../md/listbox/internals/Listbox.js';
|
|
|
93
113
|
* ```
|
|
94
114
|
*/
|
|
95
115
|
export default class Autocomplete extends LitElement {
|
|
116
|
+
protected createRenderRoot(): HTMLElement | DocumentFragment;
|
|
96
117
|
/**
|
|
97
118
|
* The MutationObserver instance used to watch for changes in slotted children.
|
|
98
119
|
*/
|
|
@@ -102,6 +123,19 @@ export default class Autocomplete extends LitElement {
|
|
|
102
123
|
* This is used for CSS anchoring and to ensure unique IDs for accessibility.
|
|
103
124
|
*/
|
|
104
125
|
protected accessor inputId: string;
|
|
126
|
+
/**
|
|
127
|
+
* The position area for the suggestions popover.
|
|
128
|
+
* This can be 'bottom' or 'top', depending on available space.
|
|
129
|
+
* Default is 'bottom'.
|
|
130
|
+
*
|
|
131
|
+
* Note, this is set dynamically based on available space
|
|
132
|
+
* and the position of the input element. This only sets the initial value.
|
|
133
|
+
*
|
|
134
|
+
* @attribute
|
|
135
|
+
* @type {'bottom' | 'top'}
|
|
136
|
+
* @default 'bottom'
|
|
137
|
+
*/
|
|
138
|
+
accessor positionArea: 'bottom' | 'top';
|
|
105
139
|
/**
|
|
106
140
|
* The reference to the slotted input element.
|
|
107
141
|
* This should be an `HTMLInputElement` or behave like one.
|
|
@@ -194,6 +228,20 @@ export default class Autocomplete extends LitElement {
|
|
|
194
228
|
* Opens the suggestions popover if it's not already open and there are visible items.
|
|
195
229
|
*/
|
|
196
230
|
protected openSuggestions(): void;
|
|
231
|
+
/**
|
|
232
|
+
* Decides the position area for the popover based on available space.
|
|
233
|
+
* It checks if there is enough space below or above the anchor element and decides accordingly.
|
|
234
|
+
*
|
|
235
|
+
* We need to do this because we set the popover height to `100%`, `-webkit-fill-available`, or `-moz-available`
|
|
236
|
+
* and it makes the popover to always open at the bottom, even if there is no space. The `position-try-fallbacks`
|
|
237
|
+
* will not work in this case, because from its perspective there is always enough space, even if that will cause
|
|
238
|
+
* the popover to have a height of just a few pixels.
|
|
239
|
+
*
|
|
240
|
+
* @param popover The popover element to position.
|
|
241
|
+
* @param anchor The anchor element relative to which the popover will be positioned.
|
|
242
|
+
* @returns 'top' or 'bottom' based on available space.
|
|
243
|
+
*/
|
|
244
|
+
protected decidePositionArea(popover: HTMLElement, anchor: HTMLElement): 'top' | 'bottom';
|
|
197
245
|
/**
|
|
198
246
|
* Closes the suggestions popover if it's open and clears any highlighted item.
|
|
199
247
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete.d.ts","sourceRoot":"","sources":["../../../../../src/elements/autocomplete/internals/autocomplete.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAEtE,OAAO,KAAK,SAAS,MAAM,0CAA0C,CAAA;AAIrE
|
|
1
|
+
{"version":3,"file":"autocomplete.d.ts","sourceRoot":"","sources":["../../../../../src/elements/autocomplete/internals/autocomplete.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAEtE,OAAO,KAAK,SAAS,MAAM,0CAA0C,CAAA;AAIrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+GG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,UAAU;cAC/B,gBAAgB,IAAI,WAAW,GAAG,gBAAgB;IAIrE;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAA;IAErC;;;OAGG;IACM,SAAS,CAAC,QAAQ,CAAC,OAAO,SAAK;IAExC;;;;;;;;;;;OAWG;IACS,QAAQ,CAAC,YAAY,EAAE,QAAQ,GAAG,KAAK,CAAW;IAE9D;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,EAAE,gBAAgB,GAAG,WAAW,GAAG,IAAI,CAAA;IAC1D;;;OAGG;IACH,SAAS,CAAC,cAAc,CAAC,EAAE,SAAS,GAAG,IAAI,CAAA;IAE3C;;OAEG;IACH,IAAI,MAAM,IAAI,OAAO,CAEpB;IAEQ,iBAAiB,IAAI,IAAI;IAUzB,oBAAoB,IAAI,IAAI;cAQlB,YAAY,CAAC,EAAE,EAAE,cAAc,GAAG,IAAI;IAKzD;;;OAGG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
|
import { __esDecorate, __runInitializers } from "tslib";
|
|
2
2
|
import { html, LitElement } from 'lit';
|
|
3
|
-
import { state } from 'lit/decorators.js';
|
|
3
|
+
import { property, state } from 'lit/decorators.js';
|
|
4
4
|
import { bound } from '../../../decorators/bound.js';
|
|
5
5
|
let Autocomplete = (() => {
|
|
6
6
|
let _classSuper = LitElement;
|
|
@@ -8,6 +8,9 @@ let Autocomplete = (() => {
|
|
|
8
8
|
let _inputId_decorators;
|
|
9
9
|
let _inputId_initializers = [];
|
|
10
10
|
let _inputId_extraInitializers = [];
|
|
11
|
+
let _positionArea_decorators;
|
|
12
|
+
let _positionArea_initializers = [];
|
|
13
|
+
let _positionArea_extraInitializers = [];
|
|
11
14
|
let _handleInputFocus_decorators;
|
|
12
15
|
let _handleInput_decorators;
|
|
13
16
|
let _handleKeydown_decorators;
|
|
@@ -18,6 +21,7 @@ let Autocomplete = (() => {
|
|
|
18
21
|
static {
|
|
19
22
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
20
23
|
_inputId_decorators = [state()];
|
|
24
|
+
_positionArea_decorators = [property()];
|
|
21
25
|
_handleInputFocus_decorators = [bound];
|
|
22
26
|
_handleInput_decorators = [bound];
|
|
23
27
|
_handleKeydown_decorators = [bound];
|
|
@@ -25,6 +29,7 @@ let Autocomplete = (() => {
|
|
|
25
29
|
_handleSuggestionSelect_decorators = [bound];
|
|
26
30
|
_handleSuggestionsSlotChange_decorators = [bound];
|
|
27
31
|
__esDecorate(this, null, _inputId_decorators, { kind: "accessor", name: "inputId", static: false, private: false, access: { has: obj => "inputId" in obj, get: obj => obj.inputId, set: (obj, value) => { obj.inputId = value; } }, metadata: _metadata }, _inputId_initializers, _inputId_extraInitializers);
|
|
32
|
+
__esDecorate(this, null, _positionArea_decorators, { kind: "accessor", name: "positionArea", static: false, private: false, access: { has: obj => "positionArea" in obj, get: obj => obj.positionArea, set: (obj, value) => { obj.positionArea = value; } }, metadata: _metadata }, _positionArea_initializers, _positionArea_extraInitializers);
|
|
28
33
|
__esDecorate(this, null, _handleInputFocus_decorators, { kind: "method", name: "handleInputFocus", static: false, private: false, access: { has: obj => "handleInputFocus" in obj, get: obj => obj.handleInputFocus }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
29
34
|
__esDecorate(this, null, _handleInput_decorators, { kind: "method", name: "handleInput", static: false, private: false, access: { has: obj => "handleInput" in obj, get: obj => obj.handleInput }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
30
35
|
__esDecorate(this, null, _handleKeydown_decorators, { kind: "method", name: "handleKeydown", static: false, private: false, access: { has: obj => "handleKeydown" in obj, get: obj => obj.handleKeydown }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
@@ -33,14 +38,25 @@ let Autocomplete = (() => {
|
|
|
33
38
|
__esDecorate(this, null, _handleSuggestionsSlotChange_decorators, { kind: "method", name: "handleSuggestionsSlotChange", static: false, private: false, access: { has: obj => "handleSuggestionsSlotChange" in obj, get: obj => obj.handleSuggestionsSlotChange }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
34
39
|
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
35
40
|
}
|
|
41
|
+
createRenderRoot() {
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
36
44
|
/**
|
|
37
45
|
* The MutationObserver instance used to watch for changes in slotted children.
|
|
38
46
|
*/
|
|
39
47
|
observer = __runInitializers(this, _instanceExtraInitializers);
|
|
40
48
|
#inputId_accessor_storage = __runInitializers(this, _inputId_initializers, ''
|
|
41
49
|
/**
|
|
42
|
-
* The
|
|
43
|
-
* This
|
|
50
|
+
* The position area for the suggestions popover.
|
|
51
|
+
* This can be 'bottom' or 'top', depending on available space.
|
|
52
|
+
* Default is 'bottom'.
|
|
53
|
+
*
|
|
54
|
+
* Note, this is set dynamically based on available space
|
|
55
|
+
* and the position of the input element. This only sets the initial value.
|
|
56
|
+
*
|
|
57
|
+
* @attribute
|
|
58
|
+
* @type {'bottom' | 'top'}
|
|
59
|
+
* @default 'bottom'
|
|
44
60
|
*/
|
|
45
61
|
);
|
|
46
62
|
/**
|
|
@@ -49,11 +65,31 @@ let Autocomplete = (() => {
|
|
|
49
65
|
*/
|
|
50
66
|
get inputId() { return this.#inputId_accessor_storage; }
|
|
51
67
|
set inputId(value) { this.#inputId_accessor_storage = value; }
|
|
68
|
+
#positionArea_accessor_storage = (__runInitializers(this, _inputId_extraInitializers), __runInitializers(this, _positionArea_initializers, 'bottom'
|
|
69
|
+
/**
|
|
70
|
+
* The reference to the slotted input element.
|
|
71
|
+
* This should be an `HTMLInputElement` or behave like one.
|
|
72
|
+
*/
|
|
73
|
+
));
|
|
74
|
+
/**
|
|
75
|
+
* The position area for the suggestions popover.
|
|
76
|
+
* This can be 'bottom' or 'top', depending on available space.
|
|
77
|
+
* Default is 'bottom'.
|
|
78
|
+
*
|
|
79
|
+
* Note, this is set dynamically based on available space
|
|
80
|
+
* and the position of the input element. This only sets the initial value.
|
|
81
|
+
*
|
|
82
|
+
* @attribute
|
|
83
|
+
* @type {'bottom' | 'top'}
|
|
84
|
+
* @default 'bottom'
|
|
85
|
+
*/
|
|
86
|
+
get positionArea() { return this.#positionArea_accessor_storage; }
|
|
87
|
+
set positionArea(value) { this.#positionArea_accessor_storage = value; }
|
|
52
88
|
/**
|
|
53
89
|
* The reference to the slotted input element.
|
|
54
90
|
* This should be an `HTMLInputElement` or behave like one.
|
|
55
91
|
*/
|
|
56
|
-
inputRef = __runInitializers(this,
|
|
92
|
+
inputRef = __runInitializers(this, _positionArea_extraInitializers);
|
|
57
93
|
/**
|
|
58
94
|
* The reference to the slotted suggestions element, which should be a `ui-listbox`.
|
|
59
95
|
* This is used to manage the suggestions popover and filtering.
|
|
@@ -69,6 +105,10 @@ let Autocomplete = (() => {
|
|
|
69
105
|
super.connectedCallback();
|
|
70
106
|
this.observer = new MutationObserver(this.handleMutations.bind(this));
|
|
71
107
|
this.observer.observe(this, { childList: true });
|
|
108
|
+
if (!this.id) {
|
|
109
|
+
this.id = `autocomplete-${Math.random().toString(36).substring(2, 15)}`;
|
|
110
|
+
}
|
|
111
|
+
this.classList.add(this.id);
|
|
72
112
|
}
|
|
73
113
|
disconnectedCallback() {
|
|
74
114
|
super.disconnectedCallback();
|
|
@@ -87,20 +127,13 @@ let Autocomplete = (() => {
|
|
|
87
127
|
*/
|
|
88
128
|
async firstSetup() {
|
|
89
129
|
await this.updateComplete;
|
|
90
|
-
const input = this.
|
|
91
|
-
const suggestions = this.
|
|
130
|
+
const input = this.querySelector('[slot="input"]');
|
|
131
|
+
const suggestions = this.querySelector('[slot="suggestions"]');
|
|
92
132
|
if (input) {
|
|
93
|
-
|
|
94
|
-
if (elements.length > 0 && elements[0] instanceof HTMLElement) {
|
|
95
|
-
this.setupInput(elements[0]);
|
|
96
|
-
}
|
|
133
|
+
this.setupInput(input);
|
|
97
134
|
}
|
|
98
135
|
if (suggestions) {
|
|
99
|
-
|
|
100
|
-
if (elements.length > 0 && elements[0] instanceof HTMLElement) {
|
|
101
|
-
// Assuming the slotted element is ui-listbox or compatible
|
|
102
|
-
this.setupSuggestions(elements[0]);
|
|
103
|
-
}
|
|
136
|
+
this.setupSuggestions(suggestions);
|
|
104
137
|
}
|
|
105
138
|
}
|
|
106
139
|
/**
|
|
@@ -174,18 +207,15 @@ let Autocomplete = (() => {
|
|
|
174
207
|
else {
|
|
175
208
|
this.inputId = input.id;
|
|
176
209
|
}
|
|
210
|
+
const anchorElement = this.querySelector('[slot="anchor"]');
|
|
177
211
|
// Ensure CSS anchor positioning can work
|
|
178
|
-
|
|
212
|
+
const anchor = anchorElement || input;
|
|
213
|
+
anchor.style.setProperty('anchor-name', `--${this.inputId}`);
|
|
179
214
|
this.inputRef = input; // Assuming it behaves like an input
|
|
180
215
|
this.inputRef.addEventListener('focus', this.handleInputFocus);
|
|
181
216
|
this.inputRef.addEventListener('input', this.handleInput);
|
|
182
217
|
this.inputRef.addEventListener('keydown', this.handleKeydown);
|
|
183
218
|
this.inputRef.addEventListener('blur', this.handleInputBlur);
|
|
184
|
-
// Apply initial filtering if suggestions are already present
|
|
185
|
-
if (this.suggestionsRef) {
|
|
186
|
-
this.suggestionsRef.style.setProperty('position-anchor', `--${this.inputId}`);
|
|
187
|
-
this.filterSuggestions(this.inputRef.value || '');
|
|
188
|
-
}
|
|
189
219
|
}
|
|
190
220
|
/**
|
|
191
221
|
* Sets up the slotted suggestions element (assumed to be a `UiListbox`).
|
|
@@ -197,9 +227,6 @@ let Autocomplete = (() => {
|
|
|
197
227
|
this.suggestionsRef = suggestionsElement;
|
|
198
228
|
this.suggestionsRef.popover = 'manual';
|
|
199
229
|
this.suggestionsRef.tabIndex = -1; // Prevent direct focus
|
|
200
|
-
if (this.inputId) {
|
|
201
|
-
this.suggestionsRef.style.setProperty('position-anchor', `--${this.inputId}`);
|
|
202
|
-
}
|
|
203
230
|
this.suggestionsRef.addEventListener('select', this.handleSuggestionSelect);
|
|
204
231
|
// The `List` dispatches `itemschange` when the slot changes, so we can listen to it.
|
|
205
232
|
this.suggestionsRef.addEventListener('itemschange', this.handleSuggestionsSlotChange);
|
|
@@ -330,9 +357,52 @@ let Autocomplete = (() => {
|
|
|
330
357
|
* Opens the suggestions popover if it's not already open and there are visible items.
|
|
331
358
|
*/
|
|
332
359
|
openSuggestions() {
|
|
333
|
-
|
|
334
|
-
|
|
360
|
+
const popover = this.suggestionsRef;
|
|
361
|
+
if (!popover || popover.matches(':popover-open')) {
|
|
362
|
+
return;
|
|
335
363
|
}
|
|
364
|
+
// we need to open the popover first to make any measurements
|
|
365
|
+
popover.showPopover();
|
|
366
|
+
const anchor = this.querySelector('[slot="anchor"]') || this.inputRef;
|
|
367
|
+
if (!anchor) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
this.positionArea = this.decidePositionArea(popover, anchor);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Decides the position area for the popover based on available space.
|
|
374
|
+
* It checks if there is enough space below or above the anchor element and decides accordingly.
|
|
375
|
+
*
|
|
376
|
+
* We need to do this because we set the popover height to `100%`, `-webkit-fill-available`, or `-moz-available`
|
|
377
|
+
* and it makes the popover to always open at the bottom, even if there is no space. The `position-try-fallbacks`
|
|
378
|
+
* will not work in this case, because from its perspective there is always enough space, even if that will cause
|
|
379
|
+
* the popover to have a height of just a few pixels.
|
|
380
|
+
*
|
|
381
|
+
* @param popover The popover element to position.
|
|
382
|
+
* @param anchor The anchor element relative to which the popover will be positioned.
|
|
383
|
+
* @returns 'top' or 'bottom' based on available space.
|
|
384
|
+
*/
|
|
385
|
+
decidePositionArea(popover, anchor) {
|
|
386
|
+
let newArea = 'bottom';
|
|
387
|
+
// Get bounding rectangles
|
|
388
|
+
const anchorRect = anchor.getBoundingClientRect();
|
|
389
|
+
const viewportHeight = window.innerHeight;
|
|
390
|
+
const spaceBelow = viewportHeight - anchorRect.bottom;
|
|
391
|
+
const spaceAbove = anchorRect.top;
|
|
392
|
+
// Estimate a typical/minimum height the popover might need to be useful
|
|
393
|
+
const popoverThresholdHeight = popover.scrollHeight || 150;
|
|
394
|
+
if (spaceBelow < popoverThresholdHeight && spaceAbove > spaceBelow && spaceAbove > popoverThresholdHeight) {
|
|
395
|
+
// Not enough space below, but more (and sufficient) space above
|
|
396
|
+
newArea = 'top';
|
|
397
|
+
}
|
|
398
|
+
else if (spaceBelow < popoverThresholdHeight && spaceAbove > spaceBelow) {
|
|
399
|
+
// Not enough space below, and space above is more than space below (even if not "sufficient")
|
|
400
|
+
newArea = 'top';
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
newArea = 'bottom'; // Default to bottom if enough space or if top is worse
|
|
404
|
+
}
|
|
405
|
+
return newArea;
|
|
336
406
|
}
|
|
337
407
|
/**
|
|
338
408
|
* Closes the suggestions popover if it's open and clears any highlighted item.
|
|
@@ -390,9 +460,42 @@ let Autocomplete = (() => {
|
|
|
390
460
|
}
|
|
391
461
|
}
|
|
392
462
|
render() {
|
|
463
|
+
const { id, positionArea, inputId } = this;
|
|
464
|
+
/*
|
|
465
|
+
position-try-fallbacks:
|
|
466
|
+
flip-block,
|
|
467
|
+
flip-inline,
|
|
468
|
+
flip-block flip-inline;
|
|
469
|
+
*/
|
|
393
470
|
return html `
|
|
394
|
-
<
|
|
395
|
-
|
|
471
|
+
<style>
|
|
472
|
+
.${id} {
|
|
473
|
+
display: inline-block;
|
|
474
|
+
|
|
475
|
+
[popover] {
|
|
476
|
+
border: none;
|
|
477
|
+
margin: 0;
|
|
478
|
+
|
|
479
|
+
box-shadow: var(--md-sys-elevation-1);
|
|
480
|
+
border-radius: var(--md-sys-shape-corner-medium);
|
|
481
|
+
|
|
482
|
+
position-area: ${positionArea};
|
|
483
|
+
position-anchor: --${inputId};
|
|
484
|
+
|
|
485
|
+
overflow: auto;
|
|
486
|
+
/* We try 100% and then vendor options which are more accurate */
|
|
487
|
+
height: 100%;
|
|
488
|
+
height: -webkit-fill-available;
|
|
489
|
+
height: -moz-available;
|
|
490
|
+
max-height: max-content;
|
|
491
|
+
width: anchor-size(width);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
[popover]:not(:popover-open) {
|
|
495
|
+
display: none;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
</style>
|
|
396
499
|
`;
|
|
397
500
|
}
|
|
398
501
|
};
|
|
@@ -417,10 +520,20 @@ let Autocomplete = (() => {
|
|
|
417
520
|
* - If a `ui-list-item` has a `data-index` attribute (e.g., `data-index="name email"`), filtering will search
|
|
418
521
|
* within the specified `data-*` attributes (e.g., `data-name`, `data-email`).
|
|
419
522
|
* - **Mutation Awareness**: Reacts to changes in slotted suggestions, re-filtering them if necessary.
|
|
420
|
-
* - **Event-Driven**: Notifies the
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
523
|
+
* - **Event-Driven**: Notifies the application via an `autocomplete` event when a suggestion is selected.
|
|
524
|
+
* The component itself does not modify the input's value, giving the application author full control.
|
|
525
|
+
*
|
|
526
|
+
* ### Accessibility
|
|
527
|
+
*
|
|
528
|
+
* The `autocomplete-input` component is designed with accessibility at its core:
|
|
529
|
+
* - **Keyboard Navigation**: Full keyboard support for navigating suggestions (ArrowUp, ArrowDown),
|
|
530
|
+
* selecting (Enter), and closing (Escape), all while focus remains on the input field.
|
|
531
|
+
* - **ARIA Attributes**: While the `autocomplete-input` manages ARIA attributes related to the popover's
|
|
532
|
+
* state, the slotted `ui-listbox` is responsible for its internal ARIA roles and states
|
|
533
|
+
* (e.g., `role="listbox"`, `aria-activedescendant`).
|
|
534
|
+
* - **Labeling Suggestions**: It is **crucial** for accessibility that the slotted `ui-listbox`
|
|
535
|
+
* has an `aria-label` attribute. This provides a descriptive name for the list of suggestions,
|
|
536
|
+
* which is announced by screen readers.
|
|
424
537
|
*
|
|
425
538
|
* The component uses CSS anchor positioning to place the suggestions popover relative to the input.
|
|
426
539
|
* Ensure your `ui-listbox` is styled appropriately for popover display (e.g., `popover="manual"`, `position-anchor`).
|
|
@@ -430,6 +543,10 @@ let Autocomplete = (() => {
|
|
|
430
543
|
* or behave like one (have a `value` property and dispatch `input`, `focus`, `blur`, and `keydown`
|
|
431
544
|
* events).
|
|
432
545
|
* @slot suggestions - The `ui-listbox` element containing `ui-list-item` elements as suggestions.
|
|
546
|
+
* @slot anchor - An optional element that points to element that will be used as the anchor for the popover.
|
|
547
|
+
* This is useful if you want to position the suggestions relative to a different element than the input.
|
|
548
|
+
* If not provided, the input element will be used as the anchor.
|
|
549
|
+
* @slot Any additional content that should be rendered inside the component.
|
|
433
550
|
*
|
|
434
551
|
* @fires autocomplete - Dispatched when a suggestion is selected by the user (e.g., via click or Enter key).
|
|
435
552
|
* The `event.detail` object contains:
|
|
@@ -444,6 +561,12 @@ let Autocomplete = (() => {
|
|
|
444
561
|
* <ui-list-item data-value="banana">Banana</ui-list-item>
|
|
445
562
|
* <ui-list-item data-value="cherry">Cherry</ui-list-item>
|
|
446
563
|
* </ui-listbox>
|
|
564
|
+
* <!-- With aria-label for accessibility -->
|
|
565
|
+
* <ui-listbox slot="suggestions" aria-label="Fruit suggestions">
|
|
566
|
+
* <ui-list-item data-value="apple">Apple</ui-list-item>
|
|
567
|
+
* <ui-list-item data-value="banana">Banana</ui-list-item>
|
|
568
|
+
* <ui-list-item data-value="cherry">Cherry</ui-list-item>
|
|
569
|
+
* </ui-listbox>
|
|
447
570
|
* </autocomplete-input>
|
|
448
571
|
*
|
|
449
572
|
* <script>
|
|
@@ -463,7 +586,7 @@ let Autocomplete = (() => {
|
|
|
463
586
|
* ```html
|
|
464
587
|
* <autocomplete-input @autocomplete="${this.handleUserSelection}">
|
|
465
588
|
* <input slot="input" type="text" placeholder="Search users..." />
|
|
466
|
-
* <ui-listbox slot="suggestions">
|
|
589
|
+
* <ui-listbox slot="suggestions" aria-label="User suggestions">
|
|
467
590
|
* <ui-list-item data-id="1" data-name="Alice Wonderland" data-email="alice@example.com" data-index="name email">
|
|
468
591
|
* Alice Wonderland
|
|
469
592
|
* <span slot="supporting-text">alice@example.com</span>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete.js","sourceRoot":"","sources":["../../../../../src/elements/autocomplete/internals/autocomplete.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAkC,MAAM,KAAK,CAAA;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAGzC,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;;sBA8FV,UAAU;;;;;;;;;;;iBAA/B,YAAa,SAAQ,WAAU;;;mCAUjD,KAAK,EAAE;4CAiLP,KAAK;uCAmBL,KAAK;yCAcL,KAAK;2CAkDL,KAAK;kDAmBL,KAAK;uDAkBL,KAAK;YAzSG,0KAAmB,OAAO,6BAAP,OAAO,yFAAK;YAkLxC,mMAAU,gBAAgB,6DAWzB;YAQD,oLAAU,WAAW,6DAIpB;YAUD,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B,CAAC;QACH,CAAC;QAEkB,MAAM;YACvB,OAAO,IAAI,CAAA;;;KAGV,CAAA;QACH,CAAC;;;AAleH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;AACH,4BAuYC","sourcesContent":["import { html, LitElement, PropertyValues, TemplateResult } from 'lit'\nimport { state } from 'lit/decorators.js'\nimport type UiListbox from '../../../md/listbox/internals/Listbox.js'\nimport type UiListItem from '../../../md/list/internals/ListItem.js'\nimport { bound } from '../../../decorators/bound.js'\n\n/**\n * An accessible and performant autocomplete component that enhances a text input with a list of suggestions.\n *\n * The `autocomplete-input` component provides a flexible way to add autocomplete functionality\n * to any text input. It works by coordinating a slotted input element with a slotted `ui-listbox`\n * containing suggestions.\n *\n * Key Features:\n *\n * - **Popover Management**: Automatically shows and hides the suggestions popover based on input focus\n * and user interaction.\n * - **Keyboard Navigation**: Allows users to navigate suggestions using ArrowUp, ArrowDown keys directly\n * from the input. Enter selects a suggestion, and Escape closes the popover.\n * The suggestion list itself never gains focus.\n * - **Dynamic Filtering**: Filters the list of suggestions as the user types into the input. Items not matching\n * the query are hidden (not removed).\n * - By default, filtering checks `item.dataset.value` and then `item.textContent`.\n * - If a `ui-list-item` has a `data-index` attribute (e.g., `data-index=\"name email\"`), filtering will search\n * within the specified `data-*` attributes (e.g., `data-name`, `data-email`).\n * - **Mutation Awareness**: Reacts to changes in slotted suggestions, re-filtering them if necessary.\n * - **Event-Driven**: Notifies the parent application via an `autocomplete` event when a suggestion is selected,\n * without directly modifying the input's value. This allows the application author to control the input update logic.\n * - **Accessibility**: Designed with accessibility in mind, ensuring keyboard navigability and proper ARIA attribute\n * management (handled by `ui-listbox`).\n *\n * The component uses CSS anchor positioning to place the suggestions popover relative to the input.\n * Ensure your `ui-listbox` is styled appropriately for popover display (e.g., `popover=\"manual\"`, `position-anchor`).\n * The component will manage `showPopover()` and `hidePopover()` calls.\n *\n * @slot input - The input element that will be used for autocomplete. This element should be an `HTMLInputElement`\n * or behave like one (have a `value` property and dispatch `input`, `focus`, `blur`, and `keydown`\n * events).\n * @slot suggestions - The `ui-listbox` element containing `ui-list-item` elements as suggestions.\n *\n * @fires autocomplete - Dispatched when a suggestion is selected by the user (e.g., via click or Enter key).\n * The `event.detail` object contains:\n * - `item`: The selected `UiListItem` instance.\n *\n * @example\n * ```html\n * <autocomplete-input @autocomplete=\"${this.handleAutocompleteSelection}\">\n * <input slot=\"input\" type=\"text\" placeholder=\"Search fruits...\" />\n * <ui-listbox slot=\"suggestions\">\n * <ui-list-item data-value=\"apple\">Apple</ui-list-item>\n * <ui-list-item data-value=\"banana\">Banana</ui-list-item>\n * <ui-list-item data-value=\"cherry\">Cherry</ui-list-item>\n * </ui-listbox>\n * </autocomplete-input>\n *\n * <script>\n * // In your component/script\n * handleAutocompleteSelection(event) {\n * const selectedItem = event.detail.item;\n * const inputElement = this.shadowRoot.querySelector('input[slot=\"input\"]');\n * if (inputElement) {\n * inputElement.value = selectedItem.dataset.value || selectedItem.textContent;\n * }\n * console.log('Selected:', selectedItem.dataset.value);\n * }\n * </script>\n * ```\n *\n * @example Dynamic filtering with `data-index`\n * ```html\n * <autocomplete-input @autocomplete=\"${this.handleUserSelection}\">\n * <input slot=\"input\" type=\"text\" placeholder=\"Search users...\" />\n * <ui-listbox slot=\"suggestions\">\n * <ui-list-item data-id=\"1\" data-name=\"Alice Wonderland\" data-email=\"alice@example.com\" data-index=\"name email\">\n * Alice Wonderland\n * <span slot=\"supporting-text\">alice@example.com</span>\n * </ui-list-item>\n * <ui-list-item data-id=\"2\" data-name=\"Bob The Builder\" data-email=\"bob@example.com\" data-index=\"name email\">\n * Bob The Builder\n * <span slot=\"supporting-text\">bob@example.com</span>\n * </ui-list-item>\n * </ui-listbox>\n * </autocomplete-input>\n *\n * <script>\n * // In your component/script\n * handleUserSelection(event) {\n * const selectedItem = event.detail.item;\n * const inputElement = this.shadowRoot.querySelector('input[slot=\"input\"]');\n * if (inputElement) {\n * // You might want to display the name, but store the ID\n * inputElement.value = selectedItem.dataset.name;\n * }\n * console.log('Selected user ID:', selectedItem.dataset.id);\n * }\n * </script>\n * ```\n */\nexport default class Autocomplete extends LitElement {\n /**\n * The MutationObserver instance used to watch for changes in slotted children.\n */\n protected observer?: MutationObserver\n\n /**\n * The ID of the input element, generated if not provided.\n * This is used for CSS anchoring and to ensure unique IDs for accessibility.\n */\n @state() protected accessor inputId = ''\n\n /**\n * The reference to the slotted input element.\n * This should be an `HTMLInputElement` or behave like one.\n */\n protected inputRef?: HTMLInputElement | HTMLElement | null\n /**\n * The reference to the slotted suggestions element, which should be a `ui-listbox`.\n * This is used to manage the suggestions popover and filtering.\n */\n protected suggestionsRef?: UiListbox | null\n\n /**\n * Checks if the suggestions popover is currently open.\n */\n get opened(): boolean {\n return this.suggestionsRef?.matches(':popover-open') || false\n }\n\n override connectedCallback(): void {\n super.connectedCallback()\n this.observer = new MutationObserver(this.handleMutations.bind(this))\n this.observer.observe(this, { childList: true })\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback()\n this.observer?.disconnect()\n this.observer = undefined\n this.clearInputListeners()\n this.clearSuggestionsListeners()\n }\n\n protected override firstUpdated(cp: PropertyValues): void {\n super.firstUpdated(cp)\n this.firstSetup()\n }\n\n /**\n * Performs initial setup after the first update, ensuring that slotted input\n * and suggestions elements are configured.\n */\n async firstSetup(): Promise<void> {\n await this.updateComplete\n const input = this.shadowRoot?.querySelector('slot[name=\"input\"]') as HTMLSlotElement | null\n const suggestions = this.shadowRoot?.querySelector('slot[name=\"suggestions\"]') as HTMLSlotElement | null\n if (input) {\n const elements = input.assignedElements()\n if (elements.length > 0 && elements[0] instanceof HTMLElement) {\n this.setupInput(elements[0])\n }\n }\n if (suggestions) {\n const elements = suggestions.assignedElements()\n if (elements.length > 0 && elements[0] instanceof HTMLElement) {\n // Assuming the slotted element is ui-listbox or compatible\n this.setupSuggestions(elements[0] as UiListbox)\n }\n }\n }\n\n /**\n * Handles mutations observed on the component's slotted children.\n * This is used to set up or tear down input and suggestions elements when they are added or removed.\n * @param mutations An array of MutationRecord objects.\n */\n protected handleMutations(mutations: MutationRecord[]): void {\n for (const mutation of mutations) {\n if (mutation.type === 'childList') {\n for (const node of mutation.removedNodes) {\n if (node instanceof HTMLElement) {\n if (node.slot === 'input' && this.inputRef === node) {\n this.clearInputListeners()\n } else if (node.slot === 'suggestions' && this.suggestionsRef === node) {\n this.clearSuggestionsListeners()\n }\n }\n }\n for (const node of mutation.addedNodes) {\n if (node instanceof HTMLElement) {\n if (node.slot === 'input') {\n this.setupInput(node)\n } else if (node.slot === 'suggestions') {\n this.setupSuggestions(node as UiListbox)\n }\n }\n }\n }\n }\n }\n\n /**\n * Clears event listeners from the current input reference and resets it.\n */\n protected clearInputListeners(): void {\n if (this.inputRef) {\n this.inputRef.removeEventListener('focus', this.handleInputFocus)\n this.inputRef.removeEventListener('input', this.handleInput)\n this.inputRef.removeEventListener('keydown', this.handleKeydown as EventListener)\n this.inputRef.removeEventListener('blur', this.handleInputBlur)\n }\n this.inputRef = null\n }\n\n /**\n * Clears event listeners from the current suggestions reference and resets it.\n */\n protected clearSuggestionsListeners(): void {\n if (this.suggestionsRef) {\n this.suggestionsRef.removeEventListener('select', this.handleSuggestionSelect as EventListener)\n // If ui-listbox uses a slot for its items, listen to its slotchange\n this.suggestionsRef.removeEventListener('itemschange', this.handleSuggestionsSlotChange)\n if (this.suggestionsRef.matches(':popover-open')) {\n this.suggestionsRef.hidePopover()\n }\n }\n this.suggestionsRef = null\n }\n\n /**\n * Sets up the slotted input element.\n * Assigns an ID if necessary, sets up CSS anchoring, and attaches event listeners.\n * @param input The HTMLElement to be used as the input.\n */\n protected setupInput(input: HTMLElement): void {\n this.clearInputListeners() // Clear any old listeners\n if (!input.id) {\n this.inputId = `autocomplete-input-${Math.random().toString(36).substring(2, 15)}`\n input.id = this.inputId\n } else {\n this.inputId = input.id\n }\n // Ensure CSS anchor positioning can work\n input.style.setProperty('anchor-name', `--${this.inputId}`)\n\n this.inputRef = input as HTMLInputElement // Assuming it behaves like an input\n this.inputRef.addEventListener('focus', this.handleInputFocus)\n this.inputRef.addEventListener('input', this.handleInput)\n this.inputRef.addEventListener('keydown', this.handleKeydown as EventListener)\n this.inputRef.addEventListener('blur', this.handleInputBlur)\n\n // Apply initial filtering if suggestions are already present\n if (this.suggestionsRef) {\n this.suggestionsRef.style.setProperty('position-anchor', `--${this.inputId}`)\n this.filterSuggestions((this.inputRef as HTMLInputElement).value || '')\n }\n }\n\n /**\n * Sets up the slotted suggestions element (assumed to be a `UiListbox`).\n * Configures popover behavior, CSS anchoring, and attaches event listeners.\n * @param suggestionsElement The `UiListbox` element to be used for suggestions.\n */\n protected setupSuggestions(suggestionsElement: UiListbox): void {\n this.clearSuggestionsListeners() // Clear any old listeners\n\n this.suggestionsRef = suggestionsElement\n this.suggestionsRef.popover = 'manual'\n this.suggestionsRef.tabIndex = -1 // Prevent direct focus\n\n if (this.inputId) {\n this.suggestionsRef.style.setProperty('position-anchor', `--${this.inputId}`)\n }\n\n this.suggestionsRef.addEventListener('select', this.handleSuggestionSelect as EventListener)\n // The `List` dispatches `itemschange` when the slot changes, so we can listen to it.\n this.suggestionsRef.addEventListener('itemschange', this.handleSuggestionsSlotChange)\n\n // Initial filter\n this.filterSuggestions(this.inputRef ? (this.inputRef as HTMLInputElement).value : '')\n }\n\n /**\n * Handles the focus event on the input element.\n * Opens the suggestions popover if there are items to display.\n */\n @bound\n protected handleInputFocus(): void {\n const items = this.suggestionsRef?.items\n if (!items || items.length === 0) {\n // If no suggestions, do not open\n return\n }\n const active = items.find((item) => !item.hidden)\n if (active) {\n this.openSuggestions()\n this.filterSuggestions(this.inputRef ? (this.inputRef as HTMLInputElement).value : '')\n }\n }\n\n /**\n * Handles the input event on the input element.\n * Filters suggestions based on the input query and opens/closes the popover accordingly.\n * @param event The input event.\n */\n @bound\n protected handleInput(event: Event): void {\n this.openSuggestions()\n const query = (event.target as HTMLInputElement).value\n this.filterSuggestions(query)\n }\n\n /**\n * Handles keydown events on the input element for navigating and selecting suggestions.\n * - ArrowDown/ArrowUp: Navigates the suggestion list.\n * - Enter: Selects the highlighted suggestion.\n * - Escape: Closes the suggestions popover.\n * @param event The keyboard event.\n */\n @bound\n protected handleKeydown(event: KeyboardEvent): void {\n if (!this.suggestionsRef) return\n\n const { key } = event\n const isSuggestionsOpen = this.suggestionsRef.matches(':popover-open')\n\n if (['ArrowDown', 'ArrowUp'].includes(key)) {\n event.preventDefault()\n if (!isSuggestionsOpen) {\n this.openSuggestions()\n // Give popover a moment to open before trying to highlight\n requestAnimationFrame(() => this.navigateList(key))\n } else {\n this.navigateList(key)\n }\n } else if (key === 'Enter') {\n if (isSuggestionsOpen && this.suggestionsRef.highlightListItem) {\n event.preventDefault()\n this.suggestionsRef.notifySelect(this.suggestionsRef.highlightListItem)\n }\n } else if (key === 'Escape') {\n if (isSuggestionsOpen) {\n event.preventDefault()\n this.closeSuggestions()\n }\n }\n }\n\n /**\n * Navigates the suggestion list based on the pressed key.\n * @param key The key that was pressed (ArrowDown or ArrowUp).\n */\n protected navigateList(key: string): void {\n if (!this.suggestionsRef) return\n switch (key) {\n case 'ArrowDown':\n this.suggestionsRef.highlightNext()\n break\n case 'ArrowUp':\n this.suggestionsRef.highlightPrevious()\n break\n // Don't handle Home or End keys here, as they break the usability of the input.\n }\n }\n\n /**\n * Handles the blur event on the input element.\n * Closes the suggestions popover if focus moves outside the autocomplete component.\n */\n @bound\n protected handleInputBlur(): void {\n // We use the manual popover mode, so we need to close suggestions\n // when the input loses focus, but only the current active element is not part of the suggestions.\n requestAnimationFrame(() => {\n if (\n !this.inputRef?.contains(document.activeElement) &&\n (!this.suggestionsRef || !this.suggestionsRef.contains(document.activeElement))\n ) {\n this.closeSuggestions()\n }\n })\n }\n\n /**\n * Handles the `select` event dispatched by the `ui-listbox` when a suggestion is chosen.\n * Dispatches an `autocomplete` event and closes the popover.\n * @param event The custom event from `ui-listbox`.\n */\n @bound\n protected handleSuggestionSelect(event: CustomEvent): void {\n event.stopPropagation()\n const selectedItem = event.detail.item as UiListItem\n this.dispatchEvent(\n new CustomEvent('autocomplete', {\n detail: { item: selectedItem },\n bubbles: false,\n composed: false,\n })\n )\n this.closeSuggestions()\n }\n\n /**\n * Handles the `itemschange` event dispatched by the `ui-listbox` when its slotted items change.\n * Re-filters the suggestions.\n */\n @bound\n protected handleSuggestionsSlotChange(): void {\n const value = this.inputRef ? (this.inputRef as HTMLInputElement).value : ''\n if (!value) {\n return\n }\n this.openSuggestions()\n this.filterSuggestions(value)\n }\n\n /**\n * Opens the suggestions popover if it's not already open and there are visible items.\n */\n protected openSuggestions(): void {\n if (this.suggestionsRef && !this.suggestionsRef.matches(':popover-open')) {\n this.suggestionsRef.showPopover()\n }\n }\n\n /**\n * Closes the suggestions popover if it's open and clears any highlighted item.\n */\n protected closeSuggestions(): void {\n if (this.suggestionsRef && this.suggestionsRef.matches(':popover-open')) {\n this.suggestionsRef.hidePopover()\n }\n }\n\n /**\n * Filters the suggestions based on the provided query.\n * Hides items that do not match and manages the highlighted item state.\n * @param query The search query string.\n */\n protected filterSuggestions(query: string): void {\n if (!this.suggestionsRef) {\n return\n }\n\n const lowerCaseQuery = query.toLowerCase().trim()\n let firstVisibleItem: UiListItem | null = null\n\n // The `items` getter in `List.ts` (parent of UiListbox) correctly gets assigned elements.\n const items = this.suggestionsRef.items as UiListItem[]\n\n for (const item of items) {\n let matches = false\n if (lowerCaseQuery === '') {\n matches = true\n } else if (item.dataset.index) {\n const indexFields = item.dataset.index.split(' ').filter(Boolean)\n for (const field of indexFields) {\n const valueToSearch = item.dataset[field] || ''\n if (valueToSearch.toLowerCase().includes(lowerCaseQuery)) {\n matches = true\n break\n }\n }\n } else {\n const valueToSearch = item.dataset.value || item.textContent || ''\n matches = valueToSearch.toLowerCase().includes(lowerCaseQuery)\n }\n item.hidden = !matches\n if (matches && !firstVisibleItem) {\n firstVisibleItem = item\n }\n }\n\n // If the currently highlighted item is now hidden, try to highlight the first visible one or clear.\n if (this.suggestionsRef.highlightListItem?.hidden) {\n // the highlightListItem clears the highlighted item if it is not passed an argument.\n this.suggestionsRef?.highlightItem(firstVisibleItem)\n }\n if (!firstVisibleItem) {\n // Close if no items are visible\n this.closeSuggestions()\n }\n }\n\n protected override render(): TemplateResult {\n return html`\n <slot name=\"input\"></slot>\n <slot name=\"suggestions\"></slot>\n `\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"autocomplete.js","sourceRoot":"","sources":["../../../../../src/elements/autocomplete/internals/autocomplete.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAkC,MAAM,KAAK,CAAA;AACtE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAGnD,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;;sBAkHV,UAAU;;;;;;;;;;;;;;iBAA/B,YAAa,SAAQ,WAAU;;;mCAcjD,KAAK,EAAE;wCAcP,QAAQ,EAAE;4CAsKV,KAAK;uCAmBL,KAAK;yCAcL,KAAK;2CAkDL,KAAK;kDAmBL,KAAK;uDAkBL,KAAK;YA5SG,0KAAmB,OAAO,6BAAP,OAAO,yFAAK;YAc5B,yLAAS,YAAY,6BAAZ,YAAY,mGAA6B;YAuK9D,mMAAU,gBAAgB,6DAWzB;YAQD,oLAAU,WAAW,6DAIpB;YAUD,0LAAU,aAAa,6DA0BtB;YAwBD,gMAAU,eAAe,6DAWxB;YAQD,qNAAU,sBAAsB,6DAW/B;YAOD,oOAAU,2BAA2B,6DAOpC;;;QAjUkB,gBAAgB;YACjC,OAAO,IAAI,CAAA;QACb,CAAC;QAED;;WAEG;QACO,QAAQ,GARC,mDAAY,CAQM;QAM5B,2EAA6B,EAAE;QAExC;;;;;;;;;;;WAWG;UAbqC;QAJxC;;;WAGG;QACM,IAAmB,OAAO,6CAAK;QAA/B,IAAmB,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,WAAW,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAA;gBAChE,CAAC;gBACD,IAAI,CAAC,MAAM,GAAG,CAAC,OAAO,CAAA;gBACtB,IAAI,OAAO,IAAI,CAAC,gBAAgB,EAAE,CAAC;oBACjC,gBAAgB,GAAG,IAAI,CAAA;gBACzB,CAAC;YACH,CAAC;YAED,oGAAoG;YACpG,IAAI,IAAI,CAAC,cAAc,CAAC,iBAAiB,EAAE,MAAM,EAAE,CAAC;gBAClD,qFAAqF;gBACrF,IAAI,CAAC,cAAc,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAA;YACtD,CAAC;YACD,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBACtB,gCAAgC;gBAChC,IAAI,CAAC,gBAAgB,EAAE,CAAA;YACzB,CAAC;QACH,CAAC;QAEkB,MAAM;YACvB,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;YAC1C;;;;;cAKE;YACF,OAAO,IAAI,CAAA;;WAEJ,EAAE;;;;;;;;;;6BAUgB,YAAY;iCACR,OAAO;;;;;;;;;;;;;;;;KAgBnC,CAAA;QACH,CAAC;;;AA1kBH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+GG;AACH,4BA2dC","sourcesContent":["import { html, LitElement, PropertyValues, TemplateResult } from 'lit'\nimport { property, state } from 'lit/decorators.js'\nimport type UiListbox from '../../../md/listbox/internals/Listbox.js'\nimport type UiListItem from '../../../md/list/internals/ListItem.js'\nimport { bound } from '../../../decorators/bound.js'\n\n/**\n * An accessible and performant autocomplete component that enhances a text input with a list of suggestions.\n *\n * The `autocomplete-input` component provides a flexible way to add autocomplete functionality\n * to any text input. It works by coordinating a slotted input element with a slotted `ui-listbox`\n * containing suggestions.\n *\n * Key Features:\n *\n * - **Popover Management**: Automatically shows and hides the suggestions popover based on input focus\n * and user interaction.\n * - **Keyboard Navigation**: Allows users to navigate suggestions using ArrowUp, ArrowDown keys directly\n * from the input. Enter selects a suggestion, and Escape closes the popover.\n * The suggestion list itself never gains focus.\n * - **Dynamic Filtering**: Filters the list of suggestions as the user types into the input. Items not matching\n * the query are hidden (not removed).\n * - By default, filtering checks `item.dataset.value` and then `item.textContent`.\n * - If a `ui-list-item` has a `data-index` attribute (e.g., `data-index=\"name email\"`), filtering will search\n * within the specified `data-*` attributes (e.g., `data-name`, `data-email`).\n * - **Mutation Awareness**: Reacts to changes in slotted suggestions, re-filtering them if necessary.\n * - **Event-Driven**: Notifies the application via an `autocomplete` event when a suggestion is selected.\n * The component itself does not modify the input's value, giving the application author full control.\n *\n * ### Accessibility\n *\n * The `autocomplete-input` component is designed with accessibility at its core:\n * - **Keyboard Navigation**: Full keyboard support for navigating suggestions (ArrowUp, ArrowDown),\n * selecting (Enter), and closing (Escape), all while focus remains on the input field.\n * - **ARIA Attributes**: While the `autocomplete-input` manages ARIA attributes related to the popover's\n * state, the slotted `ui-listbox` is responsible for its internal ARIA roles and states\n * (e.g., `role=\"listbox\"`, `aria-activedescendant`).\n * - **Labeling Suggestions**: It is **crucial** for accessibility that the slotted `ui-listbox`\n * has an `aria-label` attribute. This provides a descriptive name for the list of suggestions,\n * which is announced by screen readers.\n *\n * The component uses CSS anchor positioning to place the suggestions popover relative to the input.\n * Ensure your `ui-listbox` is styled appropriately for popover display (e.g., `popover=\"manual\"`, `position-anchor`).\n * The component will manage `showPopover()` and `hidePopover()` calls.\n *\n * @slot input - The input element that will be used for autocomplete. This element should be an `HTMLInputElement`\n * or behave like one (have a `value` property and dispatch `input`, `focus`, `blur`, and `keydown`\n * events).\n * @slot suggestions - The `ui-listbox` element containing `ui-list-item` elements as suggestions.\n * @slot anchor - An optional element that points to element that will be used as the anchor for the popover.\n * This is useful if you want to position the suggestions relative to a different element than the input.\n * If not provided, the input element will be used as the anchor.\n * @slot Any additional content that should be rendered inside the component.\n *\n * @fires autocomplete - Dispatched when a suggestion is selected by the user (e.g., via click or Enter key).\n * The `event.detail` object contains:\n * - `item`: The selected `UiListItem` instance.\n *\n * @example\n * ```html\n * <autocomplete-input @autocomplete=\"${this.handleAutocompleteSelection}\">\n * <input slot=\"input\" type=\"text\" placeholder=\"Search fruits...\" />\n * <ui-listbox slot=\"suggestions\">\n * <ui-list-item data-value=\"apple\">Apple</ui-list-item>\n * <ui-list-item data-value=\"banana\">Banana</ui-list-item>\n * <ui-list-item data-value=\"cherry\">Cherry</ui-list-item>\n * </ui-listbox>\n * <!-- With aria-label for accessibility -->\n * <ui-listbox slot=\"suggestions\" aria-label=\"Fruit suggestions\">\n * <ui-list-item data-value=\"apple\">Apple</ui-list-item>\n * <ui-list-item data-value=\"banana\">Banana</ui-list-item>\n * <ui-list-item data-value=\"cherry\">Cherry</ui-list-item>\n * </ui-listbox>\n * </autocomplete-input>\n *\n * <script>\n * // In your component/script\n * handleAutocompleteSelection(event) {\n * const selectedItem = event.detail.item;\n * const inputElement = this.shadowRoot.querySelector('input[slot=\"input\"]');\n * if (inputElement) {\n * inputElement.value = selectedItem.dataset.value || selectedItem.textContent;\n * }\n * console.log('Selected:', selectedItem.dataset.value);\n * }\n * </script>\n * ```\n *\n * @example Dynamic filtering with `data-index`\n * ```html\n * <autocomplete-input @autocomplete=\"${this.handleUserSelection}\">\n * <input slot=\"input\" type=\"text\" placeholder=\"Search users...\" />\n * <ui-listbox slot=\"suggestions\" aria-label=\"User suggestions\">\n * <ui-list-item data-id=\"1\" data-name=\"Alice Wonderland\" data-email=\"alice@example.com\" data-index=\"name email\">\n * Alice Wonderland\n * <span slot=\"supporting-text\">alice@example.com</span>\n * </ui-list-item>\n * <ui-list-item data-id=\"2\" data-name=\"Bob The Builder\" data-email=\"bob@example.com\" data-index=\"name email\">\n * Bob The Builder\n * <span slot=\"supporting-text\">bob@example.com</span>\n * </ui-list-item>\n * </ui-listbox>\n * </autocomplete-input>\n *\n * <script>\n * // In your component/script\n * handleUserSelection(event) {\n * const selectedItem = event.detail.item;\n * const inputElement = this.shadowRoot.querySelector('input[slot=\"input\"]');\n * if (inputElement) {\n * // You might want to display the name, but store the ID\n * inputElement.value = selectedItem.dataset.name;\n * }\n * console.log('Selected user ID:', selectedItem.dataset.id);\n * }\n * </script>\n * ```\n */\nexport default class Autocomplete extends LitElement {\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n return this\n }\n\n /**\n * The MutationObserver instance used to watch for changes in slotted children.\n */\n protected observer?: MutationObserver\n\n /**\n * The ID of the input element, generated if not provided.\n * This is used for CSS anchoring and to ensure unique IDs for accessibility.\n */\n @state() protected accessor inputId = ''\n\n /**\n * The position area for the suggestions popover.\n * This can be 'bottom' or 'top', depending on available space.\n * Default is 'bottom'.\n *\n * Note, this is set dynamically based on available space\n * and the position of the input element. This only sets the initial value.\n *\n * @attribute\n * @type {'bottom' | 'top'}\n * @default 'bottom'\n */\n @property() accessor positionArea: 'bottom' | 'top' = 'bottom'\n\n /**\n * The reference to the slotted input element.\n * This should be an `HTMLInputElement` or behave like one.\n */\n protected inputRef?: HTMLInputElement | HTMLElement | null\n /**\n * The reference to the slotted suggestions element, which should be a `ui-listbox`.\n * This is used to manage the suggestions popover and filtering.\n */\n protected suggestionsRef?: UiListbox | null\n\n /**\n * Checks if the suggestions popover is currently open.\n */\n get opened(): boolean {\n return this.suggestionsRef?.matches(':popover-open') || false\n }\n\n override connectedCallback(): void {\n super.connectedCallback()\n this.observer = new MutationObserver(this.handleMutations.bind(this))\n this.observer.observe(this, { childList: true })\n if (!this.id) {\n this.id = `autocomplete-${Math.random().toString(36).substring(2, 15)}`\n }\n this.classList.add(this.id)\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback()\n this.observer?.disconnect()\n this.observer = undefined\n this.clearInputListeners()\n this.clearSuggestionsListeners()\n }\n\n protected override firstUpdated(cp: PropertyValues): void {\n super.firstUpdated(cp)\n this.firstSetup()\n }\n\n /**\n * Performs initial setup after the first update, ensuring that slotted input\n * and suggestions elements are configured.\n */\n async firstSetup(): Promise<void> {\n await this.updateComplete\n const input = this.querySelector('[slot=\"input\"]') as HTMLElement | null\n const suggestions = this.querySelector('[slot=\"suggestions\"]') as HTMLElement | null\n if (input) {\n this.setupInput(input)\n }\n if (suggestions) {\n this.setupSuggestions(suggestions as UiListbox)\n }\n }\n\n /**\n * Handles mutations observed on the component's slotted children.\n * This is used to set up or tear down input and suggestions elements when they are added or removed.\n * @param mutations An array of MutationRecord objects.\n */\n protected handleMutations(mutations: MutationRecord[]): void {\n for (const mutation of mutations) {\n if (mutation.type === 'childList') {\n for (const node of mutation.removedNodes) {\n if (node instanceof HTMLElement) {\n if (node.slot === 'input' && this.inputRef === node) {\n this.clearInputListeners()\n } else if (node.slot === 'suggestions' && this.suggestionsRef === node) {\n this.clearSuggestionsListeners()\n }\n }\n }\n for (const node of mutation.addedNodes) {\n if (node instanceof HTMLElement) {\n if (node.slot === 'input') {\n this.setupInput(node)\n } else if (node.slot === 'suggestions') {\n this.setupSuggestions(node as UiListbox)\n }\n }\n }\n }\n }\n }\n\n /**\n * Clears event listeners from the current input reference and resets it.\n */\n protected clearInputListeners(): void {\n if (this.inputRef) {\n this.inputRef.removeEventListener('focus', this.handleInputFocus)\n this.inputRef.removeEventListener('input', this.handleInput)\n this.inputRef.removeEventListener('keydown', this.handleKeydown as EventListener)\n this.inputRef.removeEventListener('blur', this.handleInputBlur)\n }\n this.inputRef = null\n }\n\n /**\n * Clears event listeners from the current suggestions reference and resets it.\n */\n protected clearSuggestionsListeners(): void {\n if (this.suggestionsRef) {\n this.suggestionsRef.removeEventListener('select', this.handleSuggestionSelect as EventListener)\n // If ui-listbox uses a slot for its items, listen to its slotchange\n this.suggestionsRef.removeEventListener('itemschange', this.handleSuggestionsSlotChange)\n if (this.suggestionsRef.matches(':popover-open')) {\n this.suggestionsRef.hidePopover()\n }\n }\n this.suggestionsRef = null\n }\n\n /**\n * Sets up the slotted input element.\n * Assigns an ID if necessary, sets up CSS anchoring, and attaches event listeners.\n * @param input The HTMLElement to be used as the input.\n */\n protected setupInput(input: HTMLElement): void {\n this.clearInputListeners() // Clear any old listeners\n if (!input.id) {\n this.inputId = `autocomplete-input-${Math.random().toString(36).substring(2, 15)}`\n input.id = this.inputId\n } else {\n this.inputId = input.id\n }\n const anchorElement = this.querySelector('[slot=\"anchor\"]') as HTMLElement | null\n // Ensure CSS anchor positioning can work\n const anchor = anchorElement || input\n anchor.style.setProperty('anchor-name', `--${this.inputId}`)\n\n this.inputRef = input as HTMLInputElement // Assuming it behaves like an input\n this.inputRef.addEventListener('focus', this.handleInputFocus)\n this.inputRef.addEventListener('input', this.handleInput)\n this.inputRef.addEventListener('keydown', this.handleKeydown as EventListener)\n this.inputRef.addEventListener('blur', this.handleInputBlur)\n }\n\n /**\n * Sets up the slotted suggestions element (assumed to be a `UiListbox`).\n * Configures popover behavior, CSS anchoring, and attaches event listeners.\n * @param suggestionsElement The `UiListbox` element to be used for suggestions.\n */\n protected setupSuggestions(suggestionsElement: UiListbox): void {\n this.clearSuggestionsListeners() // Clear any old listeners\n\n this.suggestionsRef = suggestionsElement\n this.suggestionsRef.popover = 'manual'\n this.suggestionsRef.tabIndex = -1 // Prevent direct focus\n\n this.suggestionsRef.addEventListener('select', this.handleSuggestionSelect as EventListener)\n // The `List` dispatches `itemschange` when the slot changes, so we can listen to it.\n this.suggestionsRef.addEventListener('itemschange', this.handleSuggestionsSlotChange)\n\n // Initial filter\n this.filterSuggestions(this.inputRef ? (this.inputRef as HTMLInputElement).value : '')\n }\n\n /**\n * Handles the focus event on the input element.\n * Opens the suggestions popover if there are items to display.\n */\n @bound\n protected handleInputFocus(): void {\n const items = this.suggestionsRef?.items\n if (!items || items.length === 0) {\n // If no suggestions, do not open\n return\n }\n const active = items.find((item) => !item.hidden)\n if (active) {\n this.openSuggestions()\n this.filterSuggestions(this.inputRef ? (this.inputRef as HTMLInputElement).value : '')\n }\n }\n\n /**\n * Handles the input event on the input element.\n * Filters suggestions based on the input query and opens/closes the popover accordingly.\n * @param event The input event.\n */\n @bound\n protected handleInput(event: Event): void {\n this.openSuggestions()\n const query = (event.target as HTMLInputElement).value\n this.filterSuggestions(query)\n }\n\n /**\n * Handles keydown events on the input element for navigating and selecting suggestions.\n * - ArrowDown/ArrowUp: Navigates the suggestion list.\n * - Enter: Selects the highlighted suggestion.\n * - Escape: Closes the suggestions popover.\n * @param event The keyboard event.\n */\n @bound\n protected handleKeydown(event: KeyboardEvent): void {\n if (!this.suggestionsRef) return\n\n const { key } = event\n const isSuggestionsOpen = this.suggestionsRef.matches(':popover-open')\n\n if (['ArrowDown', 'ArrowUp'].includes(key)) {\n event.preventDefault()\n if (!isSuggestionsOpen) {\n this.openSuggestions()\n // Give popover a moment to open before trying to highlight\n requestAnimationFrame(() => this.navigateList(key))\n } else {\n this.navigateList(key)\n }\n } else if (key === 'Enter') {\n if (isSuggestionsOpen && this.suggestionsRef.highlightListItem) {\n event.preventDefault()\n this.suggestionsRef.notifySelect(this.suggestionsRef.highlightListItem)\n }\n } else if (key === 'Escape') {\n if (isSuggestionsOpen) {\n event.preventDefault()\n this.closeSuggestions()\n }\n }\n }\n\n /**\n * Navigates the suggestion list based on the pressed key.\n * @param key The key that was pressed (ArrowDown or ArrowUp).\n */\n protected navigateList(key: string): void {\n if (!this.suggestionsRef) return\n switch (key) {\n case 'ArrowDown':\n this.suggestionsRef.highlightNext()\n break\n case 'ArrowUp':\n this.suggestionsRef.highlightPrevious()\n break\n // Don't handle Home or End keys here, as they break the usability of the input.\n }\n }\n\n /**\n * Handles the blur event on the input element.\n * Closes the suggestions popover if focus moves outside the autocomplete component.\n */\n @bound\n protected handleInputBlur(): void {\n // We use the manual popover mode, so we need to close suggestions\n // when the input loses focus, but only the current active element is not part of the suggestions.\n requestAnimationFrame(() => {\n if (\n !this.inputRef?.contains(document.activeElement) &&\n (!this.suggestionsRef || !this.suggestionsRef.contains(document.activeElement))\n ) {\n this.closeSuggestions()\n }\n })\n }\n\n /**\n * Handles the `select` event dispatched by the `ui-listbox` when a suggestion is chosen.\n * Dispatches an `autocomplete` event and closes the popover.\n * @param event The custom event from `ui-listbox`.\n */\n @bound\n protected handleSuggestionSelect(event: CustomEvent): void {\n event.stopPropagation()\n const selectedItem = event.detail.item as UiListItem\n this.dispatchEvent(\n new CustomEvent('autocomplete', {\n detail: { item: selectedItem },\n bubbles: false,\n composed: false,\n })\n )\n this.closeSuggestions()\n }\n\n /**\n * Handles the `itemschange` event dispatched by the `ui-listbox` when its slotted items change.\n * Re-filters the suggestions.\n */\n @bound\n protected handleSuggestionsSlotChange(): void {\n const value = this.inputRef ? (this.inputRef as HTMLInputElement).value : ''\n if (!value) {\n return\n }\n this.openSuggestions()\n this.filterSuggestions(value)\n }\n\n /**\n * Opens the suggestions popover if it's not already open and there are visible items.\n */\n protected openSuggestions(): void {\n const popover = this.suggestionsRef\n if (!popover || popover.matches(':popover-open')) {\n return\n }\n // we need to open the popover first to make any measurements\n popover.showPopover()\n const anchor = (this.querySelector('[slot=\"anchor\"]') as HTMLElement | null) || this.inputRef\n if (!anchor) {\n return\n }\n this.positionArea = this.decidePositionArea(popover, anchor)\n }\n\n /**\n * Decides the position area for the popover based on available space.\n * It checks if there is enough space below or above the anchor element and decides accordingly.\n *\n * We need to do this because we set the popover height to `100%`, `-webkit-fill-available`, or `-moz-available`\n * and it makes the popover to always open at the bottom, even if there is no space. The `position-try-fallbacks`\n * will not work in this case, because from its perspective there is always enough space, even if that will cause\n * the popover to have a height of just a few pixels.\n *\n * @param popover The popover element to position.\n * @param anchor The anchor element relative to which the popover will be positioned.\n * @returns 'top' or 'bottom' based on available space.\n */\n protected decidePositionArea(popover: HTMLElement, anchor: HTMLElement): 'top' | 'bottom' {\n let newArea: 'top' | 'bottom' = 'bottom'\n // Get bounding rectangles\n const anchorRect = anchor.getBoundingClientRect()\n const viewportHeight = window.innerHeight\n\n const spaceBelow = viewportHeight - anchorRect.bottom\n const spaceAbove = anchorRect.top\n\n // Estimate a typical/minimum height the popover might need to be useful\n const popoverThresholdHeight = popover.scrollHeight || 150\n if (spaceBelow < popoverThresholdHeight && spaceAbove > spaceBelow && spaceAbove > popoverThresholdHeight) {\n // Not enough space below, but more (and sufficient) space above\n newArea = 'top'\n } else if (spaceBelow < popoverThresholdHeight && spaceAbove > spaceBelow) {\n // Not enough space below, and space above is more than space below (even if not \"sufficient\")\n newArea = 'top'\n } else {\n newArea = 'bottom' // Default to bottom if enough space or if top is worse\n }\n return newArea\n }\n\n /**\n * Closes the suggestions popover if it's open and clears any highlighted item.\n */\n protected closeSuggestions(): void {\n if (this.suggestionsRef && this.suggestionsRef.matches(':popover-open')) {\n this.suggestionsRef.hidePopover()\n }\n }\n\n /**\n * Filters the suggestions based on the provided query.\n * Hides items that do not match and manages the highlighted item state.\n * @param query The search query string.\n */\n protected filterSuggestions(query: string): void {\n if (!this.suggestionsRef) {\n return\n }\n\n const lowerCaseQuery = query.toLowerCase().trim()\n let firstVisibleItem: UiListItem | null = null\n\n // The `items` getter in `List.ts` (parent of UiListbox) correctly gets assigned elements.\n const items = this.suggestionsRef.items as UiListItem[]\n\n for (const item of items) {\n let matches = false\n if (lowerCaseQuery === '') {\n matches = true\n } else if (item.dataset.index) {\n const indexFields = item.dataset.index.split(' ').filter(Boolean)\n for (const field of indexFields) {\n const valueToSearch = item.dataset[field] || ''\n if (valueToSearch.toLowerCase().includes(lowerCaseQuery)) {\n matches = true\n break\n }\n }\n } else {\n const valueToSearch = item.dataset.value || item.textContent || ''\n matches = valueToSearch.toLowerCase().includes(lowerCaseQuery)\n }\n item.hidden = !matches\n if (matches && !firstVisibleItem) {\n firstVisibleItem = item\n }\n }\n\n // If the currently highlighted item is now hidden, try to highlight the first visible one or clear.\n if (this.suggestionsRef.highlightListItem?.hidden) {\n // the highlightListItem clears the highlighted item if it is not passed an argument.\n this.suggestionsRef?.highlightItem(firstVisibleItem)\n }\n if (!firstVisibleItem) {\n // Close if no items are visible\n this.closeSuggestions()\n }\n }\n\n protected override render(): TemplateResult {\n const { id, positionArea, inputId } = this\n /*\n position-try-fallbacks:\n flip-block,\n flip-inline,\n flip-block flip-inline;\n */\n return html`\n <style>\n .${id} {\n display: inline-block;\n\n [popover] {\n border: none;\n margin: 0;\n\n box-shadow: var(--md-sys-elevation-1);\n border-radius: var(--md-sys-shape-corner-medium);\n\n position-area: ${positionArea};\n position-anchor: --${inputId};\n\n overflow: auto;\n /* We try 100% and then vendor options which are more accurate */\n height: 100%;\n height: -webkit-fill-available;\n height: -moz-available;\n max-height: max-content;\n width: anchor-size(width);\n }\n\n [popover]:not(:popover-open) {\n display: none;\n }\n }\n </style>\n `\n }\n}\n"]}
|
|
@@ -129,12 +129,13 @@ export default class MarkedHighlight extends LitElement {
|
|
|
129
129
|
* @returns A reference to the output element.
|
|
130
130
|
*/
|
|
131
131
|
get outputElement(): HTMLElement | null;
|
|
132
|
-
protected
|
|
132
|
+
protected willUpdate(cp: PropertyValues<this>): void;
|
|
133
133
|
protected markdownElement?: HTMLScriptElement | null;
|
|
134
134
|
protected attachedValue: boolean;
|
|
135
135
|
firstUpdated(): void;
|
|
136
136
|
connectedCallback(): void;
|
|
137
137
|
disconnectedCallback(): void;
|
|
138
|
+
protected processScript(): Promise<void>;
|
|
138
139
|
/**
|
|
139
140
|
* Renders `markdown` into this element's DOM.
|
|
140
141
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkedHighlight.d.ts","sourceRoot":"","sources":["../../../../src/elements/highlight/MarkedHighlight.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAMtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU;IACrD;;;OAGG;IACyB,QAAQ,CAAC,QA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