Add validation and documentation for <amp-mega-menu>#25210
Add validation and documentation for <amp-mega-menu>#25210leafsy merged 9 commits intoampproject:masterfrom
Conversation
|
Hey @ampproject/wg-caching, these files were changed:
|
|
Oh nvm I see that owners bot has been smart enough to tag @ampproject/wg-caching already. =) |
cathyxz
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
/fyi @nainar this is a hard restriction that at most one mega menu is allowed per document.
f182fba to
1072e36
Compare
| @@ -0,0 +1,228 @@ | |||
| --- | |||
There was a problem hiding this comment.
/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> | ||
|
|
There was a problem hiding this comment.
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.
CrystalOnScript
left a comment
There was a problem hiding this comment.
Had some clarity questions and structural changes - but overall looking good! Will do another passthrough when changes are made :)
| </tr> | ||
| </table> | ||
|
|
||
| ## Overview |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
Thanks for putting the reference template together! Some take aways & updates I'll make are:
- Take the description
<tr>out of the table and move its content to immediately after the extension title. - Remove the examples
<tr>. - Move the accessibility section to just before validation.
- Add an example for styling the component.
|
@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 |
1bc2a63 to
d530e66
Compare
d530e66 to
05adc2e
Compare
CrystalOnScript
left a comment
There was a problem hiding this comment.
Did a much heavier style/content review - let me know if you have questions/concerns!
CrystalOnScript
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
I'd rewrite as:
The <amp-mega-menu> component includes a single
<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. |
There was a problem hiding this comment.
Wrap amp-mustache in <>
|
|
||
| The example below customizes: | ||
|
|
||
| - The background color of the navigation bar |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Can you update the ; to .?
validator/validator-main.protoascii
Outdated
| html_format: AMP4EMAIL | ||
| html_format: ACTIONS | ||
| tag_name: "NAV" | ||
| disallowed_ancestor: "AMP-MEGA-MENU" |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
CrystalOnScript
left a comment
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
* add validation files * add documentations * add example file
* 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
I2I: #24814
Add validation and test files for the
<amp-mega-menu>extension.The following items are enforced via validation:
<amp-list><amp-form><amp-img><amp-video><amp-carousel><amp-lightbox><amp-ad>The change in
validator-main.protoasciiwas made so thatnavinsideamp-mega-menudoes not match to the generalnavtag in this file.PR Deployed Example (need the
amp-mega-menuexperiment on)