Fix: render sub-items on mobile menu via accordion toggle#930
Open
vcfvct wants to merge 1 commit into
Open
Conversation
On mobile viewports the BasicMenu widget renders menu items that have children as plain links, making child pages (e.g. Mugs and Tumblers under DrinkWare) completely inaccessible. The root cause is the condition `item.children.length > 0 && !isMobile` which only renders NavigationMenuTrigger + NavigationMenuContent on desktop; on mobile the else branch renders a flat NavigationMenuLink and silently drops all children. This commit adds a MobileAccordionItem component that: - Shows the parent name as a navigable link to the category page - Adds a chevron toggle button that expands/collapses child links - Includes aria-expanded and aria-label for accessibility - Uses a 200ms rotate transition on the chevron indicator Desktop dropdown behavior is completely unchanged.
Author
|
@treoden , can you please take a look if this makes sense ? |
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
The
BasicMenuwidget renders menu items that have children as plain links on mobile, making child pages completely inaccessible. For example, if "DrinkWare" has sub-items "Mugs" and "Tumblers", tapping "DrinkWare" on mobile navigates directly to the category page with no way to reach the children.The root cause is the condition on line 103:
On mobile (
isMobile === true), the!isMobilecheck causes items with children to fall through to the else branch, which renders only the parent as a link and never renders the children.Desktop:
Mobile(no sub menus):
Solution
Split the render into two explicit branches — mobile and desktop:
NavigationMenuTrigger+NavigationMenuContentdropdownMobileAccordionItemcomponent that:aria-expandedandaria-labelfor accessibilityNew Mobile view:
Changes
Single file:
packages/evershop/src/modules/cms/components/BasicMenu.tsxMenuIteminterface to top level (was inline, needed by both components)MobileAccordionItemcomponent (~50 lines)isMobile ? <accordion list> : <NavigationMenu dropdown>branchTesting
npm run lint)