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 expand-single-section attribute to <amp-accordion>. #13364

Merged
merged 4 commits into from Feb 16, 2018

Conversation

nainar
Copy link
Contributor

@nainar nainar commented Feb 8, 2018

This PR does the following

  • Adds an expand-one attribute to <amp-accordion> that ensures that only one <section> in <amp-accordion> is expanded at any given time.
  • Adds a test for the expansion/collapse of <section>s in
  • Adds an example file (I found it weird that <amp-accordion> didn't have an example page. Is that for a reason?). This example needs some work.

Fixes #11359

<script async custom-element="amp-accordion" src="https://cdn.ampproject.org/v0/amp-accordion-0.1.js"></script>
</head>
<body>
<amp-accordion expand-one>
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

sgtm, descriptive.

Copy link
Contributor Author

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.

Copy link
Contributor

@cvializ cvializ left a 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();
Copy link
Contributor

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()?

Copy link
Contributor Author

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.

Copy link
Contributor

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');
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor Author

@nainar nainar left a 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?

<script async custom-element="amp-accordion" src="https://cdn.ampproject.org/v0/amp-accordion-0.1.js"></script>
</head>
<body>
<amp-accordion expand-one>
Copy link
Contributor Author

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();
Copy link
Contributor Author

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');
Copy link
Contributor Author

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

@nainar nainar changed the title Add expand-one attribute to <amp-accordion>. Add expand-single-section attribute to <amp-accordion>. Feb 9, 2018
@nainar
Copy link
Contributor Author

nainar commented Feb 9, 2018

@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
Copy link
Contributor

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

Copy link
Contributor Author

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.

@nainar
Copy link
Contributor Author

nainar commented Feb 12, 2018

Hi @cvializ could you merge if this looks good to you? Thanks!

@cvializ cvializ merged commit 289ef16 into ampproject:master Feb 16, 2018
@cvializ
Copy link
Contributor

cvializ commented Feb 16, 2018

Looks good, thanks @nainar!

protonate pushed a commit to protonate/amphtml that referenced this pull request Feb 26, 2018
…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
powdercloud pushed a commit to powdercloud/amphtml that referenced this pull request Feb 27, 2018
powdercloud added a commit that referenced this pull request Feb 28, 2018
* version bump and experimental

* Remove '(CDATA)' from the error messages. Just say 'text'.

* Revision bump for #13364, #13500, #13536, #13386, and #13625
RanAbram pushed a commit to RanAbram/amphtml that referenced this pull request Mar 12, 2018
…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
RanAbram pushed a commit to RanAbram/amphtml that referenced this pull request Mar 12, 2018
* 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
protonate pushed a commit to protonate/amphtml that referenced this pull request Mar 15, 2018
…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
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.

None yet

4 participants