Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts AutoComplete Enter key handling to click the active/only item and then trigger EnterCallback asynchronously, ensuring ValueChanged fires correctly before the callback executes. Sequence diagram for AutoComplete Enter key handling and ValueChanged ordersequenceDiagram
actor User
participant AutoCompleteInput
participant AutoCompleteMenu
participant ActiveItem
participant JsTimeout
participant BlazorInterop
participant DotNetComponent
User->>AutoCompleteInput: keydown Enter
AutoCompleteInput->>AutoCompleteInput: handlerKeydown
AutoCompleteInput->>AutoCompleteInput: read data-bb-skip-enter
alt skip_enter_true
AutoCompleteInput-->>User: ignore Enter
else skip_enter_false
AutoCompleteInput->>AutoCompleteMenu: querySelectorAll .dropdown-item
AutoCompleteMenu-->>AutoCompleteInput: items
alt single_item
AutoCompleteInput->>AutoCompleteInput: set activeItem = items[0]
else multiple_items
AutoCompleteInput->>AutoCompleteMenu: querySelector .active
AutoCompleteMenu-->>AutoCompleteInput: activeItem
end
AutoCompleteInput->>JsTimeout: setTimeout 0ms
JsTimeout-->>AutoCompleteInput: timeout callback
alt activeItem_not_null
AutoCompleteInput->>ActiveItem: click()
ActiveItem->>BlazorInterop: invoke ValueChanged via click handler
BlazorInterop->>DotNetComponent: ValueChanged
DotNetComponent-->>BlazorInterop: state updated
else activeItem_null
AutoCompleteInput-->>User: no item clicked
end
AutoCompleteInput->>BlazorInterop: invokeMethodAsync EnterCallback
BlazorInterop->>DotNetComponent: EnterCallback
DotNetComponent-->>User: handle Enter after ValueChanged
end
Flow diagram for updated handlerKeydown Enter logicflowchart TD
A_start[Start handlerKeydown on Enter] --> B_checkSkip[Read data-bb-skip-enter]
B_checkSkip -->|true| Z_end[End handlerKeydown]
B_checkSkip -->|false| C_getItems[Query .dropdown-item items]
C_getItems --> D_itemsCount{items length == 1}
D_itemsCount -->|yes| E_setActiveItemSingle[Set activeItem = items at index 0]
D_itemsCount -->|no| F_findActive[Set activeItem = menu.querySelector .active]
E_setActiveItemSingle --> G_setTimeout[setTimeout 0ms]
F_findActive --> G_setTimeout
G_setTimeout --> H_timeoutCallback[Timeout callback executes]
H_timeoutCallback --> I_activeItemCheck{activeItem is not null}
I_activeItemCheck -->|yes| J_clickActiveItem[activeItem.click]
I_activeItemCheck -->|no| K_skipClick[Skip item click]
J_clickActiveItem --> L_valueChanged[Item click triggers ValueChanged]
L_valueChanged --> M_enterCallback[invokeMethodAsync EnterCallback]
K_skipClick --> M_enterCallback
M_enterCallback --> Z_end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- The
setTimeoutcallback clears its own timer (clearTimeout(handler)), which is redundant once the handler is already executing and can be safely removed to simplify the code. - Consider adding a brief comment explaining why
setTimeout(..., 0)is needed before invokingEnterCallback, so future readers understand the ordering requirement between the item click and the callback.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `setTimeout` callback clears its own timer (`clearTimeout(handler)`), which is redundant once the handler is already executing and can be safely removed to simplify the code.
- Consider adding a brief comment explaining why `setTimeout(..., 0)` is needed before invoking `EnterCallback`, so future readers understand the ordering requirement between the item click and the callback.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where the AutoComplete component's ValueChanged event was not being triggered after pressing Enter. The fix ensures that when Enter is pressed on an autocomplete item, the item click handler executes before the EnterCallback is invoked, allowing the value to be properly updated.
Key changes:
- Refactored Enter key handling to consolidate active item detection logic
- Introduced a
setTimeoutwrapper to deferEnterCallbackexecution, ensuring the item click completes first
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| invoke.invokeMethodAsync('EnterCallback'); | ||
|
|
||
| const handler = setTimeout(async () => { | ||
| clearTimeout(handler); |
There was a problem hiding this comment.
The clearTimeout(handler) is called immediately after setting the timeout, which cancels the timeout before it can execute. This line should be removed as it defeats the purpose of using setTimeout. The timeout will complete on its own and doesn't need to be cleared here.
| clearTimeout(handler); |
| if (activeItem !== null) { | ||
| activeItem.click(); | ||
| } | ||
| await invoke.invokeMethodAsync('EnterCallback'); |
There was a problem hiding this comment.
The setTimeout callback is defined as async but the returned promise is not handled. If EnterCallback throws an error, it will result in an unhandled promise rejection. Consider either removing the async keyword (if EnterCallback doesn't need to be awaited for the fix to work) or wrap the code in a try-catch block to handle potential errors.
| if (activeItem !== null) { | |
| activeItem.click(); | |
| } | |
| await invoke.invokeMethodAsync('EnterCallback'); | |
| try { | |
| if (activeItem !== null) { | |
| activeItem.click(); | |
| } | |
| await invoke.invokeMethodAsync('EnterCallback'); | |
| } catch (error) { | |
| // Optionally log the error or handle it as needed | |
| console.error('Error in EnterCallback:', error); | |
| } |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7281 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 745 745
Lines 32628 32628
Branches 4522 4522
=========================================
Hits 32628 32628
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #7270
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Bug Fixes: