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

Fix bug where lightboxed carousel images show up twice #13563

Merged
merged 5 commits into from Feb 21, 2018

Conversation

cathyxz
Copy link
Contributor

@cathyxz cathyxz commented Feb 20, 2018

Happens when you lightbox the image inside the carousel, like so:

  <amp-carousel height="300"
  layout="fixed-height"
  type="carousel"
  >
    <amp-img src="https://picsum.photos/300/200/?image=10"
      width="300"
      height="200"
      alt="a sample image"
      lightbox></amp-img>
 </amp-carousel>

screen shot 2018-02-20 at 11 44 24 am

The bug itself is a bit awkward. It's because I can't toggle display: none on an <amp-img> with the .amp-scrollable-carousel-slide class, since it sets the display css property with !important. I'm not sure whether we should be using !important there, and I'm also not sure if the amp-scrollable-carousel-slide class should be prefixed with i-amphtml instead of amp-.

It seems reasonable to strip amp-related css classes, since basically what we're doing is taking the raw image with its raw aspect ratio, and blowing it to fill the screen. I'm wondering if we could just strip ALL CSS classes, or are there situations where it would be valid to keep the user-defined css classes? It's possible, like maybe they apply an opacity, or other visual effects...

ampClasses.push(cssClass);
}
}
clonedNode.classList.remove.apply(clonedNode.classList, ampClasses);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove all classes from the clone. I don't see a lot of situations where the style for the opener should apply to the lightboxed version. If anything it can cause weird bugs.

Copy link
Contributor

Choose a reason for hiding this comment

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

what does amp-image-lightbox do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It only propagates the aria-attributes, not the source.

Object.keys(this.ariaAttributes_).forEach(key => {
      this.ariaAttributes_[key] = sourceElement.getAttribute(key);
      if (this.ariaAttributes_[key]) {
        this.image_.setAttribute(key, this.ariaAttributes_[key]);
      }
    });

@@ -221,6 +220,7 @@ export class AmpLightboxGallery extends AMP.BaseElement {
const clonedNode = element.cloneNode(deepClone);
clonedNode.removeAttribute('on');
clonedNode.removeAttribute('id');
clonedNode.setAttribute('class', '');
Copy link
Contributor

Choose a reason for hiding this comment

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

removeAttribute?

@cathyxz cathyxz force-pushed the bugfix/extra-images-on-carousel branch from 9d323e4 to 6cdab96 Compare February 21, 2018 18:08
@cathyxz
Copy link
Contributor Author

cathyxz commented Feb 21, 2018

Had to rebase for visual diff tests.

@cathyxz cathyxz merged commit fb118c0 into ampproject:master Feb 21, 2018
@cathyxz cathyxz deleted the bugfix/extra-images-on-carousel branch February 22, 2018 22:25
RanAbram pushed a commit to RanAbram/amphtml that referenced this pull request Mar 12, 2018
)

* Fix bug where lightbox-ed carousel images show up twice

* Change spread operator to apply

* Fix lint

* Strip all css classes in image node clone

* Switch setAttribute to removeAttribute
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