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

Conversation

AndrewMusgrave
Copy link
Member

WHY are these changes introduced?

Resolves #936

WHAT is this pull request doing?

Sets selectMode when selected items exists in state

How to 🎩

Run the example or create your own, the linked issue has more details on the issue 😄

Copy-paste this code in playground/Playground.tsx:
import React from 'react';
import {Avatar, Card, Label, List, ResourceList, Select, TextStyle} from '@shopify/polaris';
interface State {}

export default class ResourceListExample extends React.Component {
  state = {
    selectedItems: [],
  };

  componentDidMount() {
    this.setState({selectedItems: [256]})
  }

  handleSelectionChange = (selectedItems) => {
    this.setState({selectedItems});
  };

  renderItem = (item) => {
    const {id, url, name, location} = item;
    const media = <Avatar customer size="medium" name={name} />;

    return (
      <ResourceList.Item
        id={id}
        url={url}
        media={media}
        accessibilityLabel={`View details for ${name}`}
      >
        <h3>
          <TextStyle variation="strong">{name}</TextStyle>
        </h3>
        <div>{location}</div>
      </ResourceList.Item>
    );
  };

  render() {
    const resourceName = {
      singular: 'customer',
      plural: 'customers',
    };

    const items = [
      {
        id: 341,
        url: 'customers/341',
        name: 'Mae Jemison',
        location: 'Decatur, USA',
      },
      {
        id: 256,
        url: 'customers/256',
        name: 'Ellen Ochoa',
        location: 'Los Angeles, USA',
      },
    ];

    const promotedBulkActions = [
      {
        content: 'Edit customers',
        onAction: () => console.log('Todo: implement bulk edit'),
      },
    ];

    const bulkActions = [
      {
        content: 'Add tags',
        onAction: () => console.log('Todo: implement bulk add tags'),
      },
      {
        content: 'Remove tags',
        onAction: () => console.log('Todo: implement bulk remove tags'),
      },
      {
        content: 'Delete customers',
        onAction: () => console.log('Todo: implement bulk delete'),
      },
    ];

    return (
      <Card>
        <ResourceList
          resourceName={resourceName}
          items={items}
          renderItem={this.renderItem}
          selectedItems={this.state.selectedItems}
          onSelectionChange={this.handleSelectionChange}
          promotedBulkActions={promotedBulkActions}
          bulkActions={bulkActions}
        />
      </Card>
    );
  }
}

@BPScott BPScott temporarily deployed to polaris-react-pr-1224 March 19, 2019 17:17 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-1224 March 19, 2019 17:18 Inactive
Copy link
Contributor

@dleroux dleroux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎩 good. Can you add this bug fix to the change log?

@BPScott BPScott requested a deployment to polaris-react-pr-1224 March 20, 2019 23:20 Abandoned
@AndrewMusgrave AndrewMusgrave merged commit 0e7dc29 into master Mar 20, 2019
@AndrewMusgrave AndrewMusgrave deleted the rs-sm branch March 20, 2019 23:25
@chloerice chloerice temporarily deployed to production March 21, 2019 17:48 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants