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, collapse, toggle actions to amp-accordion #11933

Merged
merged 24 commits into from Nov 29, 2017
Merged

Add expand, collapse, toggle actions to amp-accordion #11933

merged 24 commits into from Nov 29, 2017

Conversation

mianuddin
Copy link
Contributor

@mianuddin mianuddin commented Nov 5, 2017

Reviewer: @aghassemi

@mianuddin
Copy link
Contributor Author

Whoops, I'll correct the issues found by Travis CI

@ampprojectbot ampprojectbot added this to the Pending Triage milestone Nov 6, 2017
@aghassemi aghassemi self-requested a review November 6, 2017 23:22
@@ -59,6 +59,40 @@ class AmpAccordion extends AMP.BaseElement {
this.sessionId_ = this.getSessionStorageKey_();
this.currentState_ = this.getSessionState_();

this.registerAction('toggle', invocation => {
if (invocation.args) {
const sectionEl = document.getElementById(invocation.args['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 use this.getAmpDoc().getElementById()

this.registerAction('toggle', invocation => {
if (invocation.args) {
const sectionEl = document.getElementById(invocation.args['section']);
this.toggle_(sectionEl);
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 do a

user().assertElement(
          sectionEl,
          'No element found with id:' + sectionId);

so devs can see what's happening if they make a mistake

@@ -59,6 +59,40 @@ class AmpAccordion extends AMP.BaseElement {
this.sessionId_ = this.getSessionStorageKey_();
this.currentState_ = this.getSessionState_();

this.registerAction('toggle', invocation => {
if (invocation.args) {
const sectionEl = document.getElementById(invocation.args['section']);
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 also put invocation.args['section'] in a constant to reuse later (see next comment)

this.toggle_(sectionEl);
} else {
const accordionEl = document.getElementById(invocation.target.id);
for (let i = 0; i < accordionEl.children.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

buildCallback() queries for all sections already but keeps them in a local variable. Let;s make that an instance variable and reuse it here instead of doing accordionEl.children

const content = sectionComponents[1];
const contentId = content.getAttribute('id');
const isSectionClosedAfterClick = section.hasAttribute('expanded');
this.mutateElement(() => {
if (section.hasAttribute('expanded')) {
if (typeof opt_forceExpand !== 'undefined' && opt_forceExpand) {
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 simplify this with something like

let toExpand;
if(opt_forceExpand === true) {
toExpand = true;
} else if( opt_forceExpand === false) {
toExpand = false;
} else {
toExpnd = section.hasAttribute('expanded')
}
if(toExpand) {
...
} else {
..
}


@aghassemi
Copy link
Contributor

Thanks for the PR @mianuddin, left some comments. Nothing major.

@aghassemi
Copy link
Contributor

@mianuddin, friendly ping regarding the review comments.

@mianuddin
Copy link
Contributor Author

@aghassemi Sorry for not implementing the changes sooner, I just had a big midterm. I'm aiming to complete the changes by end of week.

@aghassemi
Copy link
Contributor

@mianuddin no rush, take your time. Just wanted to make sure still interested in continuing the work.

@mianuddin
Copy link
Contributor Author

@aghassemi Apologies for the late commits. I've made the changes requested and fixed as much as I could from Travis CI. Your comments were extremely helpful, I really appreciate it.

@aghassemi
Copy link
Contributor

@mianuddin can you please rebase (or send another PR if too tangled to fix). PR shows 259 files changed and tons of unrelated commits

@mianuddin
Copy link
Contributor Author

@aghassemi I was able to rebase it 👍

Copy link
Contributor

@aghassemi aghassemi left a comment

Choose a reason for hiding this comment

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

Looks Good. Thanks for contributing.

@aghassemi
Copy link
Contributor

@mianuddin just a few lint errors causing tests to fail.

@mianuddin
Copy link
Contributor Author

@aghassemi I'll get on those, thanks!

@mianuddin
Copy link
Contributor Author

@aghassemi You're good to go! 💯

@aghassemi aghassemi merged commit deacb1c into ampproject:master Nov 29, 2017
@mianuddin mianuddin deleted the amp-accordion-actions branch November 29, 2017 00:36
ghost pushed a commit that referenced this pull request Dec 6, 2017
gzgogo pushed a commit to gzgogo/amphtml that referenced this pull request Jan 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants