Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/react-bootstrap-table2/src/header-cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class HeaderCell extends eventDelegater(React.Component) {

if (sort) {
const customClick = cellAttrs.onClick;
cellAttrs.onKeyUp = (e) => {
if (e.key === 'Enter') {
onSort(column);
if (_.isFunction(customClick)) customClick(e);
}
};
cellAttrs.onClick = (e) => {
onSort(column);
if (_.isFunction(customClick)) customClick(e);
Expand Down
14 changes: 14 additions & 0 deletions packages/react-bootstrap-table2/test/header-cell.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,25 @@ describe('HeaderCell', () => {
expect(wrapper.find('th').prop('onClick')).toBeDefined();
});

it('should have onKeyUp event on header cell', () => {
expect(wrapper.find('th').prop('onKeyUp')).toBeDefined();
});

it('should trigger onSort callback when click on header cell', () => {
wrapper.find('th').simulate('click');
expect(onSortCallBack.callCount).toBe(1);
});

it('should trigger onSort callback when keyup Enter on header cell', () => {
wrapper.find('th').simulate('keyup', { key: 'Enter' });
expect(onSortCallBack.callCount).toBe(1);
});

it('should not trigger onSort callback when keyup key is not Enter on header cell', () => {
wrapper.find('th').simulate('keyup', { key: 'test-key' });
expect(onSortCallBack.callCount).toBe(0);
});

describe('and sorting prop is false', () => {
it('header should render SortSymbol as default', () => {
expect(wrapper.find(SortSymbol).length).toBe(1);
Expand Down