Skip to content

Fix bug where lightboxed carousel images show up twice - #13563

Merged
cathyxz merged 5 commits into
ampproject:masterfrom
cathyxz:bugfix/extra-images-on-carousel
Feb 21, 2018
Merged

Fix bug where lightboxed carousel images show up twice#13563
cathyxz merged 5 commits into
ampproject:masterfrom
cathyxz:bugfix/extra-images-on-carousel

Conversation

@cathyxz

@cathyxz cathyxz commented Feb 20, 2018

Copy link
Copy Markdown
Contributor

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...

@cathyxz
cathyxz force-pushed the bugfix/extra-images-on-carousel branch from 19c2053 to cd69570 Compare February 21, 2018 00:41
@cathyxz
cathyxz requested review from aghassemi and cvializ February 21, 2018 01:16
ampClasses.push(cssClass);
}
}
clonedNode.classList.remove.apply(clonedNode.classList, ampClasses);

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.

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
Copy Markdown
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
Copy Markdown
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]);
      }
    });

const clonedNode = element.cloneNode(deepClone);
clonedNode.removeAttribute('on');
clonedNode.removeAttribute('id');
clonedNode.setAttribute('class', '');

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.

removeAttribute?

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

cathyxz commented Feb 21, 2018

Copy link
Copy Markdown
Contributor Author

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.

4 participants