add event hooks on column (#25)

fix #23
This commit is contained in:
Allen 2017-08-26 03:06:10 -05:00 committed by GitHub
parent 20bb9c0d1b
commit 95ca444edd
3 changed files with 35 additions and 3 deletions

View File

@ -10,12 +10,15 @@ const Cell = ({ row, rowIndex, column, columnIndex }) => {
formatExtraData,
style,
classes,
title
title,
events
} = column;
let content = _.get(row, dataField);
let cellTitle;
const attrs = {};
const attrs = {
...events
};
const cellStyle = _.isFunction(style) ? style(content, row, columnIndex) : style;
const cellClasses = _.isFunction(classes) ? classes(content, row, columnIndex) : classes;

View File

@ -28,7 +28,8 @@ HeaderCell.propTypes = {
classes: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
headerTitle: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
title: PropTypes.oneOfType([PropTypes.bool, PropTypes.func])
title: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
events: PropTypes.object
}).isRequired,
index: PropTypes.number.isRequired
};

View File

@ -210,4 +210,32 @@ describe('Cell', () => {
});
});
});
describe('when column.events prop is defined', () => {
let column;
const columnIndex = 1;
beforeEach(() => {
column = {
dataField: 'id',
text: 'ID',
events: {
onClick: sinon.stub()
}
};
wrapper = shallow(
<Cell row={ row } columnIndex={ columnIndex } rowIndex={ 1 } column={ column } />);
});
it('should attachs DOM event successfully', () => {
expect(wrapper.length).toBe(1);
expect(wrapper.find('td').prop('onClick')).toBeDefined();
});
it('event hook should be called when triggering', () => {
wrapper.find('td').simulate('click');
expect(column.events.onClick.callCount).toBe(1);
});
});
});