mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
parent
20bb9c0d1b
commit
95ca444edd
7
packages/react-bootstrap-table2/src/cell.js
vendored
7
packages/react-bootstrap-table2/src/cell.js
vendored
@ -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;
|
||||
|
||||
|
||||
@ -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
|
||||
};
|
||||
|
||||
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user