fix(CNavGroup): retain nested subgroup state when reopening a collapsed parent#460
Merged
Merged
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.
Problem
When a
CNavGroupthat contains nested sub-groups is collapsed and then re-opened, all of its sub-groups appear closed — their previous open state is lost. This diverges from the vanilla@coreui/coreuinavigation (the source of truth) and from@coreui/vue, where the nested sub-groups stay open on reopen.Root cause
CSidebarNavtracked a single globalopenChain(the path of ids from the root to the deepest open group) and eachCNavGroupderived its visibility from a prefix match against it. Collapsing a parent truncatedopenChainto the parent's chain, discarding all descendant ids; reopening set it back to just the parent's own chain — so the descendants were forgotten.A single open path simply cannot represent "parent collapsed, but its children remembered as open".
Fix
Replace the single-path model with a per-level accordion, mirroring vanilla (
groupsAutoCollapse) and the Vue implementation:CNavGroupContextnow carries{ activeId, setActiveId, openBranch }for the current level instead of an ancestor-id chain.CSidebarNavprovides the root-level accordion state.CNavGroupkeeps its ownactiveChildIdfor its children. That state lives on the always-mounted component, so collapsing an ancestor never discards it — reopening restores whichever child was open.visible+onVisibleChange) is unchanged.CNavLinkopens its whole ancestor branch viaopenBranch()when it becomes active (replaces the oldsetOpenChain(parentChain)).CSidebarNavContext(not part of the public API).Tests
reopening a parent restores the open state of its nested subgroups.opening an uncontrolled group collapses its sibling.No prop changes, so the API tables are unaffected.