Skip to content

✨ Recognize details element with open/[open] attributes and summary child element#18440

Merged
Gregable merged 7 commits intoampproject:masterfrom
westonruter:add/details-element
Dec 18, 2018
Merged

✨ Recognize details element with open/[open] attributes and summary child element#18440
Gregable merged 7 commits intoampproject:masterfrom
westonruter:add/details-element

Conversation

@westonruter
Copy link
Copy Markdown
Member

I couldn't find a clear explanation on why the HTML5 details element is not allowed. The only mention of it is #1410 in relation to amp-accordion. It would be helpful to support details when converting HTML into AMP (such as in the WordPress plugin), since it could be used as-is without having to try to port it over to amp-accordion (even though the latter is more powerful), as a details-to-amp-accordion conversion so would would cause complications with existing styles that target the details element and its children.

In this PR:

  • Add details element.
  • Add details element's open boolean attribute.
  • Add [open] to amp-bind for managing the the details element's open boolean attribute.
  • Add the summary element as a child of details.

With these changes in place, an AMP document would be able to do:

<amp-state id="detailsOpen">false</amp-state>
<button on="tap:AMP.setState({ detailsOpen: ! detailsOpen })">Toggle Open</button>

<details [open]="detailsOpen">
	<summary>Learn more</summary>
	<p>This is more information.</p>
</details>

Copy link
Copy Markdown
Contributor

@honeybadgerdontcare honeybadgerdontcare left a comment

Choose a reason for hiding this comment

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

Validation feedback only.

}
}
# 4.4.8 The dl element
# 4.11.1 (HTML5.3) The details element
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.

It seems with 5.3 they've renumbered everything so this doesn't really follow our existing numbering. I'd still recommend putting it just before 4.11 Scripting below and include a 4.11 Interactive elements before it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in 7255acd

# 4.11.1 (HTML5.3) The details element
tags: {
html_format: AMP
html_format: AMP4ADS
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.

Lets begin with just AMP and leave the other formats for future PRs. If you believe these should be added to other formats then I'd recommend opening an issue asking for feedback from others as each one of these formats have a different spec. Same for below for SUMMARY.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

EXPERIMENTAL would also be removed?

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.

Yes

tag_name: "SUMMARY"
mandatory_parent: "DETAILS"
}
# 4.4.9 The dl element
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.

Please leave as 4.4.8 as these are following the HTML5 spec.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 7255acd

@honeybadgerdontcare
Copy link
Copy Markdown
Contributor

@dvoytenko for including HTML5.3 spec items
@choumx for AMP4EMAIL spec
@lannka for AMP4ADS spec

@dvoytenko
Copy link
Copy Markdown
Contributor

The element itself LG. We won't be providing any polyfills, will we?

@westonruter
Copy link
Copy Markdown
Member Author

Why are the tests failing? Do I need to rebuild something and commit?

@honeybadgerdontcare
Copy link
Copy Markdown
Contributor

The test failure mentions that the tag name is not defined. And it is not defined for summary.

@westonruter
Copy link
Copy Markdown
Member Author

The element itself LG. We won't be providing any polyfills, will we?

@dvoytenko That's a good question. In terms of the actual clicking of the summary causing the open property to toggle, that could benefit from a polyfill. Otherwise if authors polyfill it themselves with amp-bind then perhaps they could cause double toggle in browsers that already have support, and thus the element's state could be stuck.

I think the styling of the element should be left to the author, however.

@westonruter
Copy link
Copy Markdown
Member Author

On second thought, I wonder if open should be included in what amp-bind can manipulate. When using amp-bind to manage the open state, if a browser supports details natively then the state for whether the element is expanded would be stored in two separate places. As seen in the example added in 609221a, you can expand the details by clicking on the summary, without updating the amp-state:

image

Likewise, if you opened the details via an amp-state change then closing it via the component would also not cause the state to update:

image

Since the state can easily get out of sync, it seems the open attribute should be excluded from amp-bind.

Thoughts?

@westonruter
Copy link
Copy Markdown
Member Author

What about the question regarding whether the open attribute should be controllable via amp-bind? #18440 (comment)

@Gregable
Copy link
Copy Markdown
Member

Gregable commented Oct 4, 2018

Re [open], I don't really have an opinion. Adding @choumx who might.

@Gregable Gregable requested a review from dreamofabear October 4, 2018 01:52
@Gregable
Copy link
Copy Markdown
Member

Gregable commented Oct 4, 2018

LGTM once the amp-bind question is resolved.

@dreamofabear
Copy link
Copy Markdown

Either way is fine by me. I think amp-accordion has a similar issue and it's not a dealbreaker IMO.

@westonruter
Copy link
Copy Markdown
Member Author

OK, cool. Let's keep [open] then I guess.

To deal with the inconsistent state issue, it would be great to introduce a way to connect a bound attribute with some state in a more declarative way so that updates to the attribute and to the state so that there could be two-way binding.

@westonruter
Copy link
Copy Markdown
Member Author

@Gregable I believe the question is resolved.

@westonruter
Copy link
Copy Markdown
Member Author

Anything left here to do?

Copy link
Copy Markdown
Contributor

@honeybadgerdontcare honeybadgerdontcare left a comment

Choose a reason for hiding this comment

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

validation changes look good

@Gregable Gregable merged commit 18b10a2 into ampproject:master Dec 18, 2018
honeybadgerdontcare added a commit that referenced this pull request Dec 19, 2018
* cl/225092847 Add validator rules for amp-video and amp-yotpo in EXPERIMENTAL.

* cl/225106151 "add validator changes to support script templates -alabiaga@"

* cl/225388113 Revision bump for #19854

* cl/225400099 Revision bump for #19871

* cl/225612473 Remove EXPERIMENTAL from amp-list and amp-state.

* cl/225861155 Revision bump for #19872

* cl/225872246 Revision bump for #19894

* cl/225876987 Revision bump for #18700

* cl/226048698 Revision bump for #19928

* cl/226051527 Revision bump for #18440
bramanudom pushed a commit to bramanudom/amphtml that referenced this pull request Dec 19, 2018
…hild element (ampproject#18440)

* Add details element with open boolean attr and summary child element

* Add details@open attribute to amp-bind

* Add Interative elements section with details and summary elements

Also limit html_format to just AMP.

* Add missing tag_name for summary element

* Fix order of summary tag properties

* Add amp-bind example for details element

* Include details/summary elements in AMP4ADS, AMP4EMAIL, EXPERIMENTAL
bramanudom pushed a commit to bramanudom/amphtml that referenced this pull request Dec 19, 2018
* cl/225092847 Add validator rules for amp-video and amp-yotpo in EXPERIMENTAL.

* cl/225106151 "add validator changes to support script templates -alabiaga@"

* cl/225388113 Revision bump for ampproject#19854

* cl/225400099 Revision bump for ampproject#19871

* cl/225612473 Remove EXPERIMENTAL from amp-list and amp-state.

* cl/225861155 Revision bump for ampproject#19872

* cl/225872246 Revision bump for ampproject#19894

* cl/225876987 Revision bump for ampproject#18700

* cl/226048698 Revision bump for ampproject#19928

* cl/226051527 Revision bump for ampproject#18440
@westonruter westonruter deleted the add/details-element branch February 13, 2019 06:03
noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
…hild element (ampproject#18440)

* Add details element with open boolean attr and summary child element

* Add details@open attribute to amp-bind

* Add Interative elements section with details and summary elements

Also limit html_format to just AMP.

* Add missing tag_name for summary element

* Fix order of summary tag properties

* Add amp-bind example for details element

* Include details/summary elements in AMP4ADS, AMP4EMAIL, EXPERIMENTAL
noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
* cl/225092847 Add validator rules for amp-video and amp-yotpo in EXPERIMENTAL.

* cl/225106151 "add validator changes to support script templates -alabiaga@"

* cl/225388113 Revision bump for ampproject#19854

* cl/225400099 Revision bump for ampproject#19871

* cl/225612473 Remove EXPERIMENTAL from amp-list and amp-state.

* cl/225861155 Revision bump for ampproject#19872

* cl/225872246 Revision bump for ampproject#19894

* cl/225876987 Revision bump for ampproject#18700

* cl/226048698 Revision bump for ampproject#19928

* cl/226051527 Revision bump for ampproject#18440
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.

7 participants