Skip to content

Commit 2d418d8

Browse files
authored
Merge pull request #1248 from Michael-Hanley/fix/ariaLabelHeaders
Fix/aria label headers
2 parents c1d1d72 + 0c6b963 commit 2d418d8

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

packages/react-bootstrap-table2/src/header-cell.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class HeaderCell extends eventDelegater(React.Component) {
7777

7878
if (sort) {
7979
const customClick = cellAttrs.onClick;
80+
cellAttrs['aria-label'] = sorting ? `${text} sort ${sortOrder}` : `${text} sortable`;
8081
cellAttrs.onKeyUp = (e) => {
8182
if (e.key === 'Enter') {
8283
onSort(column);

packages/react-bootstrap-table2/test/header-cell.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,11 @@ describe('HeaderCell', () => {
370370
});
371371
});
372372
});
373+
374+
it('should not have aria-label', () => {
375+
wrapper = shallow(<HeaderCell column={ column } index={ index } />);
376+
expect(wrapper.find('th').prop('aria-label')).toBeUndefined();
377+
});
373378
});
374379

375380
describe('when column.sort is enable', () => {
@@ -413,11 +418,20 @@ describe('HeaderCell', () => {
413418
expect(onSortCallBack.callCount).toBe(0);
414419
});
415420

421+
it('should have aria-label', () => {
422+
expect(wrapper.find('th').prop('aria-label')).toBe('ID sortable');
423+
});
424+
425+
416426
describe('and sorting prop is false', () => {
417427
it('header should render SortSymbol as default', () => {
418428
expect(wrapper.find(SortSymbol).length).toBe(1);
419429
});
420430

431+
it('should describe column header as sortable', () => {
432+
expect(wrapper.find('th').prop('aria-label')).toBe('ID sortable');
433+
});
434+
421435
describe('when sortCaret is defined ', () => {
422436
beforeEach(() => {
423437
column = { ...column, sortCaret: jest.fn() };
@@ -445,6 +459,10 @@ describe('HeaderCell', () => {
445459
<HeaderCell column={ column } index={ index } sortOrder={ order } sorting />);
446460
});
447461

462+
it('should describe sort order in aria-label', () => {
463+
expect(wrapper.find('th').prop('aria-label')).toBe(`ID sort ${order}`);
464+
});
465+
448466
it('should render SortCaret correctly', () => {
449467
expect(wrapper.find(SortCaret).length).toBe(1);
450468
expect(wrapper.find(SortCaret).prop('order')).toEqual(order);

0 commit comments

Comments
 (0)