@gooddata/sdk-ui-kit 11.42.0-alpha.2 → 11.42.0-alpha.3

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 (35) hide show
  1. package/esm/@ui/UiAutocomplete/UiAutocomplete.d.ts +9 -0
  2. package/esm/@ui/UiAutocomplete/UiAutocomplete.d.ts.map +1 -0
  3. package/esm/@ui/UiAutocomplete/UiAutocomplete.js +230 -0
  4. package/esm/@ui/UiAutocomplete/types.d.ts +61 -0
  5. package/esm/@ui/UiAutocomplete/types.d.ts.map +1 -0
  6. package/esm/@ui/UiAutocomplete/types.js +2 -0
  7. package/esm/@ui/UiAutocomplete/useAsyncListSource.d.ts +42 -0
  8. package/esm/@ui/UiAutocomplete/useAsyncListSource.d.ts.map +1 -0
  9. package/esm/@ui/UiAutocomplete/useAsyncListSource.js +112 -0
  10. package/esm/@ui/UiCombobox/UiComboboxInput.d.ts +7 -2
  11. package/esm/@ui/UiCombobox/UiComboboxInput.d.ts.map +1 -1
  12. package/esm/@ui/UiCombobox/UiComboboxInput.js +2 -2
  13. package/esm/@ui/UiCombobox/useCombobox.d.ts.map +1 -1
  14. package/esm/@ui/UiCombobox/useCombobox.js +8 -15
  15. package/esm/@ui/UiCombobox/useComboboxChrome.d.ts +16 -5
  16. package/esm/@ui/UiCombobox/useComboboxChrome.d.ts.map +1 -1
  17. package/esm/@ui/UiCombobox/useComboboxChrome.js +53 -25
  18. package/esm/@ui/UiCombobox/useComboboxSelection.d.ts +2 -3
  19. package/esm/@ui/UiCombobox/useComboboxSelection.d.ts.map +1 -1
  20. package/esm/@ui/UiCombobox/useComboboxSelection.js +5 -9
  21. package/esm/@ui/UiTags/UiTags.js +1 -1
  22. package/esm/WidgetNotice/WidgetNotice.d.ts.map +1 -1
  23. package/esm/WidgetNotice/WidgetNotice.js +1 -1
  24. package/esm/index.d.ts +2 -0
  25. package/esm/index.d.ts.map +1 -1
  26. package/esm/index.js +1 -0
  27. package/esm/locales.d.ts +17 -0
  28. package/esm/locales.d.ts.map +1 -1
  29. package/esm/locales.js +7 -0
  30. package/esm/sdk-ui-kit.d.ts +78 -2
  31. package/package.json +11 -11
  32. package/src/@ui/UiAutocomplete/UiAutocomplete.scss +53 -0
  33. package/src/@ui/index.scss +1 -0
  34. package/styles/css/main.css +46 -0
  35. package/styles/css/main.css.map +1 -1
