Skip to content

Make carousel indicators actual buttons - #32661

Merged
XhmikosR merged 3 commits into
mainfrom
patrickhlauke-carousel-indicators
Jan 28, 2021
Merged

XhmikosR merged 3 commits into
mainfrom
patrickhlauke-carousel-indicators

Conversation

@patrickhlauke

@patrickhlauke patrickhlauke commented Jan 3, 2021 •

Copy link
Copy Markdown
Member

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 v5 v5, the v5-dev branch accessibility Keyboard, screen readers, contrast, ARIA css Sass sources or compiled CSS docs Documentation site and its content js JavaScript or TypeScript sources and plugins labels Jan 3, 2021
@patrickhlauke
patrickhlauke force-pushed the patrickhlauke-carousel-indicators branch 3 times, most recently from e6cf4e8 to dee29d4 Compare January 3, 2021 12:20
@patrickhlauke

Copy link
Copy Markdown
Member Author

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

@ffoodd ffoodd left a comment •

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.

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
Copy Markdown
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

@XhmikosR
XhmikosR requested review from MartijnCuppens and mdo January 4, 2021 12:23
@patrickhlauke

Copy link
Copy Markdown
Member Author

@mdo good to merge?

@XhmikosR

XhmikosR commented Jan 17, 2021 via email

Copy link
Copy Markdown
Member

Comment thread js/src/carousel.js Outdated
Comment thread js/src/carousel.js
@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
@patrickhlauke

Copy link
Copy Markdown
Member Author

Wondering if this could/should be backported to v4 as well (since we're going to backport #32627 which is similar/related)

@XhmikosR

Copy link
Copy Markdown
Member

Not sure about the backports, I'm waiting for @mdo decide about this and #32627 backports.

@mdo

mdo commented Jan 27, 2021

Copy link
Copy Markdown
Member

I'm in favor of backporting if it's straightforward and provides a boost to folks and accessibility :).

@XhmikosR
XhmikosR force-pushed the patrickhlauke-carousel-indicators branch from 25246de to 39e3e47 Compare January 28, 2021 09:49
@XhmikosR

Copy link
Copy Markdown
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

patrickhlauke commented Jan 28, 2021 •

Copy link
Copy Markdown
Member Author

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

XhmikosR commented Jan 28, 2021 via email

Copy link
Copy Markdown
Member

@XhmikosR

XhmikosR commented Jan 28, 2021 via email

Copy link
Copy Markdown
Member

@patrickhlauke

Copy link
Copy Markdown
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
@XhmikosR
XhmikosR deleted the patrickhlauke-carousel-indicators branch January 28, 2021 21:32
@patrickhlauke patrickhlauke added the backport-to-v4 Legacy: v4 backports label Feb 11, 2021
patrickhlauke added a commit that referenced this pull request Feb 21, 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

Labels

accessibility Keyboard, screen readers, contrast, ARIA backport-to-v4 Legacy: v4 backports css Sass sources or compiled CSS docs Documentation site and its content js JavaScript or TypeScript sources and plugins v5 v5, the v5-dev branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants