diff --git a/CHANGELOG.md b/CHANGELOG.md index b928df7c64e..745db6fc65d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## [`master`](https://github.com/elastic/eui/tree/master) +- Added `allowNeutralSort` prop to `EuiInMemoryTable` to support unsorting table columns ([#1591](https://github.com/elastic/eui/pull/1591)) - Added `mobileOptions` object prop for handling of all the mobile specific options of `EuiBasicTable` ([#1462](https://github.com/elastic/eui/pull/1462)) - Table headers now accept `React.node` types ([#1462](https://github.com/elastic/eui/pull/1462)) - Added `displayOnly` prop to `EuiFormRow` ([#1582](https://github.com/elastic/eui/pull/1582)) diff --git a/src-docs/src/views/tables/basic/props_info.js b/src-docs/src/views/tables/basic/props_info.js index c082cf28a72..0c2c62d121d 100644 --- a/src-docs/src/views/tables/basic/props_info.js +++ b/src-docs/src/views/tables/basic/props_info.js @@ -136,6 +136,11 @@ export const propsInfo = { description: 'Indicates the property/field to sort on', required: false, type: { name: '{ field: string, direction: "asc" | "desc" }' } + }, + allowNeutralSort: { + description: 'Enables/disables unsorting of table columns. Supported by EuiInMemoryTable.', + required: false, + type: { name: 'bool' } } } } diff --git a/src-docs/src/views/tables/in_memory/props_info.js b/src-docs/src/views/tables/in_memory/props_info.js index 66ce40a2868..3de82a5df7f 100644 --- a/src-docs/src/views/tables/in_memory/props_info.js +++ b/src-docs/src/views/tables/in_memory/props_info.js @@ -43,6 +43,11 @@ export const propsInfo = { required: false, type: { name: 'boolean | #Sorting' } }, + allowNeutralSort: { + description: 'Enables/disables unsorting of table columns. Defaults to true.', + required: false, + type: { name: 'boolean' } + }, search: { description: 'Configures a search bar for the table', required: false, diff --git a/src/components/basic_table/__snapshots__/in_memory_table.test.js.snap b/src/components/basic_table/__snapshots__/in_memory_table.test.js.snap index 46e0bf0c601..79478d15092 100644 --- a/src/components/basic_table/__snapshots__/in_memory_table.test.js.snap +++ b/src/components/basic_table/__snapshots__/in_memory_table.test.js.snap @@ -792,6 +792,7 @@ exports[`EuiInMemoryTable with initial sorting 1`] = ` responsive={true} sorting={ Object { + "allowNeutralSort": true, "sort": Object { "direction": "desc", "field": "name", @@ -1265,6 +1266,7 @@ exports[`EuiInMemoryTable with pagination, selection and sorting 1`] = ` } sorting={ Object { + "allowNeutralSort": true, "sort": undefined, } } @@ -1345,6 +1347,7 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and simple search } sorting={ Object { + "allowNeutralSort": true, "sort": undefined, } } @@ -1419,6 +1422,7 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and a single recor } sorting={ Object { + "allowNeutralSort": true, "sort": undefined, } } @@ -1477,6 +1481,7 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and column rendere } sorting={ Object { + "allowNeutralSort": true, "sort": undefined, } } @@ -1569,6 +1574,7 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and configured sea } sorting={ Object { + "allowNeutralSort": true, "sort": undefined, } } @@ -1612,6 +1618,7 @@ exports[`EuiInMemoryTable with sorting 1`] = ` responsive={true} sorting={ Object { + "allowNeutralSort": true, "sort": undefined, } } diff --git a/src/components/basic_table/basic_table.js b/src/components/basic_table/basic_table.js index 4ebf3f8e432..9a1f836593c 100644 --- a/src/components/basic_table/basic_table.js +++ b/src/components/basic_table/basic_table.js @@ -140,7 +140,8 @@ export const SelectionType = PropTypes.shape({ }); const SortingType = PropTypes.shape({ - sort: PropertySortType + sort: PropertySortType, + allowNeutralSort: PropTypes.bool, }); const BasicTablePropTypes = { @@ -550,6 +551,7 @@ export class EuiBasicTable extends Component { sorting.isSorted = !!sortDirection; sorting.isSortAscending = sortDirection ? SortDirection.isAsc(sortDirection) : undefined; sorting.onSort = this.resolveColumnOnSort(column); + sorting.allowNeutralSort = this.props.sorting.allowNeutralSort; } headers.push( )} - {`Click to sort in ${(ariaSortValue === 'descending' || 'none') ? 'ascending' : 'descending'} order`} + {getScreenCasterDirection()} @@ -111,6 +122,11 @@ EuiTableHeaderCell.propTypes = { onSort: PropTypes.func, isSorted: PropTypes.bool, isSortAscending: PropTypes.bool, + /** + * Set `allowNeutralSort` on EuiInMemoryTable to false to force column sorting. + * EuiBasicTable always forces column sorting. + */ + allowNeutralSort: PropTypes.bool, scope: PropTypes.oneOf(['col', 'row', 'colgroup', 'rowgroup']), /** * _DEPRECATED: use `mobileOptions.only = true`_