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 expand-single-section attribute to <amp-accordion>. #13364
Conversation
examples/accordion.amp.html
Outdated
<script async custom-element="amp-accordion" src="https://cdn.ampproject.org/v0/amp-accordion-0.1.js"></script> | ||
</head> | ||
<body> | ||
<amp-accordion expand-one> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's think of the name a bit more
I recommend single
as the attribute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about expand-single-section
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm, descriptive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change made in latest commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, just one question before LGTM
if (toExpand) { | ||
section.setAttribute('expanded', ''); | ||
header.setAttribute('aria-expanded', 'true'); | ||
// if expand-one is set, only allow one <section> to be expanded at a time | ||
if (this.element.hasAttribute('expand-one')) { | ||
this.sections_ = this.getRealChildren(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to reassign this.sections_
? Will it be different than the this.sections_
assigned in buildCallback()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, you are right. Ommitted
#### `toggle` | ||
This action toggles between the `expanded` and `collapsed` states of the `amp-accordion`. When called with no arguements, it will toggle all sections of the accordion. A single section may be specified with the `section` arguement and the corresponding `id` as the value. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, the spacing looks better 👍
expect(ampAccordion.hasAttribute('expand-one')).to.be.true; | ||
const impl = ampAccordion.implementation_; | ||
const headerElements = doc.querySelectorAll( | ||
'section > *:first-child'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: I see this in the rest of the file so you don't have to change it, but technically the *
is not required and it could just be section > :first-child
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, thanks for bringing this to my attention
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cvializ made the change you asked for.
@aghassemi have a name suggestion for you, PTAL?
examples/accordion.amp.html
Outdated
<script async custom-element="amp-accordion" src="https://cdn.ampproject.org/v0/amp-accordion-0.1.js"></script> | ||
</head> | ||
<body> | ||
<amp-accordion expand-one> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about expand-single-section
?
if (toExpand) { | ||
section.setAttribute('expanded', ''); | ||
header.setAttribute('aria-expanded', 'true'); | ||
// if expand-one is set, only allow one <section> to be expanded at a time | ||
if (this.element.hasAttribute('expand-one')) { | ||
this.sections_ = this.getRealChildren(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, you are right. Ommitted
expect(ampAccordion.hasAttribute('expand-one')).to.be.true; | ||
const impl = ampAccordion.implementation_; | ||
const headerElements = doc.querySelectorAll( | ||
'section > *:first-child'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, thanks for bringing this to my attention
@cvializ / @aghassemi for review |
@@ -86,6 +89,10 @@ Set this attribute on the `<amp-accordion>` to opt out of preserving the collaps | |||
|
|||
Set this attribute on a `<section>` to display the section as expanded on page load. | |||
|
|||
##### expand-single-section |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add ticks ` around the attribute name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done and did this for the other 2 attributes as well.
Hi @cvializ could you merge if this looks good to you? Thanks! |
Looks good, thanks @nainar! |
…3364) * Add expand-one attribute to amp-accordion. Add example file for amp-accordion. * Address cvializ@'s comments * Rename expand-one attribute to expand-single-section * Add ticks around attribute names
…3364) * Add expand-one attribute to amp-accordion. Add example file for amp-accordion. * Address cvializ@'s comments * Rename expand-one attribute to expand-single-section * Add ticks around attribute names
* version bump and experimental * Remove '(CDATA)' from the error messages. Just say 'text'. * Revision bump for ampproject#13364, ampproject#13500, ampproject#13536, ampproject#13386, and ampproject#13625
…3364) * Add expand-one attribute to amp-accordion. Add example file for amp-accordion. * Address cvializ@'s comments * Rename expand-one attribute to expand-single-section * Add ticks around attribute names
This PR does the following
expand-one
attribute to<amp-accordion>
that ensures that only one<section>
in<amp-accordion>
is expanded at any given time.<section>
s in<amp-accordion>
didn't have an example page. Is that for a reason?). This example needs some work.Fixes #11359