@@ -0,0 +1,9 @@
1
+ import type { IUiAutocompleteOption, IUiAutocompleteProps } from "./types.js";
2
+ /**
3
+ * Async autocomplete: text input + sectioned listbox driven by a `loadOptions`
4
+ * loader. Implements the ARIA combobox+listbox APG pattern.
5
+ *
6
+ * @internal
7
+ */
8
+ export declare function UiAutocomplete<T extends IUiAutocompleteOption = IUiAutocompleteOption>({ loadOptions, selectedIds, onSelect, debounceMs, messages, accessibilityConfig, dataTestId }: IUiAutocompleteProps<T>): import("react/jsx-runtime").JSX.Element;
9
+ //# sourceMappingURL=UiAutocomplete.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UiAutocomplete.d.ts","sourceRoot":"","sources":["../../../src/@ui/UiAutocomplete/UiAutocomplete.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAA0B,MAAM,YAAY,CAAC;AA+BtG;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,qBAAqB,GAAG,qBAAqB,EAAE,EACpF,WAAW,EACX,WAA6B,EAC7B,QAAQ,EACR,UAAgC,EAChC,QAAQ,EACR,mBAAmB,EACnB,UAAU,EACb,EAAE,oBAAoB,CAAC,CAAC,CAAC,2CAkOzB"}
@@ -0,0 +1,230 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // (C) 2026 GoodData Corporation
3
+ import { Fragment, useCallback, useId, useMemo } from "react";
4
+ import { useIntl } from "react-intl";
5
+ import { uiAutocompleteMessages } from "../../locales.js";
6
+ import { bem } from "../@utils/bem.js";
7
+ import { makeKeyboardNavigation } from "../@utils/keyboardNavigation.js";
8
+ import { UiComboboxContextProvider } from "../UiCombobox/UiComboboxContext.js";
9
+ import { UiComboboxInput } from "../UiCombobox/UiComboboxInput.js";
10
+ import { UiComboboxListItem } from "../UiCombobox/UiComboboxListItem.js";
11
+ import { UiComboboxPopup } from "../UiCombobox/UiComboboxPopup.js";
12
+ import { useComboboxChrome } from "../UiCombobox/useComboboxChrome.js";
13
+ import { UiSectionHeading } from "../UiSectionHeading/UiSectionHeading.js";
14
+ import { useAsyncListSource } from "./useAsyncListSource.js";
15
+ const { b, e } = bem("gd-ui-kit-autocomplete");
16
+ const DEFAULT_DEBOUNCE_MS = 400;
17
+ // Per-instance, per-generation synthetic id for the Load-more row; activating
18
+ // it triggers a page fetch instead of `onSelect`. `listboxId` keeps it unique
19
+ // across autocompletes on one page; `generation` makes it differ once the
20
+ // query reloads, so a stale highlight can't carry onto the next query's row.
21
+ const loadMoreId = (listboxId, generation) => `${listboxId}-load-more-${generation}`;
22
+ // Stable default so an omitted `selectedIds` doesn't feed a fresh array into the
23
+ // memo deps every render.
24
+ const NO_SELECTED_IDS = [];
25
+ // Mirrors `useCombobox`'s key map. Space, Home and End are left to the input
26
+ // so the user can edit the query text natively.
27
+ const autocompleteKeys = makeKeyboardNavigation({
28
+ onArrowDown: [{ code: "ArrowDown" }],
29
+ onArrowUp: [{ code: "ArrowUp" }],
30
+ onEnter: [{ code: ["Enter", "NumpadEnter"] }],
31
+ onEscape: [{ code: "Escape" }],
32
+ });
33
+ /**
34
+ * Async autocomplete: text input + sectioned listbox driven by a `loadOptions`
35
+ * loader. Implements the ARIA combobox+listbox APG pattern.
36
+ *
37
+ * @internal
38
+ */
39
+ export function UiAutocomplete({ loadOptions, selectedIds = NO_SELECTED_IDS, onSelect, debounceMs = DEFAULT_DEBOUNCE_MS, messages, accessibilityConfig, dataTestId, }) {
40
+ const intl = useIntl();
41
+ const listboxId = useId();
42
+ const copy = useMemo(() => ({
43
+ searchPlaceholder: messages?.searchPlaceholder ?? intl.formatMessage(uiAutocompleteMessages.searchPlaceholder),
44
+ stateLoading: messages?.stateLoading ?? intl.formatMessage(uiAutocompleteMessages.stateLoading),
45
+ stateError: messages?.stateError ?? intl.formatMessage(uiAutocompleteMessages.stateError),
46
+ stateNoMatch: messages?.stateNoMatch ?? intl.formatMessage(uiAutocompleteMessages.stateNoMatch),
47
+ loadMore: messages?.loadMore ?? intl.formatMessage(uiAutocompleteMessages.loadMore),
48
+ }), [intl, messages]);
49
+ const source = useAsyncListSource(loadOptions, { debounceMs });
50
+ // The Load-more row's id is stamped with the load generation, so a highlight
51
+ // left on it before a query change can't re-attach to the next query's row
52
+ // (a constant id would survive and let Enter page the wrong query — the
53
+ // synthetic row is the one id the by-id highlight tracking can't otherwise
54
+ // tell apart across queries, since real options carry distinct ids).
55
+ const loadMoreRowId = loadMoreId(listboxId, source.generation);
56
+ const selectedIdSet = useMemo(() => new Set(selectedIds), [selectedIds]);
57
+ // Flat list of the rows the highlight can land on. Section headings and
58
+ // status rows render around it but never participate.
59
+ const focusableOptions = useMemo(() => {
60
+ const options = [];
61
+ for (const section of source.sections) {
62
+ for (const option of section.options) {
63
+ if (selectedIdSet.has(option.id)) {
64
+ continue;
65
+ }
66
+ options.push({ id: option.id, label: option.label });
67
+ }
68
+ }
69
+ if (source.hasNextPage && source.status !== "loadingMore") {
70
+ options.push({ id: loadMoreRowId, label: copy.loadMore });
71
+ }
72
+ return options;
73
+ }, [source.sections, source.hasNextPage, source.status, selectedIdSet, copy.loadMore, loadMoreRowId]);
74
+ // Chrome tracks the highlight by row id, so a row that disappears (results
75
+ // change, Load-more row removed while its page loads) drops the highlight
76
+ // on its own — no manual resets to keep in sync.
77
+ const chrome = useComboboxChrome(focusableOptions);
78
+ const activeOptionData = useMemo(() => {
79
+ if (!chrome.activeOption) {
80
+ return undefined;
81
+ }
82
+ if (chrome.activeOption.id === loadMoreRowId) {
83
+ return "loadMore";
84
+ }
85
+ return findOptionById(source.sections, chrome.activeOption.id);
86
+ }, [chrome.activeOption, source.sections, loadMoreRowId]);
87
+ const handleSelect = useCallback((target) => {
88
+ if (target === "loadMore") {
89
+ // Drop the highlight while the next page loads: the Load-more row
90
+ // disappears, and a real option highlighted beforehand (e.g. clicked
91
+ // Load-more without hovering it first) must not stay Enter-armed.
92
+ chrome.setActiveIndex(null);
93
+ source.loadMore();
94
+ return;
95
+ }
96
+ onSelect(target);
97
+ // Clear the input + re-prime the loader so the next open shows the
98
+ // unfiltered first page rather than the previous query's results.
99
+ source.reset();
100
+ chrome.setIsOpen(false);
101
+ }, [chrome, source, onSelect]);
102
+ // Reopening after a failed load re-runs it, so every open path (click, type,
103
+ // and the keyboard arrows below) routes through this first to recover.
104
+ const retryIfErrored = useCallback(() => {
105
+ if (!chrome.isOpen && source.status === "error") {
106
+ source.retry();
107
+ }
108
+ }, [chrome.isOpen, source]);
109
+ const onInputKeyDown = useMemo(() => {
110
+ const onEnter = chrome.isOpen && activeOptionData ? () => handleSelect(activeOptionData) : undefined;
111
+ // Leave Escape unhandled when idle so an enclosing modal can dismiss.
112
+ const hasSomethingToClose = chrome.isOpen || source.inputValue.length > 0;
113
+ const onEscape = hasSomethingToClose
114
+ ? (event) => {
115
+ // Stop the native event too so an enclosing UiModalDialog's
116
+ // document Escape listener doesn't dismiss the whole dialog.
117
+ event.nativeEvent.stopPropagation();
118
+ if (chrome.isOpen) {
119
+ chrome.setIsOpen(false);
120
+ return;
121
+ }
122
+ source.reset();
123
+ }
124
+ : undefined;
125
+ return autocompleteKeys({
126
+ onArrowDown: () => {
127
+ retryIfErrored();
128
+ chrome.focusByDelta(1);
129
+ },
130
+ onArrowUp: () => {
131
+ retryIfErrored();
132
+ chrome.focusByDelta(-1);
133
+ },
134
+ onEnter,
135
+ onEscape,
136
+ });
137
+ }, [chrome, source, activeOptionData, handleSelect, retryIfErrored]);
138
+ const selectOptionFromContext = useCallback((option) => {
139
+ if (option.id === loadMoreRowId) {
140
+ handleSelect("loadMore");
141
+ return;
142
+ }
143
+ const resolved = findOptionById(source.sections, option.id);
144
+ if (resolved) {
145
+ handleSelect(resolved);
146
+ }
147
+ }, [handleSelect, source.sections, loadMoreRowId]);
148
+ // Stay visible across loading / error / no-match so the status row reaches
149
+ // the user; the sync combobox's "hide when empty" default does not apply here.
150
+ const shouldRenderPopup = chrome.isOpen;
151
+ const setIsOpen = useCallback((open) => {
152
+ if (open) {
153
+ retryIfErrored();
154
+ }
155
+ chrome.setIsOpen(open);
156
+ }, [chrome, retryIfErrored]);
157
+ const state = useMemo(() => ({
158
+ inputValue: source.inputValue,
159
+ onInputChange: (next) => {
160
+ source.setInputValue(next);
161
+ setIsOpen(true);
162
+ },
163
+ onInputKeyDown,
164
+ onInputBlur: () => chrome.setIsOpen(false),
165
+ availableOptions: focusableOptions,
166
+ activeIndex: chrome.activeIndex,
167
+ setActiveIndex: chrome.setActiveIndex,
168
+ activeOption: chrome.activeOption,
169
+ selectedOption: undefined,
170
+ selectOption: selectOptionFromContext,
171
+ isOpen: chrome.isOpen,
172
+ setIsOpen,
173
+ shouldRenderPopup,
174
+ anchorRef: chrome.anchorRef,
175
+ registerItemRef: chrome.registerItemRef,
176
+ creatable: false,
177
+ listboxId,
178
+ }), [
179
+ chrome,
180
+ source,
181
+ setIsOpen,
182
+ focusableOptions,
183
+ shouldRenderPopup,
184
+ onInputKeyDown,
185
+ selectOptionFromContext,
186
+ listboxId,
187
+ ]);
188
+ const visibleSections = source.sections
189
+ .map((section) => ({
190
+ ...section,
191
+ options: section.options.filter((o) => !selectedIdSet.has(o.id)),
192
+ }))
193
+ .filter((section) => section.options.length > 0);
194
+ // "No matching options" must mean the search found nothing — not that every
195
+ // match was hidden because it's already selected (a successful search). Key
196
+ // it off the loader's own result, before the selected-id filter.
197
+ const loaderReturnedNothing = source.sections.every((section) => section.options.length === 0);
198
+ const showEmptyState = source.status === "idle" && loaderReturnedNothing && !source.hasNextPage;
199
+ return (_jsx("div", { className: b(), "data-testid": dataTestId, children: _jsxs(UiComboboxContextProvider, { state: state, children: [
200
+ _jsx(UiComboboxInput, { placeholder: copy.searchPlaceholder, accessibilityConfig: accessibilityConfig }), _jsx(UiComboboxPopup, { children: _jsxs("ul", { className: e("list"), role: "listbox", id: listboxId, tabIndex: -1, children: [source.status === "loading" ? _jsx(StatusRow, { text: copy.stateLoading }) : null, source.status === "error" ? _jsx(StatusRow, { text: copy.stateError }) : null, visibleSections.length > 0 ? (_jsx(Sections, { sections: visibleSections, focusableOptions: focusableOptions })) : null, source.hasNextPage && source.status !== "loadingMore" ? (_jsx(LoadMoreRow, { id: loadMoreRowId, index: focusableOptions.findIndex((o) => o.id === loadMoreRowId), label: copy.loadMore })) : null, source.status === "loadingMore" ? _jsx(StatusRow, { text: copy.stateLoading }) : null, showEmptyState ? _jsx(StatusRow, { text: copy.stateNoMatch }) : null] }) })
201
+ ] }) }));
202
+ }
203
+ // `index` on each item must be its position in `focusableOptions` — chrome's
204
+ // active-index navigation and item-ref registry are keyed off that.
205
+ function Sections({ sections, focusableOptions, }) {
206
+ return sections.map((section) => (_jsxs(Fragment, { children: [
207
+ _jsx("li", { role: "presentation", className: e("section-header"), children: _jsx(UiSectionHeading, { label: section.label }) }), section.options.map((option) => {
208
+ const index = focusableOptions.findIndex((o) => o.id === option.id);
209
+ if (index < 0) {
210
+ return null;
211
+ }
212
+ return (_jsxs(UiComboboxListItem, { option: { id: option.id, label: option.label }, index: index, className: e("option"), children: [
213
+ _jsx("span", { className: e("option-label"), children: option.label }), option.secondaryText ? (_jsx("span", { className: e("option-secondary"), children: option.secondaryText })) : null] }, option.id));
214
+ })] }, section.id)));
215
+ }
216
+ function StatusRow({ text }) {
217
+ return (_jsx("li", { role: "presentation", className: e("state"), children: text }));
218
+ }
219
+ function LoadMoreRow({ id, index, label }) {
220
+ return (_jsx(UiComboboxListItem, { option: { id, label }, index: index, className: e("load-more"), children: _jsx("span", { children: label }) }));
221
+ }
222
+ function findOptionById(sections, id) {
223
+ for (const section of sections) {
224
+ const found = section.options.find((o) => o.id === id);
225
+ if (found) {
226
+ return found;
227
+ }
228
+ }
229
+ return undefined;
230
+ }
@@ -0,0 +1,61 @@
1
+ import { type IAccessibilityConfigBase } from "../../typings/accessibility.js";
2
+ /**
3
+ * Minimal option shape; specialized pickers map their domain objects onto it.
4
+ *
5
+ * @internal
6
+ */
7
+ export interface IUiAutocompleteOption {
8
+ id: string;
9
+ label: string;
10
+ /** Secondary label rendered muted next to the primary label. */
11
+ secondaryText?: string;
12
+ }
13
+ /** @internal */
14
+ export interface IUiAutocompleteSection<T extends IUiAutocompleteOption = IUiAutocompleteOption> {
15
+ id: string;
16
+ label: string;
17
+ options: T[];
18
+ }
19
+ /**
20
+ * User-facing copy overrides. Omitted fields fall back to the kit default.
21
+ *
22
+ * @internal
23
+ */
24
+ export interface IUiAutocompleteMessages {
25
+ searchPlaceholder?: string;
26
+ stateLoading?: string;
27
+ stateError?: string;
28
+ stateNoMatch?: string;
29
+ loadMore?: string;
30
+ }
31
+ /** @internal */
32
+ export interface IUiAutocompleteLoadResult<T extends IUiAutocompleteOption = IUiAutocompleteOption> {
33
+ sections: IUiAutocompleteSection<T>[];
34
+ /** Show a "Load more" row whose activation calls the loader with the next page. */
35
+ hasNextPage?: boolean;
36
+ }
37
+ /** @internal */
38
+ export interface IUiAutocompleteProps<T extends IUiAutocompleteOption = IUiAutocompleteOption> {
39
+ /**
40
+ * Called with the debounced search and zero-based `page` index. Page 0
41
+ * fires on every query change; subsequent pages fire on Load-more.
42
+ *
43
+ * Must be referentially stable (memoize with `useCallback`) — it is a
44
+ * fetch dependency, so a new identity each render re-runs the page-0 query.
45
+ */
46
+ loadOptions: (search: string, page: number) => Promise<IUiAutocompleteLoadResult<T>>;
47
+ /** Filtered out of the dropdown so the user cannot pick the same option twice. */
48
+ selectedIds?: ReadonlyArray<string>;
49
+ onSelect: (option: T) => void;
50
+ /** Debounce delay for the input → loader path. Defaults to 400 ms. */
51
+ debounceMs?: number;
52
+ messages?: IUiAutocompleteMessages;
53
+ /**
54
+ * Forwarded to the search input for the accessible name / description.
55
+ * The combobox-internal attributes (`role`, `ariaExpanded`, `ariaControls`,
56
+ * `ariaAutocomplete`) are owned by the component and cannot be overridden.
57
+ */
58
+ accessibilityConfig?: IAccessibilityConfigBase;
59
+ dataTestId?: string;
60
+ }
61
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/@ui/UiAutocomplete/types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAE/E;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,gBAAgB;AAChB,MAAM,WAAW,sBAAsB,CAAC,CAAC,SAAS,qBAAqB,GAAG,qBAAqB;IAC3F,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,CAAC,EAAE,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACpC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,gBAAgB;AAChB,MAAM,WAAW,yBAAyB,CAAC,CAAC,SAAS,qBAAqB,GAAG,qBAAqB;IAC9F,QAAQ,EAAE,sBAAsB,CAAC,CAAC,CAAC,EAAE,CAAC;IACtC,mFAAmF;IACnF,WAAW,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,gBAAgB;AAChB,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,qBAAqB,GAAG,qBAAqB;IACzF;;;;;;OAMG;IACH,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,CAAC;IACrF,kFAAkF;IAClF,WAAW,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACpC,QAAQ,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;IAC9B,wEAAsE;IACtE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,uBAAuB,CAAC;IACnC;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,wBAAwB,CAAC;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB"}
@@ -0,0 +1,2 @@
1
+ // (C) 2026 GoodData Corporation
2
+ export {};
@@ -0,0 +1,42 @@
1
+ import type { IUiAutocompleteOption, IUiAutocompleteSection } from "./types.js";
2
+ type LoadResult<T extends IUiAutocompleteOption> = {
3
+ sections: IUiAutocompleteSection<T>[];
4
+ hasNextPage?: boolean;
5
+ };
6
+ /** @internal */
7
+ export type AsyncListSourceLoader<T extends IUiAutocompleteOption> = (search: string, page: number) => Promise<LoadResult<T>>;
8
+ /** @internal */
9
+ export interface IUseAsyncListSourceOptions {
10
+ debounceMs: number;
11
+ }
12
+ /**
13
+ * `loadingMore` keeps prior pages visible while the next page is in flight;
14
+ * `error` blanks out the list.
15
+ *
16
+ * @internal
17
+ */
18
+ export type AsyncListStatus = "loading" | "loadingMore" | "idle" | "error";
19
+ /** @internal */
20
+ export interface IAsyncListSource<T extends IUiAutocompleteOption> {
21
+ inputValue: string;
22
+ setInputValue: (next: string) => void;
23
+ sections: IUiAutocompleteSection<T>[];
24
+ status: AsyncListStatus;
25
+ hasNextPage: boolean;
26
+ loadMore: () => void;
27
+ reset: () => void;
28
+ /** Re-run the current page-0 query — used to recover from an error state. */
29
+ retry: () => void;
30
+ /** Increments on each page-0 load; lets callers tag per-query synthetic rows. */
31
+ generation: number;
32
+ }
33
+ /**
34
+ * Async data source for an autocomplete-shaped picker: debounce via
35
+ * `useDebouncedState`, fetching with stale-result protection via
36
+ * `useCancelablePromise`, section merge on pagination.
37
+ *
38
+ * @internal
39
+ */
40
+ export declare function useAsyncListSource<T extends IUiAutocompleteOption>(loadOptions: AsyncListSourceLoader<T>, { debounceMs }: IUseAsyncListSourceOptions): IAsyncListSource<T>;
41
+ export {};
42
+ //# sourceMappingURL=useAsyncListSource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAsyncListSource.d.ts","sourceRoot":"","sources":["../../../src/@ui/UiAutocomplete/useAsyncListSource.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEhF,KAAK,UAAU,CAAC,CAAC,SAAS,qBAAqB,IAAI;IAC/C,QAAQ,EAAE,sBAAsB,CAAC,CAAC,CAAC,EAAE,CAAC;IACtC,WAAW,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,gBAAgB;AAChB,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,qBAAqB,IAAI,CACjE,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,KACX,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAE5B,gBAAgB;AAChB,MAAM,WAAW,0BAA0B;IACvC,UAAU,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,aAAa,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3E,gBAAgB;AAChB,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,qBAAqB;IAC7D,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,QAAQ,EAAE,sBAAsB,CAAC,CAAC,CAAC,EAAE,CAAC;IACtC,MAAM,EAAE,eAAe,CAAC;IACxB,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,+EAA6E;IAC7E,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,iFAAiF;IACjF,UAAU,EAAE,MAAM,CAAC;CACtB;AAeD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,qBAAqB,EAC9D,WAAW,EAAE,qBAAqB,CAAC,CAAC,CAAC,EACrC,EAAE,UAAU,EAAE,EAAE,0BAA0B,GAC3C,gBAAgB,CAAC,CAAC,CAAC,CAqHrB"}
@@ -0,0 +1,112 @@
1
+ // (C) 2026 GoodData Corporation
2
+ import { useCallback, useMemo, useState } from "react";
3
+ import { useCancelablePromise, useDebouncedState } from "@gooddata/sdk-ui";
4
+ /**
5
+ * Async data source for an autocomplete-shaped picker: debounce via
6
+ * `useDebouncedState`, fetching with stale-result protection via
7
+ * `useCancelablePromise`, section merge on pagination.
8
+ *
9
+ * @internal
10
+ */
11
+ export function useAsyncListSource(loadOptions, { debounceMs }) {
12
+ const [inputValue, setInputValue, debouncedQuery, setInputValueImmediate] = useDebouncedState("", debounceMs);
13
+ // Bumping `retryToken` re-runs page-0 even when the query is unchanged, so a
14
+ // failed load can recover (e.g. when the popup is reopened) without the user
15
+ // having to edit the search text.
16
+ const [retryToken, setRetryToken] = useState(0);
17
+ const retry = useCallback(() => setRetryToken((t) => t + 1), []);
18
+ // Each page-0 load bumps the generation; Load-more pages are tagged with the
19
+ // generation they belong to and ignored once it advances. Counting loads
20
+ // (not comparing result objects) stays correct even if a loader returns the
21
+ // same object for a repeated query.
22
+ const [generation, setGeneration] = useState(0);
23
+ const queryLoad = useCancelablePromise({ promise: () => loadOptions(debouncedQuery, 0), onSuccess: () => setGeneration((g) => g + 1) }, [debouncedQuery, loadOptions, retryToken]);
24
+ const [paginationState, setPagination] = useState(null);
25
+ const pagination = paginationState?.generation === generation ? paginationState : null;
26
+ const pendingPage = pagination?.pendingPage ?? null;
27
+ // While the typed value is ahead of the debounced one the fetch has not
28
+ // started yet, but the UI must already report loading (and below, drop the
29
+ // sections) so the previous query's options are not left clickable.
30
+ const isDebouncing = inputValue !== debouncedQuery;
31
+ const isQueryLoading = queryLoad.status === "pending" || queryLoad.status === "loading";
32
+ useCancelablePromise({
33
+ // Hold pagination until page-0 of the current query has settled, so a
34
+ // query change mid-pagination can't fetch the new query at an old page.
35
+ promise: pendingPage == null || isDebouncing || isQueryLoading
36
+ ? null
37
+ : () => loadOptions(debouncedQuery, pendingPage),
38
+ onSuccess: (result) => setPagination((prev) => prev?.pendingPage == null
39
+ ? prev
40
+ : {
41
+ generation: prev.generation,
42
+ sections: mergeSections(prev.sections, result.sections),
43
+ pagesLoaded: prev.pagesLoaded + 1,
44
+ hasNextPage: !!result.hasNextPage,
45
+ pendingPage: null,
46
+ }),
47
+ // Keep the already-loaded pages; dropping back to idle re-shows the
48
+ // Load-more row so the user can retry the failed page.
49
+ onError: () => setPagination((prev) => (prev ? { ...prev, pendingPage: null } : prev)),
50
+ }, [pendingPage, debouncedQuery, loadOptions, isDebouncing, isQueryLoading]);
51
+ const status = isDebouncing || isQueryLoading
52
+ ? "loading"
53
+ : queryLoad.status === "error"
54
+ ? "error"
55
+ : pendingPage == null
56
+ ? "idle"
57
+ : "loadingMore";
58
+ const sections = useMemo(() => {
59
+ if (status === "loading" || status === "error" || queryLoad.result === undefined) {
60
+ return [];
61
+ }
62
+ return pagination
63
+ ? mergeSections(queryLoad.result.sections, pagination.sections)
64
+ : queryLoad.result.sections;
65
+ }, [status, queryLoad.result, pagination]);
66
+ const hasNextPage = (status === "idle" || status === "loadingMore") &&
67
+ (pagination ? pagination.hasNextPage : !!queryLoad.result?.hasNextPage);
68
+ const loadMore = useCallback(() => {
69
+ if (status !== "idle" || !hasNextPage) {
70
+ return;
71
+ }
72
+ setPagination({
73
+ generation,
74
+ sections: pagination?.sections ?? [],
75
+ pagesLoaded: pagination?.pagesLoaded ?? 0,
76
+ hasNextPage,
77
+ pendingPage: (pagination?.pagesLoaded ?? 0) + 1,
78
+ });
79
+ }, [status, hasNextPage, generation, pagination]);
80
+ // `setInputValueImmediate` from useDebouncedState isn't memoized, but it only
81
+ // delegates to stable `useState` setters, so omitting it keeps `reset`
82
+ // referentially stable without going stale.
83
+ const reset = useCallback(() => {
84
+ setInputValueImmediate("");
85
+ setPagination(null);
86
+ // eslint-disable-next-line react-hooks/exhaustive-deps
87
+ }, []);
88
+ return useMemo(() => ({
89
+ inputValue,
90
+ setInputValue,
91
+ sections,
92
+ status,
93
+ hasNextPage,
94
+ loadMore,
95
+ reset,
96
+ retry,
97
+ generation,
98
+ }), [inputValue, setInputValue, sections, status, hasNextPage, loadMore, reset, retry, generation]);
99
+ }
100
+ function mergeSections(current, incoming) {
101
+ const merged = current.map((s) => ({ ...s, options: [...s.options] }));
102
+ for (const next of incoming) {
103
+ const existing = merged.find((s) => s.id === next.id);
104
+ if (existing) {
105
+ existing.options.push(...next.options);
106
+ }
107
+ else {
108
+ merged.push({ ...next, options: [...next.options] });
109
+ }
110
+ }
111
+ return merged;
112
+ }
@@ -1,8 +1,13 @@
1
1
  import { type FocusEvent, type KeyboardEvent, type MouseEvent } from "react";
2
+ import { type IAccessibilityConfigBase } from "../../typings/accessibility.js";
2
3
  /** @internal */
3
4
  export interface IUiComboboxInputProps {
4
- /** Accessible name for the input. */
5
- "aria-label"?: string;
5
+ /**
6
+ * Accessible name/description for the input (e.g. `ariaLabel`,
7
+ * `ariaDescribedBy`). The combobox role and listbox-wiring attributes are
8
+ * owned by the component and override anything passed here.
9
+ */
10
+ accessibilityConfig?: IAccessibilityConfigBase;
6
11
  /** Visible placeholder. */
7
12
  placeholder?: string;
8
13
  /** Form field name forwarded to the underlying input. */
@@ -1 +1 @@
1
- {"version":3,"file":"UiComboboxInput.d.ts","sourceRoot":"","sources":["../../../src/@ui/UiCombobox/UiComboboxInput.tsx"],"names":[],"mappings":"AAEA,OAAO,EACH,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,UAAU,EAIlB,MAAM,OAAO,CAAC;AAMf,gBAAgB;AAChB,MAAM,WAAW,qBAAqB;IAClC,qCAAqC;IACrC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IAC7D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACxD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACvD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACxD,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,oHAsF3B,CAAC"}
1
+ {"version":3,"file":"UiComboboxInput.d.ts","sourceRoot":"","sources":["../../../src/@ui/UiCombobox/UiComboboxInput.tsx"],"names":[],"mappings":"AAEA,OAAO,EACH,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,UAAU,EAIlB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAK/E,gBAAgB;AAChB,MAAM,WAAW,qBAAqB;IAClC;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,wBAAwB,CAAC;IAC/C,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IAC7D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACxD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACvD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACxD,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,oHAsF3B,CAAC"}
@@ -10,7 +10,7 @@ import { useComboboxState } from "./UiComboboxContext.js";
10
10
  * @internal
11
11
  */
12
12
  export const UiComboboxInput = forwardRef(function UiComboboxInput(props, forwardedRef) {
13
- const { "aria-label": ariaLabel, placeholder, name, autoFocus, onKeyDown: callerOnKeyDown, onFocus: callerOnFocus, onBlur: callerOnBlur, onClick: callerOnClick, dataTestId, } = props;
13
+ const { accessibilityConfig, placeholder, name, autoFocus, onKeyDown: callerOnKeyDown, onFocus: callerOnFocus, onBlur: callerOnBlur, onClick: callerOnClick, dataTestId, } = props;
14
14
  const { inputValue, onInputChange, onInputKeyDown, onInputBlur, isOpen, setIsOpen, anchorRef, activeOption, listboxId, } = useComboboxState();
15
15
  const handleKeyDown = useCallback((event) => {
16
16
  onInputKeyDown(event);
@@ -33,12 +33,12 @@ export const UiComboboxInput = forwardRef(function UiComboboxInput(props, forwar
33
33
  // Browser autofill would overlap the listbox; the combobox
34
34
  // owns its own typeahead so we suppress all native suggestions.
35
35
  autoComplete: "off", autoCapitalize: "none", autoCorrect: "off", dataTestId: dataTestId, onKeyDown: handleKeyDown, onFocus: callerOnFocus, onBlur: handleBlur, onClick: handleClick, accessibilityConfig: {
36
+ ...accessibilityConfig,
36
37
  role: "combobox",
37
38
  ariaAutocomplete: "list",
38
39
  ariaExpanded: isOpen,
39
40
  ariaActiveDescendant: activeOption?.id,
40
41
  ariaHaspopup: "listbox",
41
42
  ariaControls: listboxId,
42
- ariaLabel,
43
43
  } }));
44
44
  });
@@ -1 +1 @@
1
- {"version":3,"file":"useCombobox.d.ts","sourceRoot":"","sources":["../../../src/@ui/UiCombobox/useCombobox.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAkBtE,gBAAgB;AAChB,wBAAgB,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,gBAAgB,CA+EvE"}
1
+ {"version":3,"file":"useCombobox.d.ts","sourceRoot":"","sources":["../../../src/@ui/UiCombobox/useCombobox.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAkBtE,gBAAgB;AAChB,wBAAgB,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,gBAAgB,CAuEvE"}
@@ -15,23 +15,16 @@ const comboboxKeys = makeKeyboardNavigation({
15
15
  export function useCombobox(params) {
16
16
  const { value, defaultValue = "", onValueChange, options, creatable = false } = params;
17
17
  const listboxId = useId();
18
- const chrome = useComboboxChrome();
19
18
  const selection = useComboboxSelection({
20
19
  options,
21
20
  value,
22
21
  defaultValue,
23
22
  onValueChange,
24
23
  creatable,
25
- setIsOpen: chrome.setIsOpen,
26
- setActiveIndex: chrome.setActiveIndex,
24
+ setIsOpen: (open) => chrome.setIsOpen(open),
27
25
  });
28
- // Clamp on read so a filter that shrinks the list doesn't leave us
29
- // pointing past the end (Enter would otherwise be a silent no-op).
30
- const optionCount = selection.availableOptions.length;
31
- const safeActiveIndex = chrome.activeIndex == null ? null : Math.min(chrome.activeIndex, optionCount - 1);
32
- const activeOption = safeActiveIndex == null || optionCount === 0
33
- ? undefined
34
- : selection.availableOptions[safeActiveIndex];
26
+ const chrome = useComboboxChrome(selection.availableOptions);
27
+ const activeOption = chrome.activeOption;
35
28
  const onInputKeyDown = useMemo(() => {
36
29
  // Leave Enter unhandled when there's no selectable target so creatable
37
30
  // flows like UiTags (add tag on unhandled Enter) can react to it.
@@ -53,12 +46,12 @@ export function useCombobox(params) {
53
46
  }
54
47
  : undefined;
55
48
  return comboboxKeys({
56
- onArrowDown: () => chrome.focusByDelta(1, optionCount),
57
- onArrowUp: () => chrome.focusByDelta(-1, optionCount),
49
+ onArrowDown: () => chrome.focusByDelta(1),
50
+ onArrowUp: () => chrome.focusByDelta(-1),
58
51
  onEnter,
59
52
  onEscape,
60
53
  });
61
- }, [chrome, selection, activeOption, optionCount]);
54
+ }, [chrome, selection, activeOption]);
62
55
  return useMemo(() => ({
63
56
  availableOptions: selection.availableOptions,
64
57
  inputValue: selection.inputValue,
@@ -74,8 +67,8 @@ export function useCombobox(params) {
74
67
  selectOption: selection.selectOption,
75
68
  anchorRef: chrome.anchorRef,
76
69
  registerItemRef: chrome.registerItemRef,
77
- shouldRenderPopup: optionCount > 0,
70
+ shouldRenderPopup: selection.availableOptions.length > 0,
78
71
  creatable,
79
72
  listboxId,
80
- }), [chrome, selection, onInputKeyDown, activeOption, creatable, listboxId, optionCount]);
73
+ }), [chrome, selection, onInputKeyDown, activeOption, creatable, listboxId]);
81
74
  }
@@ -1,9 +1,20 @@
1
- import type { IUiComboboxState } from "./types.js";
1
+ import type { IUiComboboxOption, IUiComboboxState } from "./types.js";
2
2
  type IUseComboboxChromeReturn = Pick<IUiComboboxState, "isOpen" | "setIsOpen" | "activeIndex" | "setActiveIndex" | "anchorRef" | "registerItemRef"> & {
3
- /** Open the popup if needed and move highlight by `delta`, wrapping at `total`. */
4
- focusByDelta: (delta: 1 | -1, total: number) => void;
3
+ /** The currently highlighted option, or undefined. */
4
+ activeOption: IUiComboboxOption | undefined;
5
+ /** Open the popup if needed and move the highlight by `delta`, wrapping around. */
6
+ focusByDelta: (delta: 1 | -1) => void;
5
7
  };
6
- /** @internal */
7
- export declare function useComboboxChrome(): IUseComboboxChromeReturn;
8
+ /**
9
+ * Owns popup open/close, highlight, and scroll. The highlight is tracked by
10
+ * option **id**, not index: when the option list changes (async results arrive,
11
+ * a row is filtered out) a highlighted row that's gone simply resolves to no
12
+ * index, so the highlight can never point at a different row than the user
13
+ * navigated to. Callers pass the current `options` so the id ⇄ index mapping
14
+ * and `focusByDelta` wrapping stay in sync with what's rendered.
15
+ *
16
+ * @internal
17
+ */
18
+ export declare function useComboboxChrome(options: IUiComboboxOption[]): IUseComboboxChromeReturn;
8
19
  export {};
9
20
  //# sourceMappingURL=useComboboxChrome.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useComboboxChrome.d.ts","sourceRoot":"","sources":["../../../src/@ui/UiCombobox/useComboboxChrome.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,KAAK,wBAAwB,GAAG,IAAI,CAChC,gBAAgB,EAChB,QAAQ,GAAG,WAAW,GAAG,aAAa,GAAG,gBAAgB,GAAG,WAAW,GAAG,iBAAiB,CAC9F,GAAG;IACA,mFAAmF;IACnF,YAAY,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxD,CAAC;AAEF,gBAAgB;AAChB,wBAAgB,iBAAiB,IAAI,wBAAwB,CAmE5D"}
1
+ {"version":3,"file":"useComboboxChrome.d.ts","sourceRoot":"","sources":["../../../src/@ui/UiCombobox/useComboboxChrome.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEtE,KAAK,wBAAwB,GAAG,IAAI,CAChC,gBAAgB,EAChB,QAAQ,GAAG,WAAW,GAAG,aAAa,GAAG,gBAAgB,GAAG,WAAW,GAAG,iBAAiB,CAC9F,GAAG;IACA,sDAAsD;IACtD,YAAY,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC5C,mFAAmF;IACnF,YAAY,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC;CACzC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,wBAAwB,CA6FxF"}