Skip to content

feat: add a multi-column drop-down and async auto-complete to the ComboBox editor (#377) - #513

Open
michaelstonis wants to merge 5 commits into
mainfrom
feat/377-combobox-multicolumn-autocomplete
Open

michaelstonis wants to merge 5 commits into
mainfrom
feat/377-combobox-multicolumn-autocomplete

Conversation

@michaelstonis

Copy link
Copy Markdown
Contributor

Closes #377.

Changes

ComboBox columns get two lookup editors: a drop-down with several columns per item, and an auto-complete that asks an asynchronous provider for the typed text. All of it lives in DrawnComboBox (now partial: DrawnComboBox.Columns.cs, DrawnComboBox.Search.cs) and in the editor wiring (CellEditorFactory, EditSession). KumikoRenderer, KumikoInputController and the hit tester are unchanged. The drop-down draws itself and handles its own keys.

Multi-column drop-down

  • New DrawnComboBoxColumn (Header, MemberPath, Selector, Width, IsSearchable). MemberPath resolves through KumikoAccessorRegistry. Selector is reflection-free and wins over MemberPath. A Width of zero or less shares the width the other columns leave.
  • DrawnComboBox.DropdownColumns and DropdownMinWidth. When DropdownMinWidth is not set, the minimum width is the sum of the column widths, and a shared column counts as 80. The drop-down is max(box width, min width), placed with PopupLayout so it stays inside PopupViewport.
  • Each item's column texts are read once, when the items are set, into a string[] (DrawnComboBoxItem.ColumnTexts, which can also be set with init on an item you build yourself). Nothing is read while the drop-down draws.
  • The drop-down draws a header row (DropdownHeaderBackgroundColor, DropdownHeaderTextColor, bold header font) and one DrawTextInRect per cell, clipped to the cell. The item paints are resolved once per draw instead of once per item, and the steady-state draw allocates nothing.
  • With IsFilterable, typing matches the display text and every column with IsSearchable true. Filtering and typeahead now go through DrawnComboBox.Comparer, which the edit session sets to the grid's KumikoSource.Comparer. Before, filtering used OrdinalIgnoreCase and typeahead used CurrentCultureIgnoreCase.
  • Pointer and keyboard skip the header row (a press on it does nothing). Up, Down, Page Up, Page Down, Home and End move over the items only.

Auto-complete

  • DrawnComboBox.ItemsProvider (Func<string, CancellationToken, Task<IEnumerable>>), MinimumSearchLength (default 1; 0 also searches when the drop-down opens), SearchDelay (default 250 ms) and the read-only IsSearching.
  • Debounce: Task.Delay posts back through the SynchronizationContext of the thread that typed, the same pattern the search panel uses. Without a context the search starts at once. The provider is called on the UI thread, and its task's result is posted back the same way.
  • Every new text cancels the previous request's CancellationTokenSource and bumps a generation counter. A result whose generation is no longer current is dropped, so a stale answer never replaces a newer one. Closing the drop-down (Escape, focus loss, end of edit) also cancels.
  • An empty list shows a "Searching..." row while a request is pending and a "No matches" row once the search answered with nothing. A provider that throws synchronously, a faulted task, or results that fail to enumerate all show "No matches", and the exception goes to Trace.TraceWarning, the logging the accessor registry already uses.
  • The results are read with the same display and value paths, selectors and drop-down columns as SetItemsFromSource, and the first result is highlighted.

Current value, free text, no match

  • New DrawnComboBox.SetSelectedValue(object?, string displayText): when no item has the value, the value stays selected as an item outside the list (SelectedIndex is -1, SelectedItem is set). It survives later searches, and it is re-matched by value when a result has it. CellEditorFactory opens an auto-complete or free-text editor this way, using the cell value formatted for editing as the text. The editor therefore shows the cell's value and commits it unchanged (IsDirty false) unless the user picks something else.
  • DrawnComboBox.AllowsFreeText / KumikoColumn.EditorAllowsFreeText: typed text that matches no item becomes IValueEditor.Value, committed by Enter, Tab or a click elsewhere. Text equal to an item's display text commits that item's value. Escape restores the value the drop-down opened with.
  • Without free text, Enter with typed text and nothing to pick keeps the drop-down open and sets the new DrawnComboBox.Validation to Error, drawn with the new ErrorBorderColor. Typing again clears it. While a search is still pending, Enter waits instead of failing.

Column-level mirrors (KumikoColumn.ComboBox.cs; KumikoColumn is now partial): EditorDropdownColumns, EditorItemsProvider, EditorMinimumSearchLength, EditorSearchDelay, EditorAllowsFreeText. CellEditorFactory now also copies the paths and selectors when EditorItems is null, because the provider's results need them.

Accessibility: when the keyboard moves the highlight, and when a search completes, DrawnComboBox raises an internal AnnouncementRequested. The highlighted item is read as its column texts with their headers ("Code: ACME-001, Name: Acme Corp, City: Seattle", formatted with KumikoStrings.ComboBoxColumnText); a search that found nothing reads as "No matches". EditSession forwards it through a new internal EditorAnnouncementRequested event, and both hosts' accessibility partials pass it to their existing Announce: MAUI SemanticScreenReader, Uno peer notification. EditSession also gives the combo box the grid's Strings and Comparer.

New strings (KumikoStrings.ComboBox.cs): ComboBoxSearching ("Searching..."), ComboBoxNoMatches ("No matches"), ComboBoxColumnText ("{0}: {1}").

Public API added (all in PublicAPI.Unshipped.txt; no shipped member changed):

  • DrawnComboBoxColumn (type, constructor, Header, MemberPath, Selector, Width, IsSearchable)
  • DrawnComboBox: DropdownColumns, DropdownMinWidth, DropdownHeaderBackgroundColor, DropdownHeaderTextColor, ItemsProvider, MinimumSearchLength, SearchDelay, IsSearching, AllowsFreeText, Validation, ErrorBorderColor, Comparer, Strings, SetSelectedValue(object?, string)
  • DrawnComboBoxItem.ColumnTexts (get, init)
  • KumikoColumn: EditorDropdownColumns, EditorItemsProvider, EditorMinimumSearchLength, EditorSearchDelay, EditorAllowsFreeText
  • KumikoStrings: ComboBoxSearching, ComboBoxNoMatches, ComboBoxColumnText

Samples: the shared samples/Shared/LookupData.cs holds the offices and a directory of about 2,000 people searched with a 400 ms delay. On the MAUI MainPage and the Uno BasicGridPage, the City column is now a multi-column lookup (Code, City, State, with the drop-down columns declared in XAML), and a new Mentor column is an auto-complete over the directory (minimum 2 characters). The XAML declares both columns; the code-behind sets the City items and the Mentor provider.

Docs: a new README section, "Lookup columns: multi-column drop-downs and auto-complete", in Editing; the ComboBox row of the column-type table; docs/ARCHITECTURE.md; a CHANGELOG entry under Unreleased / Added.

Acceptance criteria

  • DropdownColumns draws a header and several columns per item; typing filters across searchable columns.
  • ItemsProvider loads items asynchronously with debounce and cancellation; stale results never replace newer ones.
  • Free-text and no-match behavior as specified; the current value survives opening the editor with an async provider.
  • Behavior tests in tests/KumikoUI.Core.Tests/Components/DrawnComboBoxTests.cs (layout, search, async ordering with a fake provider, keyboard) and editing tests. DrawnComboBoxTests is now partial: DrawnComboBoxTests.MultiColumn.cs and DrawnComboBoxTests.AutoComplete.cs. The new Editing/ComboBoxLookupEditorTests.cs covers the editing flow.
  • Works on MAUI and Uno (including WebAssembly). Partly verified. Both hosts and both samples build (Uno for desktop and browserwasm), and the host test suites pass. The debounce and the results go through the UI thread's SynchronizationContext, which both hosts provide. A unit test checks that against a dedicated UI thread with its own context. I did not run the samples interactively, so behavior on a device or in a WebAssembly browser is not checked.
  • MainPage (MAUI) and BasicGridPage (Uno) samples show a multi-column lookup (City) and an auto-complete column (Mentor).
  • XML docs on every new public member; PublicAPI.Unshipped.txt updated. In this worktree, eng/update-public-api.sh Core emptied the file because dotnet format failed to load the workspace, so the new lines came from the RS0016 build diagnostics and were sorted in. The build is clean.
  • README "Editing" section updated; CHANGELOG entry under Unreleased.
  • Screen readers hear the highlighted item's texts; no allocations added to the per-frame grid render path. The grid renderer is untouched. The drop-down resolves its paints once per draw and allocates nothing per frame. The announcement string is built only when the keyboard moves the highlight. The issue's pointer to Spec: virtual accessibility tree with per-cell navigation (WinUI IGridProvider, iOS UIAccessibilityContainer, Android ExploreByTouchHelper, WASM ARIA) #79 section 9 (popup items exposing that text as their accessible name) is not done: it needs that popup semantics tree, which is not in this branch.

Verification

  • dotnet build src/KumikoUI.Core: succeeded, 0 warnings.
  • dotnet build src/KumikoUI.Maui -f net10.0-maccatalyst: succeeded.
  • dotnet build src/KumikoUI.Uno -f net10.0-desktop: succeeded. The only warnings are the existing Uno0001 ones in KumikoDataGrid.Editing.cs and KumikoDataGrid.Input.cs.
  • dotnet test tests/KumikoUI.Core.Tests: 4392 passed, 5 skipped, 0 failed. LocalizationTests.TheGermanTable_ChangesEveryProperty failed until the German test table got the three new strings; it passes now.
  • dotnet test tests/KumikoUI.Uno.Tests: 321 passed.
  • dotnet test tests/KumikoUI.Maui.Tests: 449 passed.
  • dotnet build samples/SampleApp.Uno -f net10.0-desktop and -f net10.0-browserwasm: succeeded.
  • dotnet build samples/SampleApp.Maui -f net10.0-maccatalyst -p:KumikoDevFlow=false: succeeded. With DevFlow on (the default in Debug), restore fails with NU1605, a Microsoft.Maui.Controls downgrade from 10.0.110 to 10.0.41. That comes from MauiDevFlowMauiVersion and is unrelated to this change.
  • dotnet run --project eng/DocsSnippets -c Release, then dotnet build tests/KumikoUI.Docs.Snippets.Uno -f net10.0-desktop -c Release and dotnet build tests/KumikoUI.Docs.Snippets.Maui -f net10.0-maccatalyst -c Release: succeeded.
  • dotnet run --project eng/DocsIdentifiers -c Release: 0 problems.

Narrow the items provider catches to recoverable exceptions, compute the
test editor bounds in float, and use an early continue in the filter loop.
Comment on lines +390 to +394
foreach (var item in _items)
{
if (!Matches(item, _filterText)) continue;
_filteredItems.Add(item);
}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Editing: add a multi-column drop-down and an async auto-complete editor for ComboBox columns

2 participants