Skip to content

#53331 Twenty Twenty-One: Update primary-navigation.js#2833

Closed
carolinan wants to merge 2 commits intoWordPress:trunkfrom
carolinan:Update/twenty-twenty-one-53331
Closed

#53331 Twenty Twenty-One: Update primary-navigation.js#2833
carolinan wants to merge 2 commits intoWordPress:trunkfrom
carolinan:Update/twenty-twenty-one-53331

Conversation

@carolinan
Copy link
Contributor

In Twenty Twenty-One, there is a bug where clicking on an anchor link in the content changes the state of the button that opens and closes the responsive menu.

This PR adds a conditional to check if the clicked anchor link is inside the primary navigation menu (ID site-navigation).
This is to prevent content anchor links from changing the state of the button.

Known limitations: The state of the button is not reset when the browser is resized.
If a menu anchor link is first clicked while on desktop width, and the browser width is reduced, the menu button will show the text "Close" even though the menu is not opened.

Trac ticket: https://core.trac.wordpress.org/ticket/53331

Testing instructions:

  1. In the WordPress admin backend, navigate to Appearance > Menus.
  2. Select a menu that shows in the "Primary Menu" Display Location. If there is no new menu, create a new one and assign it to the "Primary Menu" under Display Location.
  3. Under the "Add menu items" section, expand the sub-section "Custom Links".
  4. In the field URL, add something like #test.
  5. In the Field Link Text add something like "Sample Link".
  6. Click the Button Add To Menu to add the item to your menu.
  7. Click Save Menu which should be on the right near the bottom.
  8. Create a new post or page. In the content, add text with an anchor link such as #test2.
  9. Go to the front of the website and open the post or page that you created.
  10. Reduce the browser window width until the button that opens the responsive menu shows.
  11. Click on the anchor link in the content.
  12. Confirm that the menu button does not change visually.
  13. Open the primary menu in the header. Click on the Sample Link menu item you created in step 5.
  14. Confirm that the menu closes.

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

wrapper.classList.remove( id + '-navigation-open', 'lock-scrolling' );
twentytwentyoneToggleAriaExpanded( mobileButton );
// Wait 550 and scroll to the anchor.
setTimeout(function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although there's this setTimeout. the page scrolls immediately. This happens because the browser runs the default action: it follows the link and scrolls to the page fragment. We should either prevent the default action with an event.preventDefault() placed before the setTimeout or remove the setTimeout.

Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carolinan thank you. LGTM.

@audrasjb
Copy link
Contributor

@audrasjb audrasjb closed this Jan 24, 2023
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.

4 participants