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

Carousel #6295

Merged
merged 7 commits into from Nov 22, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions extensions/amp-carousel/0.1/slidescroll.js
Expand Up @@ -467,8 +467,10 @@ export class AmpSlideScroll extends BaseSlides {
if (showIndex == newIndex) {
this.scheduleLayout(this.slides_[showIndex]);
this.scheduleResume(this.slides_[showIndex]);
this.slides_[showIndex].setAttribute('aria-hidden', 'false');
} else {
this.schedulePreload(this.slides_[showIndex]);
this.slides_[showIndex].setAttribute('aria-hidden', 'true');
}
});
this.slidesContainer_./*OK*/scrollLeft =
Expand Down Expand Up @@ -515,6 +517,7 @@ export class AmpSlideScroll extends BaseSlides {
setStyle(this.slideWrappers_[i], 'order', '');
}
this.slideWrappers_[i].classList.remove(SHOWN_CSS_CLASS);
this.slides_[i].setAttribute('aria-hidden', 'true');
Copy link
Contributor

Choose a reason for hiding this comment

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

should we removeAttribute here and let the browser take care of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aghassemi - WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM. End result is the same,removeAttribute is a faster DOM operation than setAttribute anyway.

}
// Pause if not the current slide
if (this.slideIndex_ != i) {
Expand Down
23 changes: 23 additions & 0 deletions extensions/amp-carousel/0.1/test/test-slidescroll.js
Expand Up @@ -91,6 +91,8 @@ describe('SlideScroll', () => {
.to.be.true;
expect(impl.slideWrappers_[1].classList.contains(SHOW_CLASS))
.to.be.true;
expect(impl.slides_[0].getAttribute('aria-hidden')).to.equal('false');
expect(impl.slides_[1].getAttribute('aria-hidden')).to.equal('true');
});
});

Expand Down Expand Up @@ -192,6 +194,9 @@ describe('SlideScroll', () => {
'amp-carousel-next', {'fromSlide': 'slide-id', 'toSlide': '1'});
expect(analyticsEventSpy).to.have.been.calledWith(
'amp-carousel-change', {'fromSlide': 'slide-id', 'toSlide': '1'});
expect(impl.slides_[0].getAttribute('aria-hidden')).to.equal('true');
expect(impl.slides_[1].getAttribute('aria-hidden')).to.equal('false');
expect(impl.slides_[2].getAttribute('aria-hidden')).to.equal('true');

impl.showSlide_(0);

Expand Down Expand Up @@ -220,6 +225,8 @@ describe('SlideScroll', () => {
'amp-carousel-prev', {'fromSlide': '1', 'toSlide': 'slide-id'});
expect(analyticsEventSpy).to.have.been.calledWith(
'amp-carousel-change', {'fromSlide': '1', 'toSlide': 'slide-id'});
expect(impl.slides_[0].getAttribute('aria-hidden')).to.equal('false');
expect(impl.slides_[1].getAttribute('aria-hidden')).to.equal('true');

impl.showSlide_(4);

Expand All @@ -246,6 +253,9 @@ describe('SlideScroll', () => {
'amp-carousel-prev', {'fromSlide': 'slide-id', 'toSlide': '4'});
expect(analyticsEventSpy).to.have.been.calledWith(
'amp-carousel-change', {'fromSlide': 'slide-id', 'toSlide': '4'});
expect(impl.slides_[3].getAttribute('aria-hidden')).to.equal('true');
expect(impl.slides_[4].getAttribute('aria-hidden')).to.equal('false');
expect(impl.slides_[0].getAttribute('aria-hidden')).to.equal('true');
});
});

Expand Down Expand Up @@ -587,6 +597,10 @@ describe('SlideScroll', () => {
sandbox.spy(impl, 'hideRestOfTheSlides_');
const setControlsStateSpy = sandbox.spy(impl, 'setControlsState');

expect(impl.slides_[4].getAttribute('aria-hidden')).to.equal('true');
expect(impl.slides_[0].getAttribute('aria-hidden')).to.equal('false');
expect(impl.slides_[1].getAttribute('aria-hidden')).to.equal('true');

impl.showSlide_(1);

expect(updateInViewportSpy).to.have.been.calledWith(
Expand All @@ -611,6 +625,9 @@ describe('SlideScroll', () => {
expect(hideRestOfTheSlidesSpy).to.have.been.calledWith([0, 1, 2]);
expect(hideRestOfTheSlidesSpy.callCount).to.equal(1);
expect(setControlsStateSpy.callCount).to.equal(1);
expect(impl.slides_[0].getAttribute('aria-hidden')).to.equal('true');
expect(impl.slides_[1].getAttribute('aria-hidden')).to.equal('false');
expect(impl.slides_[2].getAttribute('aria-hidden')).to.equal('true');

impl.showSlide_(0);

Expand All @@ -637,6 +654,9 @@ describe('SlideScroll', () => {
expect(hideRestOfTheSlidesSpy).to.have.been.calledWith([4, 0, 1]);
expect(hideRestOfTheSlidesSpy.callCount).to.equal(2);
expect(setControlsStateSpy.callCount).to.equal(2);
expect(impl.slides_[4].getAttribute('aria-hidden')).to.equal('true');
expect(impl.slides_[0].getAttribute('aria-hidden')).to.equal('false');
expect(impl.slides_[1].getAttribute('aria-hidden')).to.equal('true');

impl.showSlide_(4);

Expand All @@ -662,6 +682,9 @@ describe('SlideScroll', () => {
expect(hideRestOfTheSlidesSpy).to.have.been.calledWith([3, 4, 0]);
expect(hideRestOfTheSlidesSpy.callCount).to.equal(3);
expect(setControlsStateSpy.callCount).to.equal(3);
expect(impl.slides_[3].getAttribute('aria-hidden')).to.equal('true');
expect(impl.slides_[4].getAttribute('aria-hidden')).to.equal('false');
expect(impl.slides_[0].getAttribute('aria-hidden')).to.equal('true');

});
});
Expand Down