LearnNewsExamplesServices
Frontmatter
id7125
titleComboBox: Optimize afterSetValue Selection Handling for SingleSelect
stateClosed
labels
enhancement
assigneestobiu
createdAtJul 29, 2025, 11:47 PM
updatedAtJul 29, 2025, 11:49 PM
githubUrlhttps://github.com/neomjs/neo/issues/7125
authortobiu
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJul 29, 2025, 11:49 PM

ComboBox: Optimize afterSetValue Selection Handling for SingleSelect

Closed v10.2.0 enhancement
tobiu
tobiu commented on Jul 29, 2025, 11:47 PM

Description:

The afterSetValue method in Neo.form.field.ComboBox contains a redundant call to selectionModel?.deselect(oldValue) when singleSelect is enabled.

Current Code (src/form/field/ComboBox.mjs, afterSetValue method):

if (me._picker?.isVisible) {
    let selectionModel = me.list?.selectionModel;

    if (value) {
        oldValue && selectionModel?.deselect(oldValue); // <-- This line is redundant when singleSelect is true
        selectionModel?.select(value)
    } else {
        selectionModel.deselectAll()
    }
}

Problem: When selectionModel.singleSelect is true (which is the default for ComboBox), the selectionModel.select(value) method itself handles the deselection of any previously selected item. Therefore, explicitly calling selectionModel?.deselect(oldValue) before select(value) is unnecessary. This leads to:

  • Redundant method calls.
  • Potentially unnecessary view.update() calls and selectionChange events from the selectionModel.

Proposed Change: Remove the line oldValue && selectionModel?.deselect(oldValue); from the afterSetValue method in src/form/field/ComboBox.mjs.

Reasoning: The selectionModel.select() method, when singleSelect is true, is designed to ensure only one item is selected. It will internally deselect any existing selection before applying the new one. Removing the redundant deselect call will streamline the selection logic, improve efficiency, and prevent potential unnecessary event emissions from the selectionModel.

tobiu assigned to @tobiu on Jul 29, 2025, 11:47 PM
tobiu added the enhancement label on Jul 29, 2025, 11:47 PM
tobiu referenced in commit 4b26ff7 - "ComboBox: Optimize afterSetValue Selection Handling for SingleSelect #7125" on Jul 29, 2025, 11:48 PM
tobiu closed this issue on Jul 29, 2025, 11:49 PM