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

Provide a pause button for Carousels #1146

Merged
merged 6 commits into from
Apr 20, 2022

Conversation

MewenLeHo
Copy link
Contributor

@MewenLeHo MewenLeHo commented Mar 10, 2022

Closes #1112

@MewenLeHo MewenLeHo force-pushed the main-mewenleho-carousels-pause-button branch from 11da3d8 to 47a3cb9 Compare March 10, 2022 16:04
@MewenLeHo MewenLeHo force-pushed the main-mewenleho-carousels-pause-button branch from 577d087 to 05a2203 Compare March 14, 2022 16:12
Copy link
Member

@louismaximepiton louismaximepiton left a comment

Choose a reason for hiding this comment

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

I feel weird using the pause button and unpause on hover. IMHO, I would have done a pause button that prevent hover on carousel play/pause behavior

scss/_variables.scss Outdated Show resolved Hide resolved
scss/_variables.scss Show resolved Hide resolved
scss/_variables.scss Outdated Show resolved Hide resolved
site/content/docs/5.1/components/carousel.md Outdated Show resolved Hide resolved
js/src/carousel.js Outdated Show resolved Hide resolved
js/src/carousel.js Outdated Show resolved Hide resolved
this._element.nextElementSibling.classList.add('play')
this._element.nextElementSibling.setAttribute('title', 'Play Carousel')
this._element.nextElementSibling.querySelector('span.visually-hidden').innerHTML = 'Play Carousel'
this._isPaused = true
Copy link
Member

Choose a reason for hiding this comment

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

IMO, this is dupe with following code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line is mandatory in order to prevent side effects between the play/pause button VS the already existing 'pause on hover' option.

Without this line, if you set the carousel to pause using the button and hover it with your cursor then the carousel will stay on pause on mouseenter and will restart to cycle on mouseleave but it will be stuck on the current slide.

However it may be due to the bug I found on Bootstrap carousel but we will have to wait for their fix to check it.

js/src/carousel.js Show resolved Hide resolved
@MewenLeHo
Copy link
Contributor Author

I feel weird using the pause button and unpause on hover. IMHO, I would have done a pause button that prevent hover on carousel play/pause behavior

I do not think that i's a good idea to block an option for users. In my opinion it's better to allow both and to make sure that it will not break is someone want to use both options.

js/src/carousel.js Outdated Show resolved Hide resolved
@@ -479,6 +479,22 @@ describe('Carousel', () => {
}, 10)
})
})

it('should take care of element either passed as a CSS selector or DOM element (Play/Pause button)', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure to understand this test, shouldn't it return the Carousel itself since you call new Carousel ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed together, it's a basic test used in all components. I think we need to keep it as it is.

scss/_variables.scss Outdated Show resolved Hide resolved
js/tests/unit/carousel.spec.js Show resolved Hide resolved
Copy link
Member

@louismaximepiton louismaximepiton left a comment

Choose a reason for hiding this comment

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

Two little points to clarify, but LGTM already.

const carouselEl = fixtureEl.querySelector('#myCarousel')
const carousel = new Carousel(carouselEl)

spyOn(carousel, 'pause').and.callThrough()
Copy link
Member

Choose a reason for hiding this comment

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

Do we need these .callthrough ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

const mouseOverEvent = createEvent('mouseover')
carouselEl.dispatchEvent(mouseOverEvent)

setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need these setTimeout ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because of th promise.

@MewenLeHo MewenLeHo force-pushed the main-mewenleho-carousels-pause-button branch from fe7df32 to 455a5b0 Compare April 4, 2022 13:27
Copy link
Member

@louismaximepiton louismaximepiton left a comment

Choose a reason for hiding this comment

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

LGTM if the behavior is approved !

@julien-deramond
Copy link
Member

FYI approved by the a11y team.

@julien-deramond julien-deramond force-pushed the main-mewenleho-carousels-pause-button branch from 16001a7 to caa8434 Compare April 6, 2022 11:30
Copy link
Member

@julien-deramond julien-deramond left a comment

Choose a reason for hiding this comment

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

Haven't finished the review yet but here are some first comments.

js/src/carousel.js Outdated Show resolved Hide resolved
js/src/carousel.js Outdated Show resolved Hide resolved
js/src/carousel.js Outdated Show resolved Hide resolved
js/src/carousel.js Outdated Show resolved Hide resolved
@MewenLeHo MewenLeHo force-pushed the main-mewenleho-carousels-pause-button branch 2 times, most recently from 16001a7 to 520a54b Compare April 6, 2022 13:06
Copy link
Member

@louismaximepiton louismaximepiton left a comment

Choose a reason for hiding this comment

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

Regarding performance, I think it could be a bit better.

Just looked at it, but the example button seems to be not aligned with the carousel

if (this._playPauseButton !== null && this._playPauseButton.classList.contains('pause')) {
this._playPauseButton.classList.remove('pause')
this._playPauseButton.classList.add('play')
this._playPauseButton.setAttribute('title', this._playPauseButton.getAttribute(SELECTOR_CAROUSEL_PLAY_TEXT))

This comment was marked as off-topic.

Copy link
Member

Choose a reason for hiding this comment

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

  • I think we should have a default value in English I guess

js/src/carousel.js Outdated Show resolved Hide resolved
js/src/carousel.js Outdated Show resolved Hide resolved
' <div class="carousel-item">item 3</div>',
' </div>',
'</div>',
'<button type="button" class="btn btn-icon btn-secondary pause" data-bs-control="play-button" data-bs-target="#myCarousel" data-bs-play-text="Play Carousel" data-bs-pause-text="Pause Carousel" title="Pause Carousel">',
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you should try with another text or language here ?

@MewenLeHo MewenLeHo force-pushed the main-mewenleho-carousels-pause-button branch from 39043f5 to fc3f65b Compare April 13, 2022 15:27
@julien-deramond julien-deramond force-pushed the main-mewenleho-carousels-pause-button branch 2 times, most recently from e401bfa to 31e3fce Compare April 19, 2022 06:51
site/content/docs/5.1/components/carousel.md Show resolved Hide resolved
scss/_variables.scss Outdated Show resolved Hide resolved
js/tests/unit/carousel.spec.js Outdated Show resolved Hide resolved
@julien-deramond
Copy link
Member

Just looked at it, but the example button seems to be not aligned with the carousel

I agree with @louismaximepiton's comment

@julien-deramond
Copy link
Member

julien-deramond commented Apr 19, 2022

@MewenLeHo There is an issue with JS tests probably linked to the remaining [data-bs-control="play-button"] in carousel.spec.js removed in 4038734:

const buttonPlayPauselEl = fixtureEl.querySelector('[data-bs-control="play-button"]')
const buttonPlayPauselBySelector = new Carousel('[data-bs-control="play-button"]')

I let you fix the tests and then I'll approve + merge 🚀

@julien-deramond
Copy link
Member

Bundlewatch needs to be updated as well

@MewenLeHo MewenLeHo force-pushed the main-mewenleho-carousels-pause-button branch from c9354f9 to 2c06277 Compare April 19, 2022 13:48
Copy link
Member

@julien-deramond julien-deramond left a comment

Choose a reason for hiding this comment

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

🚀

@julien-deramond julien-deramond merged commit 7f07c73 into main Apr 20, 2022
@julien-deramond julien-deramond deleted the main-mewenleho-carousels-pause-button branch April 20, 2022 05:34
@julien-deramond julien-deramond mentioned this pull request Jul 25, 2022
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.

Provide a pause button for Carousels
3 participants