Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4da199f

Browse files
fix #29
1 parent b00007c commit 4da199f

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@ import _ from './utils';
55

66

77
const HeaderCell = ({ column, index }) => {
8-
const { headerTitle, text, headerAlign, headerFormatter } = column;
9-
const attrs = {};
8+
const {
9+
text,
10+
headerTitle,
11+
headerAlign,
12+
headerFormatter,
13+
headerEvents
14+
} = column;
15+
const attrs = {
16+
...headerEvents
17+
};
1018
const headerStyle = {};
1119
const children = headerFormatter ? headerFormatter(column, index) : text;
1220

@@ -39,6 +47,7 @@ HeaderCell.propTypes = {
3947
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
4048
headerTitle: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
4149
title: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
50+
headerEvents: PropTypes.object,
4251
events: PropTypes.object,
4352
headerAlign: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
4453
align: PropTypes.oneOfType([PropTypes.string, PropTypes.func])

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,30 @@ describe('HeaderCell', () => {
147147
expect(formatter.calledWith(column, index)).toBe(true);
148148
});
149149
});
150+
151+
describe('when column.headerEvents prop is defined', () => {
152+
let column;
153+
154+
beforeEach(() => {
155+
column = {
156+
dataField: 'id',
157+
text: 'ID',
158+
headerEvents: {
159+
onClick: sinon.stub()
160+
}
161+
};
162+
163+
wrapper = shallow(<HeaderCell column={ column } index={ index } />);
164+
});
165+
166+
it('should attachs DOM event successfully', () => {
167+
expect(wrapper.length).toBe(1);
168+
expect(wrapper.find('th').prop('onClick')).toBeDefined();
169+
});
170+
171+
it('event hook should be called when triggering', () => {
172+
wrapper.find('th').simulate('click');
173+
expect(column.headerEvents.onClick.callCount).toBe(1);
174+
});
175+
});
150176
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /