Skip to content

Add validation and documentation for <amp-mega-menu>#25210

Merged
leafsy merged 9 commits intoampproject:masterfrom
leafsy:mega-menu-docs
Oct 31, 2019
Merged

Add validation and documentation for <amp-mega-menu>#25210
leafsy merged 9 commits intoampproject:masterfrom
leafsy:mega-menu-docs

Conversation

@leafsy
Copy link
Copy Markdown
Contributor

@leafsy leafsy commented Oct 22, 2019

I2I: #24814

Add validation and test files for the <amp-mega-menu> extension.

The following items are enforced via validation:

  • Whitelist the components below inside mega menu:
    • <amp-list>
    • <amp-form>
    • <amp-img>
    • <amp-video>
    • <amp-carousel>
    • <amp-lightbox>
    • <amp-ad>
  • Mega menu should contain a single nav element, which:
    • Has either ul or ol as its only child;
    • Has no other siblings;
    • Is parented by either mega menu itself or amp-list/template;
  • The ul/ol under nav can contain only li (menu items) as children;
  • Every menu item should have 1~2 direct children:
    • If there are two children, exactly one should have role="dialog";
    • Disallow role=”menu” as a child (until supported by implementation);

The change in validator-main.protoascii was made so that nav inside amp-mega-menu does not match to the general nav tag in this file.

PR Deployed Example (need the amp-mega-menu experiment on)

@amp-owners-bot
Copy link
Copy Markdown

amp-owners-bot bot commented Oct 22, 2019

Hey @ampproject/wg-caching, these files were changed:

  • extensions/amp-mega-menu/0.1/test/validator-amp-mega-menu-error.html
  • extensions/amp-mega-menu/0.1/test/validator-amp-mega-menu-error.out
  • extensions/amp-mega-menu/0.1/test/validator-amp-mega-menu.html
  • extensions/amp-mega-menu/0.1/test/validator-amp-mega-menu.out
  • extensions/amp-mega-menu/validator-amp-mega-menu.protoascii

@leafsy leafsy requested a review from cathyxz October 22, 2019 22:58
@cathyxz cathyxz requested review from Gregable and removed request for Gregable October 22, 2019 23:14
@cathyxz
Copy link
Copy Markdown
Contributor

cathyxz commented Oct 22, 2019

Oh nvm I see that owners bot has been smart enough to tag @ampproject/wg-caching already. =)

Copy link
Copy Markdown
Contributor

@cathyxz cathyxz left a comment

Choose a reason for hiding this comment

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

I'd defer to @ampproject/wg-caching for the correct usage of reference points, but this looks fine. Consider adding your documentation to this PR, since we should review to make sure that validator rules and documentation are consistent with each other.

tag_name: "AMP-MEGA-MENU"
requires_extension: "amp-mega-menu"
# Mandate that component contains a nav element as descendant. This approach
# only works because there is at most one <amp-mega-menu> in a document.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/fyi @nainar this is a hard restriction that at most one mega menu is allowed per document.

@leafsy leafsy changed the title Add validation rules for <amp-mega-menu> Add validation and documentation for <amp-mega-menu> Oct 23, 2019
@@ -0,0 +1,228 @@
---
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/fyi @nainar in case you would like to take a look.
/cc @CrystalOnScript for a documentation review

<td>This element includes <a href="https://amp.dev/documentation/guides-and-tutorials/learn/common_attributes">common attributes</a> extended to AMP components.</td>
</tr>
</table>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add a section on Accessibility. In particular, reference the accessibility documentation with regards to Hover, as well as explain the elements and attributes added for accessibility.

Copy link
Copy Markdown
Contributor

@cathyxz cathyxz left a comment

Choose a reason for hiding this comment

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

LGTM

@honeybadgerdontcare
Copy link
Copy Markdown
Contributor

@twifkak for detailed validation review. I've requested @leafsy to split the validator test file into separate test files since it's usage is unique and then any <!-- Valid: ...> will return a PASS for that file.

Copy link
Copy Markdown
Contributor

@CrystalOnScript CrystalOnScript left a comment

Choose a reason for hiding this comment

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

Had some clarity questions and structural changes - but overall looking good! Will do another passthrough when changes are made :)

</tr>
</table>

## Overview
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall this looks good! We're attempting to standardize the reference documentation - theres a template that outlines headers and content here. Would you mind taking a look a seeing if theres any updates we can make to this document to align with the template? Please let me know if theres anything confusing or if you disagree with anything in the template. Its a WIP :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for putting the reference template together! Some take aways & updates I'll make are:

  1. Take the description <tr> out of the table and move its content to immediately after the extension title.
  2. Remove the examples <tr>.
  3. Move the accessibility section to just before validation.
  4. Add an example for styling the component.

@leafsy
Copy link
Copy Markdown
Contributor Author

leafsy commented Oct 28, 2019

@CrystalOnScript Really appreciate your review! It's my first time writing this kind of documentation, so definitely nice to get more eyes on the pr.

About the restriction of one <amp-mega-menu> per document, I've given it more thought and think that we should drop it from validation rules. I can think of use cases where developer might include multiple mega menus for different devices and switch them via media query. What we don't want is nested mega menus, which should already been prevented via validation. /cc @nainar on this

Copy link
Copy Markdown
Contributor

@CrystalOnScript CrystalOnScript left a comment

Choose a reason for hiding this comment

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

Did a much heavier style/content review - let me know if you have questions/concerns!

Copy link
Copy Markdown
Contributor

@CrystalOnScript CrystalOnScript left a comment

Choose a reason for hiding this comment

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

Looking really great! Just some last minute nits I didn't catch before :)


# `amp-mega-menu`

A horizontal navigation bar containing a set of menu items that, when activated via click, open/close corresponding containers underneath with additional content.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Simplify to:

Horizontal navigation bar with menu items that open/close content containers on click.


## Overview

`<amp-mega-menu>` provides a way to organize and display large collections of navigational content at the top of an AMP page. The component is intended primarily for desktop and tablet use cases, and it can be used jointly with [`<amp-sidebar>`](../amp-sidebar/0.1/amp-sidebar.md) to create a responsive menu.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd rewrite as:

The <amp-mega-menu> component includes a single

element containing either a <ul> or <ol>, where each <li> element is a menu item.


### Dynamic content rendering

Fetch content of `<amp-mega-menu>` dynamically from a JSON endpoint using [`<amp-list>`](../amp-list/amp-list.md) and [`amp-mustache`](../amp-mustache/amp-mustache.md) template.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wrap amp-mustache in <>


The example below customizes:

- The background color of the navigation bar
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mind adding a . at the end of each bullet?


Keyboard support for the component includes:

- Left/right arrow keys to navigate between menu items when focused;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you update the ; to .?

html_format: AMP4EMAIL
html_format: ACTIONS
tag_name: "NAV"
disallowed_ancestor: "AMP-MEGA-MENU"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add a comment that inside AMP-MEGA-MENU, this is replaced by more specific rules. (It took me a while to figure out why this was here.)

child_tags: {
mandatory_num_child_tags: 1
child_tag_name_oneof: "NAV"
child_tag_name_oneof: "AMP-LIST"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a test for this? amp-list does not satisfy "amp-mega-menu" so given the mandatory_num_child_tags: 1, I don't see how this can be used (unless you have two mega-menus as I mention above).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So my intention is that mega menu can follow one of two patterns:
<amp-mega-menu> > <nav> > ... or
<amp-mega-menu> > <amp-list> > <template> > <nav> > ...
Where the nav underneath <template> would satisfy the requirement. Examples of both cases are included in validator-amp-mega-menu.html.

html_format: AMP
tag_name: "AMP-MEGA-MENU"
requires_extension: "amp-mega-menu"
requires: "amp-mega-menu nav"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

requires/satisfies may not be doing exactly what you expect. They are whole-document booleans. e.g. I think this will be valid:

<amp-mega-menu layout=fixed-height>
  <amp-list></amp-list> <!-- meets the `child_tag_name_oneof` requirement but not the `requires` -->
</amp-mega-menu>
<amp-mega-menu layout=fixed-height>
  <nav><ol>...valid li...</ol></nav> <!-- `satisfies: "amp-mega-menu"` for both mega-menus -->
</amp-mega-menu>

If I'm wrong about that, add a test to prove me wrong. :)

But is this necessary? Maybe the mandatory_num_child_tags+child_tag_name_oneof is sufficient?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah you're right. It'd be simple if we didn't need to support the second case in the comment above. Rather than using requires/satisfies, perhaps I can still use reference points to cover both cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@twifkak updated the validation rules and added some more tests. I'm now using reference points to validate the two cases mentioned before, and should no longer need to change validator-main.protoascii. The only situation not covered by the new rules is nested navs, which I can add as a dev warning instead.

Copy link
Copy Markdown
Contributor

@CrystalOnScript CrystalOnScript left a comment

Choose a reason for hiding this comment

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

Thanks for all the edits! LGTM :)

siblings_disallowed: true
tag_name: "$REFERENCE_POINT"
spec_name: "AMP-MEGA-MENU > AMP-LIST"
# Include mandatory amp-list attrs so that <amp-mega-menu> > <nav>
Copy link
Copy Markdown
Member

@twifkak twifkak Oct 31, 2019

Choose a reason for hiding this comment

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

Neat hack. We're lucky that the two can be differentiated by attributes. It seems a bit fragile given it's dependent on the mandatory_anyof in validator-amp-list.protoascii (or else a no-attrs <amp-list/> would match the nav ref point), but I can't think of a better solution off the top of my head.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Indeed; it'd be nice if we could distinguish reference points by tag name, but not sure if there's significant engineering cost associated with that.

@leafsy leafsy merged commit bab8868 into ampproject:master Oct 31, 2019
@leafsy leafsy deleted the mega-menu-docs branch October 31, 2019 23:24
amaltas added a commit that referenced this pull request Nov 5, 2019
amaltas added a commit that referenced this pull request Nov 6, 2019
* cl/277925913 Revision bump for #25291

* cl/277925913 Revision bump for #25291

* cl/278402306 Remove unused CSS selector code

* cl/278620720 Revision bump for #25210

* cl/278642597 Revision bump for #24793

* cl/278653831 Revision bump for #25425

* Fix merge issues in original rollup commit
micajuine-ho pushed a commit to micajuine-ho/amphtml that referenced this pull request Dec 27, 2019
* add validation files

* add documentations

* add example file
micajuine-ho pushed a commit to micajuine-ho/amphtml that referenced this pull request Dec 27, 2019
* cl/277925913 Revision bump for ampproject#25291

* cl/277925913 Revision bump for ampproject#25291

* cl/278402306 Remove unused CSS selector code

* cl/278620720 Revision bump for ampproject#25210

* cl/278642597 Revision bump for ampproject#24793

* cl/278653831 Revision bump for ampproject#25425

* Fix merge issues in original rollup commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants