Repository navigation
fix(useMultipleSelection): preserve active item when removing another item - #1701
Open
charan-rathore wants to merge 1 commit into
Open
charan-rathore wants to merge 1 commit into
charan-rathore wants to merge 1 commit into
Conversation
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.
What
Keep the active selection when
removeSelectedItemremoves a different item.Why
Removing the final selected item currently changes
activeIndexto 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
FunctionRemoveSelectedItemreducer case.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 validatecommand. 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