Commit 7c7641c
authored
refactor(combo): overhaul selection, data pipeline, and component architecture (#2164)
* refactor(combo): overhaul selection, data pipeline, and component architecture
Major refactoring of the `IgcComboComponent` and its supporting infrastructure
to improve maintainability, correctness, and adherence to project conventions.
- `combo.ts`
- Inherits from `IgcBaseComboBoxComponent` instead of bare `LitElement`, sharing
open/close lifecycle (`_show`, `_hide`) with picker components.
- Removed the `SelectionController` — selection state (`_selected: Set<T>`) is now
managed directly inside the component for a simpler, single-source-of-truth model.
- Replaced `@watch('open')` decorator with `willUpdate()` lifecycle hook.
- Replaced `@queryAssignedElements` with `addSlotController` / `setSlots` for slot
detection (no more `inputPrefix` / `inputSuffix` public properties).
- Form value serialization moved into the `setFormValue` transformer on
`createFormValueState` — removes the separate `_setFormValue()` override.
- `_setDefaultValue` now handles invalid JSON gracefully instead of throwing.
- `firstUpdated` removed; initialization is handled by `willUpdate` / `willUpdate`
data-sync guard for the delayed-data scenario.
- Added `_syncSelectionFromValue()` (value → Set) and `_syncValueFromSelection()`
(Set → form value) for explicit one-way data flow.
- Added `_resolveItems()`, `_resolveItemValue()`, `_getValues()` private helpers.
- All internal render helpers and event handlers renamed to `_camelCase` convention
(e.g., `renderMainInput` → `_renderMainInput`, `handleMainInput` → `_handleMainInput`).
- `groupKey` / `groupSorting` setters removed — now simple `@property` declarations;
pipeline invalidation driven by `willUpdate`.
- `filteringOptions` and `disableFiltering` setters simplified.
- `label` and `placeholder` changed from `!` non-null asserted to optional (`?`).
- `placeholderSearch` setter typed as `string | undefined`.
- Added `Iterator.from` usage for lazy mapping/filtering of selections.
- `controllers/data.ts` — `DataController` → `DataState`
- Introduced a **dirty flag** pattern: `invalidate()` marks state as dirty and
`hostUpdate()` runs the pipeline lazily before each render, batching multiple
property changes into a single pipeline execution.
- Locale-aware `Intl.Collator` initialized from host locale; updated via
`updateLocale(locale)`.
- `dataState` is now a read-only accessor.
- Added `invalidate()` and `updateLocale()` as explicit public API.
- Internal pipeline methods prefixed with `_`.
- `controllers/navigation.ts`
- Removed all `// @ts-expect-error: protected access` hacks.
- Added `interactions` config object to decouple `hide`, `show`, `toggleSelection`,
`select`, and `clearSelection` callbacks — the navigation controller no longer
reaches into the combo's protected methods directly.
- `_active` field is now public (`active`) so it can be read without casting.
- `_getNearestItem` rewritten with a `for` loop (was `while` with off-by-one risk).
- Navigation mutations now call `requestUpdate('_activeIndex', previous)` with the
old value so Lit schedules targeted updates.
- Keybinding setup moved to the constructor body (was at the end).
- `controllers/selection.ts`
- **Deleted.** All selection logic inlined into `combo.ts`.
- `combo-item.ts`
- `renderCheckbox` renamed to `_renderCheckbox`.
- Switched from `nothing` conditional to Lit's `cache()` directive to preserve the
checkbox DOM subtree when `hideCheckbox` toggles.
- `connectedCallback` marked `@internal`.
- Missing `@attr` / `@default` JSDoc tags added.
- `combo-list.ts` / `combo-header.ts`
- Added explicit `void` return type to `register()` methods.
- `common/mixins/combo-box.ts`
- `IgcBaseComboBoxLikeComponent` renamed to `IgcBaseComboBoxComponent` (core open/
close behaviour only: `open`, `_show`, `_hide`, `_handleAnchorClick`, events).
- `IgcComboBoxBaseLikeComponent` extracted as a new subclass that adds
`keepOpenOnSelect` and `keepOpenOnOutsideClick` — used by Dropdown, Select,
DatePicker, and DateRangePicker.
- Protected event helpers renamed: `emitClosing` → `_emitClosing`, etc.
- `handleAnchorClick` → `_handleAnchorClick`.
- Utility functions (`getItems`, `getActiveItems`, etc.) given explicit return types.
- `setInitialSelectionState` simplified using `last()` and direct assignment.
- `common/util.ts`
- `findElementFromEventPath` renamed to `getElementFromPath` with full JSDoc.
- New `stopPropagation(event)` utility function extracted (used in combo template).
- `asArray` now uses `value == null` instead of `isDefined(value)`.
- Cross-component rename: `findElementFromEventPath` → `getElementFromPath`
Updated all callers: `button-group`, `calendar`, `carousel`, `drag`, `key-bindings`,
`root-click`, `date-picker`, `date-range-picker`, `dropdown`, `resize-controller`,
`select`, `stepper`, `tabs`, `tile`, `tree-item`.
---
- Added test: *"should handle invalid JSON in value attribute gracefully"*.
- Removed `await list.layoutComplete` from keyboard-selection test (no longer needed).1 parent f74b953 commit 7c7641c
29 files changed
Lines changed: 970 additions & 942 deletions
File tree
- src/components
- button-group
- calendar
- carousel
- combo
- controllers
- operations
- common
- controllers
- mixins
- date-picker
- date-range-picker
- dropdown
- resize-container
- select
- stepper
- tabs
- tile-manager
- tree
- stories
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
| 170 | + | |
174 | 171 | | |
175 | 172 | | |
176 | 173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | 25 | | |
27 | 26 | | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
270 | | - | |
| 270 | + | |
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
| 157 | + | |
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | 45 | | |
47 | 46 | | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
501 | 501 | | |
502 | 502 | | |
503 | 503 | | |
504 | | - | |
| 504 | + | |
505 | 505 | | |
506 | 506 | | |
507 | 507 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
| 43 | + | |
41 | 44 | | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
| 51 | + | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
| |||
54 | 58 | | |
55 | 59 | | |
56 | 60 | | |
57 | | - | |
| 61 | + | |
| 62 | + | |
58 | 63 | | |
59 | 64 | | |
60 | 65 | | |
61 | 66 | | |
62 | | - | |
63 | | - | |
| 67 | + | |
| 68 | + | |
64 | 69 | | |
65 | 70 | | |
66 | 71 | | |
67 | 72 | | |
68 | | - | |
| 73 | + | |
69 | 74 | | |
70 | 75 | | |
71 | 76 | | |
| |||
79 | 84 | | |
80 | 85 | | |
81 | 86 | | |
82 | | - | |
| 87 | + | |
83 | 88 | | |
84 | 89 | | |
85 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
| |||
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
12 | | - | |
| 11 | + | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1028 | 1028 | | |
1029 | 1029 | | |
1030 | 1030 | | |
1031 | | - | |
1032 | 1031 | | |
1033 | 1032 | | |
1034 | 1033 | | |
| |||
1518 | 1517 | | |
1519 | 1518 | | |
1520 | 1519 | | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
1521 | 1540 | | |
1522 | 1541 | | |
1523 | 1542 | | |
| |||
0 commit comments