mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-28 13:10:03 +00:00
fix #29
This commit is contained in:
@@ -5,8 +5,16 @@ import _ from './utils';
|
||||
|
||||
|
||||
const HeaderCell = ({ column, index }) => {
|
||||
const { headerTitle, text, headerAlign, headerFormatter } = column;
|
||||
const attrs = {};
|
||||
const {
|
||||
text,
|
||||
headerTitle,
|
||||
headerAlign,
|
||||
headerFormatter,
|
||||
headerEvents
|
||||
} = column;
|
||||
const attrs = {
|
||||
...headerEvents
|
||||
};
|
||||
const headerStyle = {};
|
||||
const children = headerFormatter ? headerFormatter(column, index) : text;
|
||||
|
||||
@@ -39,6 +47,7 @@ HeaderCell.propTypes = {
|
||||
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
||||
headerTitle: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
|
||||
title: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
|
||||
headerEvents: PropTypes.object,
|
||||
events: PropTypes.object,
|
||||
headerAlign: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||
align: PropTypes.oneOfType([PropTypes.string, PropTypes.func])
|
||||
|
||||
@@ -147,4 +147,30 @@ describe('HeaderCell', () => {
|
||||
expect(formatter.calledWith(column, index)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when column.headerEvents prop is defined', () => {
|
||||
let column;
|
||||
|
||||
beforeEach(() => {
|
||||
column = {
|
||||
dataField: 'id',
|
||||
text: 'ID',
|
||||
headerEvents: {
|
||||
onClick: sinon.stub()
|
||||
}
|
||||
};
|
||||
|
||||
wrapper = shallow(<HeaderCell column={ column } index={ index } />);
|
||||
});
|
||||
|
||||
it('should attachs DOM event successfully', () => {
|
||||
expect(wrapper.length).toBe(1);
|
||||
expect(wrapper.find('th').prop('onClick')).toBeDefined();
|
||||
});
|
||||
|
||||
it('event hook should be called when triggering', () => {
|
||||
wrapper.find('th').simulate('click');
|
||||
expect(column.headerEvents.onClick.callCount).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user