Skip to content

Commit 1d339e6

Browse files
jelbournannieyw
authored andcommitted
fix(material/paginator): add role="group" to host (#22512)
In testing `<mat-paginator>` with VoiceOver, I found that the interaction was much nicer when the paginator controls were semantically grouped with `role="group"`. This change adds the role and updates the documentation to explicitly instruct users to apply a meaningful label. (cherry picked from commit f06ff2a)
1 parent 5337421 commit 1d339e6

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

src/material-experimental/mdc-paginator/paginator.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,12 @@ describe('MDC-based MatPaginator', () => {
467467
expect(paginator.showFirstLastButtons).toBe(true);
468468
});
469469

470+
it('should set `role="group"` on the host element', () => {
471+
const fixture = createComponent(MatPaginatorApp);
472+
const hostElement = fixture.nativeElement.querySelector('mat-paginator');
473+
expect(hostElement.getAttribute('role')).toBe('group');
474+
});
475+
470476
});
471477

472478
function getPreviousButton(fixture: ComponentFixture<any>) {

src/material-experimental/mdc-paginator/paginator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export const MAT_PAGINATOR_DEFAULT_OPTIONS =
5757
inputs: ['disabled'],
5858
host: {
5959
'class': 'mat-mdc-paginator',
60+
'role': 'group',
6061
},
6162
changeDetection: ChangeDetectionStrategy.OnPush,
6263
encapsulation: ViewEncapsulation.None,

src/material/paginator/paginator.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ This will allow you to change the following:
2626
3. The tooltip messages on the navigation buttons.
2727

2828
### Accessibility
29-
The `aria-label`s for next page, previous page, first page and last page buttons can be set in `MatPaginatorIntl`.
29+
The paginator uses `role="group"` to semantically group its child controls. You must add an
30+
`aria-label` or `aria-labelledby` attribute to `<mat-paginator>` with a label that describes
31+
the content controlled by the pagination control.
32+
33+
You can set the `aria-label` attributes for the button and select controls within the paginator in
34+
`MatPaginatorIntl`.

src/material/paginator/paginator.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,12 @@ describe('MatPaginator', () => {
467467
expect(paginator.showFirstLastButtons).toBe(true);
468468
});
469469

470+
it('should set `role="group"` on the host element', () => {
471+
const fixture = createComponent(MatPaginatorApp);
472+
const hostElement = fixture.nativeElement.querySelector('mat-paginator');
473+
expect(hostElement.getAttribute('role')).toBe('group');
474+
});
475+
470476
});
471477

472478
function getPreviousButton(fixture: ComponentFixture<any>) {

src/material/paginator/paginator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ export abstract class _MatPaginatorBase<O extends {
357357
inputs: ['disabled'],
358358
host: {
359359
'class': 'mat-paginator',
360+
'role': 'group',
360361
},
361362
changeDetection: ChangeDetectionStrategy.OnPush,
362363
encapsulation: ViewEncapsulation.None,

0 commit comments

Comments
 (0)