From 4da199f4fc262add2746b476f8a89d9707a757af Mon Sep 17 00:00:00 2001 From: Allen Date: Sat, 26 Aug 2017 04:55:00 -0500 Subject: [PATCH] fix #29 --- .../react-bootstrap-table2/src/header-cell.js | 13 ++++++++-- .../test/header-cell.test.js | 26 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/packages/react-bootstrap-table2/src/header-cell.js b/packages/react-bootstrap-table2/src/header-cell.js index 40a9276..3f1e7b8 100644 --- a/packages/react-bootstrap-table2/src/header-cell.js +++ b/packages/react-bootstrap-table2/src/header-cell.js @@ -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]) diff --git a/packages/react-bootstrap-table2/test/header-cell.test.js b/packages/react-bootstrap-table2/test/header-cell.test.js index 78f826a..76a2962 100644 --- a/packages/react-bootstrap-table2/test/header-cell.test.js +++ b/packages/react-bootstrap-table2/test/header-cell.test.js @@ -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(); + }); + + 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); + }); + }); });