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

Make carousel indicators actual buttons #32661

Merged
merged 3 commits into from Jan 28, 2021

Conversation

patrickhlauke
Copy link
Member

@patrickhlauke patrickhlauke commented Jan 3, 2021

Currently, the carousel indicators are not conveyed at all to assistive technologies, and they can only be operated using the mouse.

This change generalises some of the stylings and JS to be backwards-compatible (meaning it's non-breaking), but caters for a more correct structure where the indicators are actual button elements (thus keyboard-focusable/operable), and where the currently active indicator is conveyed with aria-current

Preview: https://deploy-preview-32661--twbs-bootstrap.netlify.app/docs/5.0/components/carousel/#with-indicators

@patrickhlauke patrickhlauke requested review from a team as code owners January 3, 2021 11:11
@patrickhlauke patrickhlauke marked this pull request as draft January 3, 2021 11:11
@patrickhlauke patrickhlauke added this to Inbox in v5.0.0-beta2 via automation Jan 3, 2021
@patrickhlauke patrickhlauke force-pushed the patrickhlauke-carousel-indicators branch 2 times, most recently from ec39752 to e6cf4e8 Compare January 3, 2021 11:29
@XhmikosR XhmikosR removed this from Inbox in v5.0.0-beta2 Jan 3, 2021
@XhmikosR XhmikosR added this to Inbox in v5.0.0-beta3 via automation Jan 3, 2021
@patrickhlauke patrickhlauke force-pushed the patrickhlauke-carousel-indicators branch from e6cf4e8 to dee29d4 Compare January 3, 2021 12:20
@patrickhlauke
Copy link
Member Author

This relies on #32631 being merged to remove the overridden focus indicator for the button in reboot

Copy link
Member

@ffoodd ffoodd left a comment

Choose a reason for hiding this comment

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

LGTM, this is really needed.

I only wonder if we shouldn't introduce anew class name for single indicator (eg .carousel-indicator) instead of relying on data- attribute?
Edit: would be a breaking change.

@patrickhlauke
Copy link
Member Author

Edit: would be a breaking change.

yup, exactly. i see this as a first step, then we can make it a breaking change next time to offer more styling flexibility

@patrickhlauke
Copy link
Member Author

@mdo good to merge?

@XhmikosR
Copy link
Member

XhmikosR commented Jan 17, 2021 via email

js/src/carousel.js Outdated Show resolved Hide resolved
js/src/carousel.js Outdated Show resolved Hide resolved
@XhmikosR XhmikosR marked this pull request as draft January 18, 2021 13:53
@patrickhlauke patrickhlauke marked this pull request as ready for review January 18, 2021 15:10
@XhmikosR
Copy link
Member

So, about the JS part. Before, we were only looping once. Now we loop twice. Why can't we use children() like before? Also, I don't get how more than one active indicators can be present?

@XhmikosR XhmikosR force-pushed the patrickhlauke-carousel-indicators branch from 39e3e47 to be40c85 Compare January 28, 2021 09:54
@patrickhlauke
Copy link
Member Author

patrickhlauke commented Jan 28, 2021

Why can't we use children() like before

because it's not guaranteed that they're immediate children. before, with our structure, it was just a list, and the indicators were the immediate <li> elements. now, you may be using one container for all the indicators, and then have a few more structures in between, and only then the links or buttons of whatever you're using.

i.e. I could decide that yes, I still want an ordered list structure, so end up with

<ol class="carousel-indicators">
  <li ...><button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" aria-label="Slide 1"></button></li>
  ...
</ol>

or whatever.

@XhmikosR
Copy link
Member

XhmikosR commented Jan 28, 2021 via email

@XhmikosR
Copy link
Member

XhmikosR commented Jan 28, 2021 via email

@patrickhlauke
Copy link
Member Author

I don't get how more than one active indicators can be present?

I don't think my code looks for more than one? I do findOne to get the current active indicator and then remove its class and aria-current, and then i loop through all indicators, but as soon as i find one that has the right data-bs-slide-to i set class/aria-current and then break (as suggested by @rohit2sharma95)

@XhmikosR XhmikosR merged commit e79c8f3 into main Jan 28, 2021
v5.0.0-beta2 automation moved this from Approved to Done Jan 28, 2021
@XhmikosR XhmikosR deleted the patrickhlauke-carousel-indicators branch January 28, 2021 21:32
@patrickhlauke patrickhlauke added this to Inbox in v4.6.1 via automation Feb 11, 2021
@XhmikosR XhmikosR moved this from Inbox to Needs manual backport in v4.6.1 Feb 15, 2021
patrickhlauke added a commit that referenced this pull request Feb 21, 2021
@patrickhlauke patrickhlauke moved this from Needs manual backport to Cherry-picked/Manually backported in v4.6.1 Feb 21, 2021
@XhmikosR XhmikosR removed this from Cherry-picked/Manually backported in v4.6.1 Feb 22, 2021
XhmikosR pushed a commit that referenced this pull request Mar 11, 2021
Make carousel indicators actual buttons
XhmikosR pushed a commit that referenced this pull request Oct 8, 2021
Make carousel indicators actual buttons
maxokorokov added a commit to maxokorokov/ng-bootstrap that referenced this pull request Feb 22, 2022
- In Bootstrap 5 the CSS selector matching indicators has changed and included `data-bs-target` attribute that we were missing
- Recommended carousel markup changed from using `ul`, `li` and `a` to using `button` elements
- Had to refactor tests as selectors were not precise enough

On Bootstrap side see:
- twbs/bootstrap#32661
- twbs/bootstrap#32627

Fixes ng-bootstrap#4200
Fixes ng-bootstrap#4253
maxokorokov added a commit to ng-bootstrap/ng-bootstrap that referenced this pull request Feb 23, 2022
- In Bootstrap 5 the CSS selector matching indicators has changed and included `data-bs-target` attribute that we were missing
- Recommended carousel markup changed from using `ul`, `li` and `a` to using `button` elements
- Had to refactor tests as selectors were not precise enough

On Bootstrap side see:
- twbs/bootstrap#32661
- twbs/bootstrap#32627

Fixes #4200
Fixes #4253
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
v5.0.0-beta2
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants