Skip to content

fix(useMultipleSelection): preserve active item when removing another item - #1701

Open
charan-rathore wants to merge 1 commit into
downshift-js:masterfrom
charan-rathore:fix/preserve-active-item-on-removal
Open

charan-rathore wants to merge 1 commit into
downshift-js:masterfrom
charan-rathore:fix/preserve-active-item-on-removal

Conversation

@charan-rathore

Copy link
Copy Markdown

What

Keep the active selection when removeSelectedItem removes a different item.

Why

Removing the final selected item currently changes activeIndex to the new final index even when the dropdown input or another selected item is active. Removing an earlier item also leaves an active item's index unadjusted.

For example, with A, B and C selected and the input focused (activeIndex: -1), removing C moves focus to B. The input should stay active.

How

Decrement the active index when an earlier item is removed. Keep it unchanged when a later item is removed. When the active item is removed, keep the next item active or use the previous item if the removed item was last. Removing the sole selected item still returns to -1.

Changes

  • Update the FunctionRemoveSelectedItem reducer case.
  • Add three regressions covering the input, an earlier active item, and an active item shifted by an earlier removal.

Testing

The three new cases fail against the original reducer and pass with the fix. The repository source tests pass: 92 suites, 1,113 tests and 49 snapshots, with 100% statements, branches, functions and lines. The SSR test, root TypeScript check, ESM/CJS Rollup builds and changed-file lint/format checks also pass.

These checks used an isolated toolchain with the repository-declared CommonJS plugin override, not the full npm run validate command. Native and nativeWeb CJS builds and export smoke checks also pass. The production UMD build fails on the same prop-types export error with the original reducer and this patch in this toolchain; the complete built-artifact suite cannot collect without that artifact. Preact and docs E2E were not run. A browser reproduction using the built ESM output confirms that removing C preserves input focus with the fix.

Checklist

  • Documentation - N/A, no API change
  • Tests
  • TypeScript Types - N/A, no type change
  • Ready to be merged - awaiting review and remaining CI validation

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant