Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added a split variant to `Button` ([#2329](https://github.com/Shopify/polaris-react/pull/2329))
- Allow DataTable headers to be React Elements ([#2635](https://github.com/Shopify/polaris-react/pull/2635))
- Added support for explicit order of items in `ActionMenu` ([2057](https://github.com/Shopify/polaris-react/pull/2057))
- Made the `DataTable` horizontal `Navigation` optional ([#2647](https://github.com/Shopify/polaris-react/pull/2647))

### Bug fixes

Expand Down
25 changes: 17 additions & 8 deletions src/components/DataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ export interface DataTableProps {
showTotalsInFooter?: boolean;
/** Lists of data points which map to table body rows. */
rows: TableData[][];
/** Truncate content in first column instead of wrapping.
/** Hide column visibility and navigation buttons above the header when the table horizontally collapses to be scrollable.
* @default false
*/
hideScrollIndicator?: boolean;
/** Truncate content in first column instead of wrapping.
* @default true
*/
truncate?: boolean;
/** Vertical alignment of content in the cells.
* @default 'top'
Expand Down Expand Up @@ -131,6 +135,7 @@ class DataTableInner extends React.PureComponent<
showTotalsInFooter,
rows,
footerContent,
hideScrollIndicator = false,
} = this.props;
const {
condensed,
Expand Down Expand Up @@ -166,15 +171,19 @@ class DataTableInner extends React.PureComponent<
<tfoot>{totalsMarkup}</tfoot>
) : null;

const navigationMarkup = hideScrollIndicator ? null : (
<Navigation
columnVisibilityData={columnVisibilityData}
isScrolledFarthestLeft={isScrolledFarthestLeft}
isScrolledFarthestRight={isScrolledFarthestRight}
navigateTableLeft={this.navigateTable('left')}
navigateTableRight={this.navigateTable('right')}
/>
);

return (
<div className={wrapperClassName}>
<Navigation
columnVisibilityData={columnVisibilityData}
isScrolledFarthestLeft={isScrolledFarthestLeft}
isScrolledFarthestRight={isScrolledFarthestRight}
navigateTableLeft={this.navigateTable('left')}
navigateTableRight={this.navigateTable('right')}
/>
{navigationMarkup}
<div className={className} ref={this.dataTable}>
<div className={styles.ScrollContainer} ref={this.scrollContainer}>
<EventListener event="resize" handler={this.handleResize} />
Expand Down
26 changes: 25 additions & 1 deletion src/components/DataTable/tests/DataTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
// eslint-disable-next-line no-restricted-imports
import {mountWithAppProvider, trigger} from 'test-utilities/legacy';
import {Checkbox} from 'components';
import {Cell} from '../components';
import {Cell, Navigation} from '../components';
import {DataTable, DataTableProps} from '../DataTable';

describe('<DataTable />', () => {
Expand Down Expand Up @@ -223,6 +223,30 @@ describe('<DataTable />', () => {
});
});

describe('hideScrollIndicator', () => {
it('shows <Navigation /> by default', () => {
const dataTable = mountWithAppProvider(<DataTable {...defaultProps} />);

expect(dataTable.find(Navigation)).toHaveLength(1);
});

it('hide <Navigation /> when true', () => {
const dataTable = mountWithAppProvider(
<DataTable {...defaultProps} hideScrollIndicator />,
);

expect(dataTable.find(Navigation)).toHaveLength(0);
});

it('show <Navigation /> when false', () => {
const dataTable = mountWithAppProvider(
<DataTable {...defaultProps} hideScrollIndicator={false} />,
);

expect(dataTable.find(Navigation)).toHaveLength(1);
});
});

describe('verticalAlign', () => {
it('defaults to undefined', () => {
const dataTable = mountWithAppProvider(<DataTable {...defaultProps} />);
Expand Down