Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of nested AMP navigation for the main menu in twenty nineteen theme. #6660

Merged
merged 25 commits into from
Oct 21, 2022

Conversation

dhaval-parekh
Copy link
Collaborator

@dhaval-parekh dhaval-parekh commented Oct 26, 2021

Summary

Fixes #4400

This PR makes the main navigation menu of twenty nineteen theme AMP-compatible. It transforms all first menu items with submenu into AMP nested menu within the AMP sidebar.

None AMP

4400-none-AMP.mov

AMP

4400-AMP.mov

Checklist

  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

Copy link
Collaborator

@milindmore22 milindmore22 left a comment

Choose a reason for hiding this comment

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

LGTM

@dhaval-parekh dhaval-parekh marked this pull request as ready for review October 29, 2021 11:07
@github-actions
Copy link
Contributor

github-actions bot commented Oct 29, 2021

Plugin builds for 74c408a are ready 🛎️!

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

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

Impressive how closely you've got it looking and behaving like non-AMP! 👍

The only thing I see you couldn't replicate is the "priority+" menu, which we know we couldn't do.

The one challenge I see with the submenus right now as implemented here is tapping them to open.

Non-AMP AMP
image image

Technically the non-AMP priority+ ... button is a bit smaller than the AMP 🔽. Nevertheless, in the latter there is a but more left margin making it easier to tap as opposed to tapping the top-level menu link (I think).

Maybe all of the buttons to open the sidebars should have the same styling with left margin?

*
* @return bool True if request is from mobile device Otherwise False.
*/
public static function is_mobile_request() {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to implement this without resorting to checking the user agent? I worry that checking for whether it is a mobile user agent will not work reliably due to caching layers. This is the same reason why we do client-side redirection by default with JS instead of server-side redirection in PHP.

One possibility would be to use the approach taken for Twenty Seventeen for the sticky menu, where the sanitizer makes a copy of the menu which is shown when it is made sticky. But that may be overkill. It may be worthwhile for each submenu however: include the original li > ul.sub-menu but only allow it to be displayed on desktop. Then also include the li > amp-sidebar but only show it on mobile. This may involve having two buttons, one that is desktop-specific and one that is mobile-specific.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have updated the implementation and removed the usage of is_mobile_request() and used the media query to display AMP navigation for mobile.

However, when bento is enabled ( with the filter add_filter( 'amp_bento_enabled', '__return_true' ); ) AMP navigation is broken. Currenttly fixing AMP navigation with bento enabled.

Copy link
Member

Choose a reason for hiding this comment

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

Broken in what way?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Bento disabled Bento enabled
image image

I think it is breaking because in bento mode. we are loading script 1.0 version for amp-sidebar component. and that may not support amp-nested-menu

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The issue is caused because the bento component for amp-nested-menu is not available.

includes/sanitizers/class-amp-core-theme-sanitizer.php Outdated Show resolved Hide resolved
includes/sanitizers/class-amp-core-theme-sanitizer.php Outdated Show resolved Hide resolved
includes/sanitizers/class-amp-core-theme-sanitizer.php Outdated Show resolved Hide resolved
includes/sanitizers/class-amp-core-theme-sanitizer.php Outdated Show resolved Hide resolved
includes/sanitizers/class-amp-core-theme-sanitizer.php Outdated Show resolved Hide resolved
includes/sanitizers/class-amp-core-theme-sanitizer.php Outdated Show resolved Hide resolved
includes/sanitizers/class-amp-core-theme-sanitizer.php Outdated Show resolved Hide resolved
@westonruter westonruter added this to the v2.3 milestone Dec 7, 2021
@westonruter
Copy link
Member

Since we're just a couple days prior to release, I'm going to punt this to 2.3 to go along with the other theme compatibility improvements to go with WordPress 5.9.

@westonruter westonruter removed this from the v2.3 milestone Jan 13, 2022
@westonruter westonruter added this to the v2.3.1 milestone Sep 29, 2022
@thelovekesh
Copy link
Collaborator

@westonruter This is ready for your review. After testing all changes looks good to me.

Non-AMP

Screencast.from.09-30-2022.09.23.33.PM.webm

AMP

Screencast.from.09-30-2022.09.27.46.PM.webm

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

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

Looks good. Just a couple small suggestions.

includes/sanitizers/class-amp-core-theme-sanitizer.php Outdated Show resolved Hide resolved
includes/sanitizers/class-amp-core-theme-sanitizer.php Outdated Show resolved Hide resolved
@westonruter
Copy link
Member

It looks like an E2E test is failing due to a change in Twenty Nineteen:

  ● Twenty Nineteen theme on AMP › main navigation on mobile › should have a togglable submenu

    Node is either not clickable or not an HTMLElement

@thelovekesh thelovekesh force-pushed the enhancement/4400-twentynineteen-mobile-menu branch from 9ab206a to 74c408a Compare October 21, 2022 15:43
await expect( menuItemWithSubmenu ).toMatchElement( '.sub-menu', { visible: false } );

await expect( menuItemWithSubmenu ).toClick( '.submenu-expand' );
await expect( menuItemWithSubmenu ).toClick( '.display-on-mobile' );
Copy link
Member

Choose a reason for hiding this comment

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

Was this a change in the theme?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nope, it was from core theme sanitizer.

@westonruter westonruter merged commit ccf43a3 into develop Oct 21, 2022
@westonruter westonruter deleted the enhancement/4400-twentynineteen-mobile-menu branch October 21, 2022 16:14
@westonruter westonruter modified the milestones: v2.3.1, v2.4 Jan 26, 2023
@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelogged Whether the issue/PR has been added to release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use amp-nested-menu to implement mobile menu in Twenty Nineteen
5 participants