refactor(carousel): Improved focus management and accessibility - #2296
Merged
Conversation
The carousel component has been refactored to enhance focus management and accessibility. The component now delegates focus to its indicators, navigation buttons or the first focusable element in the active slide when the carousel gains focus, whichever is present in that order. This enhances the user experience for keyboard and screen reader users, ensuring that they can easily navigate through the carousel content.
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors igc-carousel to improve keyboard focus entry and accessibility by enabling Shadow DOM focus delegation and adjusting the shadow DOM order so indicators are reached before navigation controls.
Changes:
- Enabled Shadow DOM
delegatesFocusforigc-carouselto improve focus behavior. - Reordered rendering so the indicator container precedes navigation buttons in the shadow DOM (affecting focus/tab order).
- Updated carousel shadow DOM rendering assertion and added a changelog entry describing the behavior change.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/components/carousel/carousel.ts | Adds delegatesFocus and reorders indicator vs navigation rendering to improve keyboard focus entry. |
| src/components/carousel/carousel.spec.ts | Updates the expected shadow DOM structure to match the new render order. |
| CHANGELOG.md | Documents the carousel focus delegation behavior change under Unreleased. |
Comments suppressed due to low confidence (1)
src/components/carousel/carousel.ts:100
- The new
delegatesFocusbehavior plus the DOM reorder changes the keyboard focus entry point (indicators now come before navigation). There’s no unit test asserting the new focus delegation / tab-order behavior (e.g., focusing the carousel host or tabbing into it lands on the active indicator when indicators are present, otherwise on the prev/next buttons, otherwise on the first focusable in the active slide). Adding a focused test would prevent regressions for issue #2291.
@shadowOptions({ delegatesFocus: true })
export default class IgcCarouselComponent extends EventEmitterMixin<
IgcCarouselComponentEventMap,
Constructor<LitElement>
>(LitElement) {
kdinev
previously approved these changes
Jul 27, 2026
Member
|
@rkaraivanov Maybe a test for the tab order? |
…l-focus-management
- Added unit tests for focus delegation and focus management in the carousel component. - Changed _renderIndicators() from a generator function to plain function.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/components/carousel/carousel.spec.ts:512
- The PR description/changelog mention delegating focus to the first focusable element in the active slide when indicators and navigation are not present, but the current Focus interaction tests only cover the indicator and previous-button cases. Adding a test for the “no indicators + no navigation” path will help prevent regressions and ensure the documented behavior is actually verified.
describe('Focus', () => {
it('should delegate focus to the active indicator in the indicator container when present', async () => {
carousel.focus();
expect(carousel.shadowRoot?.activeElement).to.equal(
carousel.renderRoot.querySelector(
'igc-carousel-indicator[tabindex="0"]'
)
);
});
it('should delegate focus to the previous button when the indicator container is not present', async () => {
carousel.hideIndicators = true;
await elementUpdated(carousel);
carousel.focus();
expect(carousel.shadowRoot?.activeElement).to.equal(prevButton);
});
});
kdinev
approved these changes
Jul 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The carousel component has been refactored to enhance focus management and accessibility. The component now delegates focus to its indicators, navigation buttons or the first focusable element in the active slide when the carousel gains focus, whichever is present in that order. This enhances the user experience for keyboard and screen reader users, ensuring that they can easily navigate through the carousel content.
Type of Change
Related Issues
#2291
Checklist