diff --git a/README.md b/README.md index 39f14b1..5098694 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Rebuilt [react-bootstrap-table](https://github.com/AllenFang/react-bootstrap-tab * [`react-bootstrap-table2-overlay`](https://www.npmjs.com/package/react-bootstrap-table2-overlay) * [`react-bootstrap-table2-toolkit`](https://www.npmjs.com/package/react-bootstrap-table2-toolkit) -This can help your application with less bundled size and also help us have clean design to avoid handling to much logic in kernal module(SRP). +This can help your application with less bundled size and also help us have clean design to avoid handling to much logic in kernel module(SRP). ## Migration If you are the user from legacy [`react-bootstrap-table`](https://github.com/AllenFang/react-bootstrap-table/), please have a look on [this](./docs/migration.md). @@ -40,4 +40,4 @@ $ yarn storybook $ Go to localhost:6006 ``` -**Storybook examples: [`packages/react-bootstrap-table2-example/examples`](https://github.com/react-bootstrap-table/react-bootstrap-table2/tree/master/packages/react-bootstrap-table2-example/examples)** \ No newline at end of file +**Storybook examples: [`packages/react-bootstrap-table2-example/examples`](https://github.com/react-bootstrap-table/react-bootstrap-table2/tree/master/packages/react-bootstrap-table2-example/examples)** diff --git a/docs/cell-edit.md b/docs/cell-edit.md index 8502c8c..6c46151 100644 --- a/docs/cell-edit.md +++ b/docs/cell-edit.md @@ -10,6 +10,7 @@ $ npm install react-bootstrap-table2-editor --save * [blurToSave](#blurToSave) * [nonEditableRows](#nonEditableRows) * [timeToCloseMessage](#timeToCloseMessage) +* [autoSelectText](#autoSelectText) * [beforeSaveCell](#beforeSaveCell) * [afterSaveCell](#afterSaveCell) * [errorMessage](#errorMessage) @@ -43,6 +44,11 @@ Default is `false`, enable it will be able to save the cell automatically when b ### cellEdit.nonEditableRows - [Function] `cellEdit.nonEditableRows` accept a callback function and expect return an array which used to restrict all the columns of some rows as non-editable. So the each item in return array should be rowkey(`keyField`) +### cellEdit.autoSelectText - [Bool] +Default is false, when enable it, `react-bootstrap-table2` will help you to select the text in the text input automatically when editing. + +> NOTE: This props only work for `text` and `textarea`. + ### cellEdit.timeToCloseMessage - [Function] If a [`column.validator`](./columns.md#validator) defined and the new value is invalid, `react-bootstrap-table2` will popup a alert at the bottom of editor. `cellEdit.timeToCloseMessage` is a chance to let you decide how long the alert should be stay. Default is 3000 millisecond. diff --git a/docs/row-expand.md b/docs/row-expand.md index 1aa958a..5f6b47a 100644 --- a/docs/row-expand.md +++ b/docs/row-expand.md @@ -13,6 +13,7 @@ * [onExpand](#onExpand) * [onExpandAll](#onExpandAll) * [showExpandColumn](#showExpandColumn) +* [onlyOneExpanding](#onlyOneExpanding) * [expandColumnRenderer](#expandColumnRenderer) * [expandHeaderColumnRenderer](#expandHeaderColumnRenderer) @@ -127,3 +128,13 @@ const expandRow = { showExpandColumn: true }; ``` + +### expandRow.onlyOneExpanding - [Bool] +Default is `false`. Enable this will only allow one row get expand at the same time. + +```js +const expandRow = { + renderer: (row) => ... + onlyOneExpanding: true +}; +``` diff --git a/docs/row-selection.md b/docs/row-selection.md index eb57e6b..9ed4e9f 100644 --- a/docs/row-selection.md +++ b/docs/row-selection.md @@ -16,6 +16,7 @@ * [onSelect](#onSelect) * [onSelectAll](#onSelectAll) * [hideSelectColumn](#hideSelectColumn) +* [hideSelectAll](#hideSelectAll) * [selectionRenderer](#selectionRenderer) * [selectionHeaderRenderer](#selectionHeaderRenderer) @@ -222,3 +223,13 @@ const selectRow = { bgColor: 'red' }; ``` + +### selectRow.hideSelectAll - [Bool] +Default is `false`, if you don't want to render the select all checkbox on the header of selection column, give this prop as `true`! + +```js +const selectRow = { + mode: 'checkbox', + hideSelectAll: true +}; +``` diff --git a/packages/react-bootstrap-table2-editor/src/editing-cell.js b/packages/react-bootstrap-table2-editor/src/editing-cell.js index 463c8c5..39aa9a5 100644 --- a/packages/react-bootstrap-table2-editor/src/editing-cell.js +++ b/packages/react-bootstrap-table2-editor/src/editing-cell.js @@ -24,6 +24,7 @@ export default (_, onStartEdit) => onUpdate: PropTypes.func.isRequired, onEscape: PropTypes.func.isRequired, timeToCloseMessage: PropTypes.number, + autoSelectText: PropTypes.bool, className: PropTypes.string, style: PropTypes.object } @@ -31,6 +32,7 @@ export default (_, onStartEdit) => static defaultProps = { timeToCloseMessage: TIME_TO_CLOSE_MESSAGE, className: null, + autoSelectText: false, style: {} } @@ -121,7 +123,7 @@ export default (_, onStartEdit) => render() { let editor; - const { row, column, className, style, rowIndex, columnIndex } = this.props; + const { row, column, className, style, rowIndex, columnIndex, autoSelectText } = this.props; const { dataField } = column; const value = _.get(row, dataField); @@ -174,13 +176,13 @@ export default (_, onStartEdit) => } else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.SELECT) { editor = ; } else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.TEXTAREA) { - editor = ; + editor = ; } else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.CHECKBOX) { editor = ; } else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.DATE) { editor = ; } else { - editor = ; + editor = ; } return ( diff --git a/packages/react-bootstrap-table2-editor/src/text-editor.js b/packages/react-bootstrap-table2-editor/src/text-editor.js index 1a28a29..aaee204 100644 --- a/packages/react-bootstrap-table2-editor/src/text-editor.js +++ b/packages/react-bootstrap-table2-editor/src/text-editor.js @@ -5,9 +5,10 @@ import PropTypes from 'prop-types'; class TextEditor extends Component { componentDidMount() { - const { defaultValue, didMount } = this.props; + const { defaultValue, didMount, autoSelectText } = this.props; this.text.value = defaultValue; this.text.focus(); + if (autoSelectText) this.text.select(); if (didMount) didMount(); } @@ -16,7 +17,7 @@ class TextEditor extends Component { } render() { - const { defaultValue, didMount, className, ...rest } = this.props; + const { defaultValue, didMount, className, autoSelectText, ...rest } = this.props; const editorClass = cs('form-control editor edit-text', className); return ( +`; + +export default () => ( +
+

Auto Select Text Input Field When Editing

+ + { sourceCode } +
+); diff --git a/packages/react-bootstrap-table2-example/examples/row-expand/expand-only-one.js b/packages/react-bootstrap-table2-example/examples/row-expand/expand-only-one.js new file mode 100644 index 0000000..4ef5bc4 --- /dev/null +++ b/packages/react-bootstrap-table2-example/examples/row-expand/expand-only-one.js @@ -0,0 +1,73 @@ +import React from 'react'; + +import BootstrapTable from 'react-bootstrap-table-next'; +import Code from 'components/common/code-block'; +import { productsExpandRowsGenerator } from 'utils/common'; + +const products = productsExpandRowsGenerator(); + +const columns = [{ + dataField: 'id', + text: 'Product ID' +}, { + dataField: 'name', + text: 'Product Name' +}, { + dataField: 'price', + text: 'Product Price' +}]; + +const expandRow = { + onlyOneExpanding: true, + renderer: row => ( +
+

{ `This Expand row is belong to rowKey ${row.id}` }

+

You can render anything here, also you can add additional data on every row object

+

expandRow.renderer callback will pass the origin row object to you

+
+ ) +}; + +const sourceCode = `\ +import BootstrapTable from 'react-bootstrap-table-next'; + +const columns = [{ + dataField: 'id', + text: 'Product ID' +}, { + dataField: 'name', + text: 'Product Name' +}, { + dataField: 'price', + text: 'Product Price' +}]; + +const expandRow = { + renderer: row => ( +
+

{ \`This Expand row is belong to rowKey $\{row.id}\` }

+

You can render anything here, also you can add additional data on every row object

+

expandRow.renderer callback will pass the origin row object to you

+
+ ) +}; + + +`; + +export default () => ( +
+ + { sourceCode } +
+); diff --git a/packages/react-bootstrap-table2-example/examples/row-selection/hide-select-all.js b/packages/react-bootstrap-table2-example/examples/row-selection/hide-select-all.js new file mode 100644 index 0000000..6f036b8 --- /dev/null +++ b/packages/react-bootstrap-table2-example/examples/row-selection/hide-select-all.js @@ -0,0 +1,59 @@ +import React from 'react'; + +import BootstrapTable from 'react-bootstrap-table-next'; +import Code from 'components/common/code-block'; +import { productsGenerator } from 'utils/common'; + +const products = productsGenerator(); + +const columns = [{ + dataField: 'id', + text: 'Product ID' +}, { + dataField: 'name', + text: 'Product Name' +}, { + dataField: 'price', + text: 'Product Price' +}]; + +const selectRow = { + mode: 'checkbox', + clickToSelect: true, + hideSelectAll: true +}; + +const sourceCode = `\ +import BootstrapTable from 'react-bootstrap-table-next'; + +const columns = [{ + dataField: 'id', + text: 'Product ID' +}, { + dataField: 'name', + text: 'Product Name' +}, { + dataField: 'price', + text: 'Product Price' +}]; + +const selectRow = { + mode: 'checkbox', + clickToSelect: true, + hideSelectAll: true +}; + + +`; + +export default () => ( +
+ + { sourceCode } +
+); diff --git a/packages/react-bootstrap-table2-example/examples/search/default-search.js b/packages/react-bootstrap-table2-example/examples/search/default-search.js new file mode 100644 index 0000000..dc38cbc --- /dev/null +++ b/packages/react-bootstrap-table2-example/examples/search/default-search.js @@ -0,0 +1,83 @@ +/* eslint react/prop-types: 0 */ +import React from 'react'; + +import BootstrapTable from 'react-bootstrap-table-next'; +import ToolkitProvider, { Search } from 'react-bootstrap-table2-toolkit'; +import Code from 'components/common/code-block'; +import { productsGenerator } from 'utils/common'; + +const { SearchBar } = Search; +const products = productsGenerator(); + +const columns = [{ + dataField: 'id', + text: 'Product ID' +}, { + dataField: 'name', + text: 'Product Name' +}, { + dataField: 'price', + text: 'Product Price' +}]; + +const sourceCode = `\ +import BootstrapTable from 'react-bootstrap-table-next'; +import ToolkitProvider, { Search } from 'react-bootstrap-table2-toolkit'; + +const { SearchBar } = Search; +const columns = [{ + dataField: 'id', + text: 'Product ID' +}, { + dataField: 'name', + text: 'Product Name' +}, { + dataField: 'price', + text: 'Product Price' +}]; + + + { + props => ( +
+

Input something at below input field:

+ +
+ +
+ ) + } +
+`; + +export default () => ( +
+ + { + props => ( +
+

Input something at below input field:

+ +
+ +
+ ) + } +
+ { sourceCode } +
+); diff --git a/packages/react-bootstrap-table2-example/stories/index.js b/packages/react-bootstrap-table2-example/stories/index.js index 0c652db..771655f 100644 --- a/packages/react-bootstrap-table2-example/stories/index.js +++ b/packages/react-bootstrap-table2-example/stories/index.js @@ -97,6 +97,7 @@ import CellEditHooks from 'examples/cell-edit/cell-edit-hooks-table'; import CellEditValidator from 'examples/cell-edit/cell-edit-validator-table'; import CellEditStyleTable from 'examples/cell-edit/cell-edit-style-table'; import CellEditClassTable from 'examples/cell-edit/cell-edit-class-table'; +import AutoSelectTextInput from 'examples/cell-edit/auto-select-text-input-table'; import EditorStyleTable from 'examples/cell-edit/editor-style-table'; import EditorClassTable from 'examples/cell-edit/editor-class-table'; import DropdownEditorTable from 'examples/cell-edit/dropdown-editor-table'; @@ -115,6 +116,7 @@ import ClickToSelectWithCellEditTable from 'examples/row-selection/click-to-sele import SelectionNoDataTable from 'examples/row-selection/selection-no-data'; import SelectionStyleTable from 'examples/row-selection/selection-style'; import SelectionClassTable from 'examples/row-selection/selection-class'; +import HideSelectAllTable from 'examples/row-selection/hide-select-all'; import CustomSelectionTable from 'examples/row-selection/custom-selection'; import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows'; import SelectionBgColorTable from 'examples/row-selection/selection-bgcolor'; @@ -126,6 +128,7 @@ import BasicRowExpand from 'examples/row-expand'; import RowExpandManagement from 'examples/row-expand/expand-management'; import NonExpandableRows from 'examples/row-expand/non-expandable-rows'; import ExpandColumn from 'examples/row-expand/expand-column'; +import ExpandOnlyOne from 'examples/row-expand/expand-only-one'; import CustomExpandColumn from 'examples/row-expand/custom-expand-column'; import ExpandHooks from 'examples/row-expand/expand-hooks'; @@ -136,6 +139,7 @@ import CustomPaginationTable from 'examples/pagination/custom-pagination'; // search import SearchTable from 'examples/search'; +import DefaultSearch from 'examples/search/default-search'; import DefaultCustomSearch from 'examples/search/default-custom-search'; import FullyCustomSearch from 'examples/search/fully-custom-search'; import SearchFormattedData from 'examples/search/search-formatted'; @@ -276,6 +280,7 @@ storiesOf('Cell Editing', module) .add('Cell Level Editable', () => ) .add('Rich Hook Functions', () => ) .add('Validation', () => ) + .add('Auto Select Text Input', () => ) .add('Custom Cell Style', () => ) .add('Custom Cell Classes', () => ) .add('Custom Editor Classes', () => ) @@ -297,6 +302,7 @@ storiesOf('Row Selection', module) .add('Selection without Data', () => ) .add('Selection Style', () => ) .add('Selection Class', () => ) + .add('Hide Select All', () => ) .add('Custom Selection', () => ) .add('Selection Background Color', () => ) .add('Not Selectabled Rows', () => ) @@ -309,6 +315,7 @@ storiesOf('Row Expand', module) .add('Expand Management', () => ) .add('Non Expandabled Rows', () => ) .add('Expand Indicator', () => ) + .add('Expand Only One Row at The Same Time', () => ) .add('Custom Expand Indicator', () => ) .add('Expand Hooks', () => ); @@ -321,6 +328,7 @@ storiesOf('Pagination', module) storiesOf('Table Search', module) .addDecorator(bootstrapStyle()) .add('Basic Search Table', () => ) + .add('Default Search Table', () => ) .add('Default Custom Search', () => ) .add('Fully Custom Search', () => ) .add('Search Fromatted Value', () => ) diff --git a/packages/react-bootstrap-table2-toolkit/README.md b/packages/react-bootstrap-table2-toolkit/README.md index 0886862..bfcce99 100644 --- a/packages/react-bootstrap-table2-toolkit/README.md +++ b/packages/react-bootstrap-table2-toolkit/README.md @@ -63,6 +63,22 @@ const { SearchBar } = Search; ### Search Options +#### defaultSearch - [string] +Accept a string that will be used for default searching when first time table render. + +```js + + // ... + +``` + #### searchFormatted - [bool] If you want to search on the formatted data, you are supposed to enable this props. `react-bootstrap-table2` will check if you define the `column.formatter` when doing search. diff --git a/packages/react-bootstrap-table2-toolkit/context.js b/packages/react-bootstrap-table2-toolkit/context.js index eba442e..0bf29b8 100644 --- a/packages/react-bootstrap-table2-toolkit/context.js +++ b/packages/react-bootstrap-table2-toolkit/context.js @@ -17,6 +17,7 @@ class ToolkitProvider extends statelessDrcorator(React.Component) { search: PropTypes.oneOfType([ PropTypes.bool, PropTypes.shape({ + defaultSearch: PropTypes.string, searchFormatted: PropTypes.bool }) ]), @@ -42,7 +43,7 @@ class ToolkitProvider extends statelessDrcorator(React.Component) { constructor(props) { super(props); this.state = { - searchText: '' + searchText: typeof props.search === 'object' ? (props.search.defaultSearch || '') : '' }; this._ = null; this.onSearch = this.onSearch.bind(this); @@ -85,6 +86,7 @@ class ToolkitProvider extends statelessDrcorator(React.Component) { return ( { FileSaver.saveAs( - new Blob(['\ufeff', content], { type: 'text/plain;charset=utf-8' }), + new Blob([content], { type: 'text/plain;charset=utf-8' }), fileName, noAutoBOM ); diff --git a/packages/react-bootstrap-table2-toolkit/src/search/SearchBar.js b/packages/react-bootstrap-table2-toolkit/src/search/SearchBar.js index 99ee8ee..2160c8a 100644 --- a/packages/react-bootstrap-table2-toolkit/src/search/SearchBar.js +++ b/packages/react-bootstrap-table2-toolkit/src/search/SearchBar.js @@ -47,6 +47,7 @@ const SearchBar = ({ style={ style } onKeyUp={ () => debounceCallback() } className={ `form-control ${className}` } + defaultValue={ searchText } placeholder={ placeholder || SearchBar.defaultProps.placeholder } { ...rest } /> diff --git a/packages/react-bootstrap-table2/src/bootstrap-table.js b/packages/react-bootstrap-table2/src/bootstrap-table.js index 50ec912..b0d4779 100644 --- a/packages/react-bootstrap-table2/src/bootstrap-table.js +++ b/packages/react-bootstrap-table2/src/bootstrap-table.js @@ -146,6 +146,7 @@ BootstrapTable.propTypes = { mode: PropTypes.oneOf([Const.ROW_SELECT_SINGLE, Const.ROW_SELECT_MULTIPLE]).isRequired, clickToSelect: PropTypes.bool, clickToEdit: PropTypes.bool, + hideSelectAll: PropTypes.bool, onSelect: PropTypes.func, onSelectAll: PropTypes.func, style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), @@ -165,6 +166,7 @@ BootstrapTable.propTypes = { onExpandAll: PropTypes.func, nonExpandable: PropTypes.array, showExpandColumn: PropTypes.bool, + onlyOneExpanding: PropTypes.bool, expandColumnRenderer: PropTypes.func, expandHeaderColumnRenderer: PropTypes.func }), diff --git a/packages/react-bootstrap-table2/src/contexts/row-expand-context.js b/packages/react-bootstrap-table2/src/contexts/row-expand-context.js index d6b1702..3e882c6 100644 --- a/packages/react-bootstrap-table2/src/contexts/row-expand-context.js +++ b/packages/react-bootstrap-table2/src/contexts/row-expand-context.js @@ -25,12 +25,13 @@ export default ( } handleRowExpand = (rowKey, expanded, rowIndex, e) => { - const { data, keyField, expandRow: { onExpand } } = this.props; + const { data, keyField, expandRow: { onExpand, onlyOneExpanding } } = this.props; let currExpanded = [...this.state.expanded]; if (expanded) { - currExpanded.push(rowKey); + if (onlyOneExpanding) currExpanded = [rowKey]; + else currExpanded.push(rowKey); } else { currExpanded = currExpanded.filter(value => value !== rowKey); } diff --git a/packages/react-bootstrap-table2/src/contexts/selection-context.js b/packages/react-bootstrap-table2/src/contexts/selection-context.js index 631ffe5..12a7af8 100644 --- a/packages/react-bootstrap-table2/src/contexts/selection-context.js +++ b/packages/react-bootstrap-table2/src/contexts/selection-context.js @@ -80,7 +80,15 @@ export default ( } if (onSelectAll) { - onSelectAll(!isUnSelect, dataOperator.getSelectedRows(data, keyField, currSelected), e); + onSelectAll( + !isUnSelect, + dataOperator.getSelectedRows( + data, + keyField, + isUnSelect ? this.state.selected : currSelected + ), + e + ); } this.setState(() => ({ selected: currSelected })); diff --git a/packages/react-bootstrap-table2/src/header-cell.js b/packages/react-bootstrap-table2/src/header-cell.js index 2053453..79b4b9b 100644 --- a/packages/react-bootstrap-table2/src/header-cell.js +++ b/packages/react-bootstrap-table2/src/header-cell.js @@ -49,6 +49,7 @@ const HeaderCell = (props) => { if (headerStyle) { cellStyle = _.isFunction(headerStyle) ? headerStyle(column, index) : headerStyle; + cellStyle = cellStyle ? { ...cellStyle } : cellStyle; } if (headerTitle) { diff --git a/packages/react-bootstrap-table2/src/row-event-delegater.js b/packages/react-bootstrap-table2/src/row-event-delegater.js index 283ffd6..ee62606 100644 --- a/packages/react-bootstrap-table2/src/row-event-delegater.js +++ b/packages/react-bootstrap-table2/src/row-event-delegater.js @@ -5,7 +5,8 @@ const events = [ 'onClick', 'onDoubleClick', 'onMouseEnter', - 'onMouseLeave' + 'onMouseLeave', + 'onContextMenu' ]; export default ExtendBase => diff --git a/packages/react-bootstrap-table2/src/row-selection/selection-header-cell.js b/packages/react-bootstrap-table2/src/row-selection/selection-header-cell.js index 3658e0a..8635bd5 100644 --- a/packages/react-bootstrap-table2/src/row-selection/selection-header-cell.js +++ b/packages/react-bootstrap-table2/src/row-selection/selection-header-cell.js @@ -27,6 +27,7 @@ export default class SelectionHeaderCell extends Component { mode: PropTypes.string.isRequired, checkedStatus: PropTypes.string, onAllRowsSelect: PropTypes.func, + hideSelectAll: PropTypes.bool, selectionHeaderRenderer: PropTypes.func } @@ -63,7 +64,10 @@ export default class SelectionHeaderCell extends Component { CHECKBOX_STATUS_CHECKED, CHECKBOX_STATUS_INDETERMINATE, ROW_SELECT_MULTIPLE } = Const; - const { mode, checkedStatus, selectionHeaderRenderer } = this.props; + const { mode, checkedStatus, selectionHeaderRenderer, hideSelectAll } = this.props; + if (hideSelectAll) { + return ; + } const checked = checkedStatus === CHECKBOX_STATUS_CHECKED; diff --git a/packages/react-bootstrap-table2/test/contexts/selection-context.test.js b/packages/react-bootstrap-table2/test/contexts/selection-context.test.js index 819fada..f53432e 100644 --- a/packages/react-bootstrap-table2/test/contexts/selection-context.test.js +++ b/packages/react-bootstrap-table2/test/contexts/selection-context.test.js @@ -220,6 +220,25 @@ describe('DataContext', () => { it('should set state.selected correctly', () => { expect(wrapper.state('selected')).toEqual(data.map(d => d[keyField])); }); + + describe('when selectRow.onSelectAll is defined', () => { + const onSelectAll = jest.fn(); + beforeEach(() => { + wrapper = shallow(shallowContext({ + ...defaultSelectRow, + onSelectAll + })); + wrapper.instance().handleAllRowsSelect(e, false); + }); + + it('should call selectRow.onSelectAll correctly', () => { + expect(onSelectAll).toHaveBeenCalledWith( + true, + dataOperator.getSelectedRows(data, keyField, wrapper.state('selected')), + e + ); + }); + }); }); describe('when isUnSelect argument is true', () => { @@ -234,24 +253,25 @@ describe('DataContext', () => { it('should set state.selected correctly', () => { expect(wrapper.state('selected')).toEqual([]); }); - }); - describe('when selectRow.onSelectAll is defined', () => { - const onSelectAll = jest.fn(); - beforeEach(() => { - wrapper = shallow(shallowContext({ - ...defaultSelectRow, - onSelectAll - })); - wrapper.instance().handleAllRowsSelect(e, false); - }); + describe('when selectRow.onSelectAll is defined', () => { + const onSelectAll = jest.fn(); + beforeEach(() => { + wrapper = shallow(shallowContext({ + ...defaultSelectRow, + selected: data.map(d => d[keyField]), + onSelectAll + })); + wrapper.instance().handleAllRowsSelect(e, true); + }); - it('should call selectRow.onSelectAll correctly', () => { - expect(onSelectAll).toHaveBeenCalledWith( - true, - dataOperator.getSelectedRows(data, keyField, wrapper.state('selected')), - e - ); + it('should call selectRow.onSelectAll correctly', () => { + expect(onSelectAll).toHaveBeenCalledWith( + false, + dataOperator.getSelectedRows(data, keyField, data.map(d => d[keyField])), + e + ); + }); }); }); }); diff --git a/packages/react-bootstrap-table2/test/row-selection/selection-header-cell.test.js b/packages/react-bootstrap-table2/test/row-selection/selection-header-cell.test.js index be9a519..da89009 100644 --- a/packages/react-bootstrap-table2/test/row-selection/selection-header-cell.test.js +++ b/packages/react-bootstrap-table2/test/row-selection/selection-header-cell.test.js @@ -104,6 +104,22 @@ describe('', () => { }); describe('render', () => { + describe('when props.hideSelectAll is true', () => { + beforeEach(() => { + const checkedStatus = Const.CHECKBOX_STATUS_CHECKED; + + wrapper = shallow( + + ); + }); + + it('should render empty th element', () => { + expect(wrapper.find('th').length).toBe(1); + expect(wrapper.find('th[data-row-selection]').length).toBe(1); + expect(wrapper.find(CheckBox).length).toBe(0); + }); + }); + describe('when props.mode is radio', () => { beforeEach(() => { const checkedStatus = Const.CHECKBOX_STATUS_CHECKED;