Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ResourceList] Fix selectMode when programmatically setting selectedItems #1224

Merged
merged 2 commits into from
Mar 20, 2019
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 @@ -20,6 +20,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f

### Bug fixes

- Fixed selectMode on `ResourceList` not toggling when items are selected programmatically ([#1224](https://github.com/Shopify/polaris-react/pull/1224))
- Fixed unnecessary height on `TextField` due to unhandled carriage returns ([#901](https://github.com/Shopify/polaris-react/pull/901))
- Ensured server side rendering matches client side rendering for [embedded app components](https://github.com/Shopify/polaris-react/blob/master/documentation/Embedded%20apps.md#components-which-wrap-shopify-app-bridge) ([#976](https://github.com/Shopify/polaris-react/pull/976))
- Fixed rendering of the spinner on `TextField` when setting to readOnly ([#1118](https://github.com/Shopify/polaris-react/pull/1199))
Expand Down
9 changes: 9 additions & 0 deletions src/components/ResourceList/ResourceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ export class ResourceList extends React.Component<CombinedProps, State> {
componentWillReceiveProps(nextProps: Props) {
const {selectedItems} = this.props;

if (
nextProps.selectedItems &&
nextProps.selectedItems.length > 0 &&
!this.state.selectMode
) {
this.setState({selectMode: true});
return;
}

if (
selectedItems &&
selectedItems.length > 0 &&
Expand Down
15 changes: 15 additions & 0 deletions src/components/ResourceList/tests/ResourceList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,21 @@ describe('<ResourceList />', () => {
);
expect(resourceList.find(BulkActions)).toHaveLength(1);
});

it('enables select mode when items are programmatically selected', () => {
const resourceList = mountWithAppProvider(
<ResourceList
items={singleItemWithID}
renderItem={renderItem}
bulkActions={bulkActions}
selectedItems={[]}
/>,
);

expect(resourceList.find(BulkActions).prop('selectMode')).toBe(false);
resourceList.setProps({selectedItems: ['1']});
expect(resourceList.find(BulkActions).prop('selectMode')).toBe(true);
});
});
});

Expand Down