fix(navigation-menu): open the dropdown panel under its trigger - #222
Merged
Merged
Conversation
A horizontal NavigationMenu rendered every dropdown in one shared panel
pinned to the menu's left edge, so a trigger near the end opened a panel
hundreds of pixels away, detached from it when the content was narrow.
The panel now follows the open trigger. The component measures the
trigger's inline start and width; CSS places the panel with clamp() so it
stays inside the menu, using the panel width the viewport already
exposes. It slides between triggers, appears in place when the menu
first opens, follows the list when it scrolls, and respects dir="rtl".
Below the sm breakpoint the panel keeps its full width.
A new align prop ('start' | 'center' | 'end', default 'center') chooses
where the panel sits relative to the trigger. The docs page gains a
Dropdown Alignment section to switch it live.
The list also reserved 8px under its items for the overlay scrollbar at
all times. That room is now added only while the list overflows, so a
menu that fits no longer shows the gap.
Closes #220
2 tasks done
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.
Summary
A horizontal
NavigationMenurendered every dropdown in one shared panel pinned to the menu's left edge. A trigger near the end of the menu opened a panel far away from it: 442px off for the last of six triggers, and fully detached (up to 202px apart) when the dropdown content was narrow.The panel now opens under the trigger that opened it, centred by default, and stays inside the menu when the trigger sits near an edge. A new
alignprop choosesstart,centerorend.The list also reserved 8px under its items for the overlay scrollbar at all times. That room is now added only while the list overflows.
Closes #220
Type of change
Changes
NavigationMenu: measures the open trigger's inline start and width and exposes them as--sv5ui-nav-trigger-startand--sv5ui-nav-trigger-width. Positioning stays in CSS: oneclamp()oninset-inline-startcombines the trigger, the panel width the viewport already exposes, and an alignment factor, so the panel never leaves the menu. Only the trigger is measured in JS.dir="rtl".unmountOnHide={false}.smbreakpoint the panel keeps its full width, as before.alignprop ('start' | 'center' | 'end', default'center'), implemented as a variant.scrollslot usesdata-[overflow]:pb-2instead of a permanentpb-2. Overflow is detected in the existing resize observers, so a menu that fits no longer shows the gap, and an overflowing menu still keeps the scrollbar clear of the items. Hovering does not change the height./navigation-menuswitchesalignlive.start,end, panel kept inside the menu at an edge, and the scroll padding toggling as the menu shrinks and grows. The alignment tests and the padding test fail ondev; the edge test passes on both and guards the clamp.CHANGELOG.mdentries under[Unreleased].Checklist
Closes #…)pnpm checkpasses (0 errors, 0 warnings)pnpm lintpassespnpm testpassesCHANGELOG.mdunder[Unreleased]*.types.ts, Material 3 design tokens)Screenshots / notes
Verified in Chromium against
dev:Header): the panel sits under every trigger and inside the menu. With room it is centred to 0px; the first and last triggers are clamped to the menu edges.alignstart,centerandendland at 0px in both LTR and RTL./navigation-menu: panel sizes and the gap to the trigger are unchanged; wide mega panels stay where they were, two move closer to their trigger. Thearrowindicator keeps its position and now sits over the panel.Behaviour change: every horizontal menu now centres its panel on the trigger. A menu that relied on the 8px gap under the list is 8px shorter.
Only verified in Chromium.