Repository navigation
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
Open
michaelstonis wants to merge 5 commits into
michaelstonis wants to merge 5 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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(nowpartial:DrawnComboBox.Columns.cs,DrawnComboBox.Search.cs) and in the editor wiring (CellEditorFactory,EditSession).KumikoRenderer,KumikoInputControllerand the hit tester are unchanged. The drop-down draws itself and handles its own keys.Multi-column drop-down
DrawnComboBoxColumn(Header,MemberPath,Selector,Width,IsSearchable).MemberPathresolves throughKumikoAccessorRegistry.Selectoris reflection-free and wins overMemberPath. AWidthof zero or less shares the width the other columns leave.DrawnComboBox.DropdownColumnsandDropdownMinWidth. WhenDropdownMinWidthis not set, the minimum width is the sum of the column widths, and a shared column counts as 80. The drop-down ismax(box width, min width), placed withPopupLayoutso it stays insidePopupViewport.string[](DrawnComboBoxItem.ColumnTexts, which can also be set withiniton an item you build yourself). Nothing is read while the drop-down draws.DropdownHeaderBackgroundColor,DropdownHeaderTextColor, bold header font) and oneDrawTextInRectper 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.IsFilterable, typing matches the display text and every column withIsSearchabletrue. Filtering and typeahead now go throughDrawnComboBox.Comparer, which the edit session sets to the grid'sKumikoSource.Comparer. Before, filtering usedOrdinalIgnoreCaseand typeahead usedCurrentCultureIgnoreCase.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-onlyIsSearching.Task.Delayposts back through theSynchronizationContextof 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.CancellationTokenSourceand 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.Trace.TraceWarning, the logging the accessor registry already uses.SetItemsFromSource, and the first result is highlighted.Current value, free text, no match
DrawnComboBox.SetSelectedValue(object?, string displayText): when no item has the value, the value stays selected as an item outside the list (SelectedIndexis -1,SelectedItemis set). It survives later searches, and it is re-matched by value when a result has it.CellEditorFactoryopens 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 (IsDirtyfalse) unless the user picks something else.DrawnComboBox.AllowsFreeText/KumikoColumn.EditorAllowsFreeText: typed text that matches no item becomesIValueEditor.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.DrawnComboBox.ValidationtoError, drawn with the newErrorBorderColor. Typing again clears it. While a search is still pending, Enter waits instead of failing.Column-level mirrors (
KumikoColumn.ComboBox.cs;KumikoColumnis nowpartial):EditorDropdownColumns,EditorItemsProvider,EditorMinimumSearchLength,EditorSearchDelay,EditorAllowsFreeText.CellEditorFactorynow also copies the paths and selectors whenEditorItemsis null, because the provider's results need them.Accessibility: when the keyboard moves the highlight, and when a search completes,
DrawnComboBoxraises an internalAnnouncementRequested. The highlighted item is read as its column texts with their headers ("Code: ACME-001, Name: Acme Corp, City: Seattle", formatted withKumikoStrings.ComboBoxColumnText); a search that found nothing reads as "No matches".EditSessionforwards it through a new internalEditorAnnouncementRequestedevent, and both hosts' accessibility partials pass it to their existingAnnounce: MAUISemanticScreenReader, Uno peer notification.EditSessionalso gives the combo box the grid'sStringsandComparer.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,EditorAllowsFreeTextKumikoStrings:ComboBoxSearching,ComboBoxNoMatches,ComboBoxColumnTextSamples: the shared
samples/Shared/LookupData.csholds 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
DropdownColumnsdraws a header and several columns per item; typing filters across searchable columns.ItemsProviderloads items asynchronously with debounce and cancellation; stale results never replace newer ones.tests/KumikoUI.Core.Tests/Components/DrawnComboBoxTests.cs(layout, search, async ordering with a fake provider, keyboard) and editing tests.DrawnComboBoxTestsis now partial:DrawnComboBoxTests.MultiColumn.csandDrawnComboBoxTests.AutoComplete.cs. The newEditing/ComboBoxLookupEditorTests.cscovers the editing flow.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.PublicAPI.Unshipped.txtupdated. In this worktree,eng/update-public-api.sh Coreemptied the file becausedotnet formatfailed to load the workspace, so the new lines came from the RS0016 build diagnostics and were sorted in. The build is clean.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 inKumikoDataGrid.Editing.csandKumikoDataGrid.Input.cs.dotnet test tests/KumikoUI.Core.Tests: 4392 passed, 5 skipped, 0 failed.LocalizationTests.TheGermanTable_ChangesEveryPropertyfailed 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-desktopand-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 fromMauiDevFlowMauiVersionand is unrelated to this change.dotnet run --project eng/DocsSnippets -c Release, thendotnet build tests/KumikoUI.Docs.Snippets.Uno -f net10.0-desktop -c Releaseanddotnet build tests/KumikoUI.Docs.Snippets.Maui -f net10.0-maccatalyst -c Release: succeeded.dotnet run --project eng/DocsIdentifiers -c Release: 0 problems.