Skip to content

Conversation

tauthomas01
Copy link
Contributor

@tauthomas01 tauthomas01 commented Feb 9, 2024

WHY are these changes introduced?

Fixes https://github.com/Shopify/polaris-internal/issues/1360

The goal of this PR is to add a new disabled prop in the ResourceItem component. We want to have a disabled state in this component because one of our page is displaying it as a list of items and when we click on a ResourceItem, it's loading the same template along with the same list of ResourceItem. In that case, if we have a disabled state on the current item, it would be great to prevent users from clicking on it again because it would load the same page.

WHAT is this pull request doing?

When disabled prop is true in the ResourceItem:

  • We hide the UnstyledLink/button as well as its accessibility attributes as it's no longer an interactive element. This should read as a regular text.
  • The onClick should not be triggered when we hit onKeyUp or click on the disabled element
  • The cursor style is now default + font color follows the disabled state like IndexTable.Row
  • The hover state is removed
  • onClick or url prop won't be triggered as long as disabled: true
  • The checkbox selectable state is true

Here is a Playground code snippet below to test. In the example, I've added checkboxes in the ResourceList to make sure it still works as expected.

Code snippet for playground
import React, {useState} from 'react';
import type {ResourceListProps} from '@shopify/polaris';

import {
  Page,
  LegacyCard,
  ResourceList,
  ResourceItem,
  Text,
  Avatar,
} from '../src';

export function Playground() {
  const [selectedItems, setSelectedItems] = useState<
    ResourceListProps['selectedItems']
  >([]);

  return (
    <Page title="Playground">
      <LegacyCard>
        <ResourceList
          resourceName={{singular: 'customer', plural: 'customers'}}
          selectable
          selectedItems={selectedItems}
          onSelectionChange={setSelectedItems}
          items={[
            {
              id: '145',
              url: '#',
              avatarSource:
                'https://burst.shopifycdn.com/photos/freelance-designer-working-on-laptop.jpg?width=746',
              name: 'Yi So-Yeon',
              location: 'Gwangju, South Korea',
            },
            {
              id: '146',
              url: '#',
              avatarSource:
                'https://burst.shopifycdn.com/photos/woman-standing-in-front-of-yellow-background.jpg?width=746',
              name: 'Jane Smith',
              location: 'Manhattan, New York',
            },
            {
              id: '147',
              url: '#',
              avatarSource:
                'https://burst.shopifycdn.com/photos/relaxing-in-headphones.jpg?width=746',
              name: 'Grace Baker',
              location: 'Los Angeles, California',
            },
          ]}
          renderItem={(item) => {
            const {id, url, avatarSource, name, location} = item;

            return (
              <ResourceItem
                disabled={id === '145'}
                id={id}
                url={url}
                media={
                  <Avatar
                    customer
                    size="md"
                    name={name}
                    source={avatarSource}
                  />
                }
                accessibilityLabel={`View details for ${name}`}
                name={name}
                onClick={() => console.log('clicked')}
              >
                <h3>
                  <Text fontWeight="bold" as="span">
                    {name}
                  </Text>
                </h3>
                <div>{location}</div>
              </ResourceItem>
            );
          }}
        />
      </LegacyCard>
    </Page>
  );
}
Screen.Recording.2024-02-13.at.2.58.34.PM.mov

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

🎩 checklist

@tauthomas01 tauthomas01 marked this pull request as ready for review February 9, 2024 21:47
Copy link
Member

@chloerice chloerice left a comment

Choose a reason for hiding this comment

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

Hey @tauthomas01 👋🏽 The active state for ResourceItem is its selected state. The interaction here is a disabled state, so let's also make sure to disable the checkbox when selectable is true. The font color should also indicate that it's disabled like the IndexTable.Row does cc @Shopify/polaris-ux

@tauthomas01 tauthomas01 changed the title [ResourceItem] Add active prop [ResourceItem] Add disabled prop Feb 13, 2024
@tauthomas01
Copy link
Contributor Author

Hi @chloerice , thank you for the review! I made the changes based on your comments and updated the PR description to reflect the new prop name.

Copy link
Member

@chloerice chloerice left a comment

Choose a reason for hiding this comment

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

Thank you for contributing @tauthomas01! 🎉 Can you add the Playground code you wrote as a story for this state?

@chloerice chloerice added Component Contribution Tracking contribution in conjuction with year and type, e.g., "Component" + "Contribution" + "2023" 2024 Community contribution tracking for year 2024 labels Feb 14, 2024
@tauthomas01
Copy link
Contributor Author

/snapit

Copy link
Contributor

🫰✨ Thanks @tauthomas01! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

yarn add @shopify/polaris-migrator@0.0.0-snapshot-release-20240214135159
yarn add @shopify/polaris@0.0.0-snapshot-release-20240214135159
yarn add @shopify/polaris-tokens@0.0.0-snapshot-release-20240214135159
yarn add @shopify/stylelint-polaris@0.0.0-snapshot-release-20240214135159

@tauthomas01 tauthomas01 merged commit 1ba3181 into main Feb 14, 2024
@tauthomas01 tauthomas01 deleted the tauthomas01/1360-add-active-prop-resource-item branch February 14, 2024 15:10
sam-b-rose pushed a commit that referenced this pull request Feb 15, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @shopify/polaris-icons@8.3.0

### Minor Changes

- [#11526](#11526)
[`b65f1e679`](b65f1e6)
Thanks [@j-wanita](https://github.com/j-wanita)! - Add list icons for
product, collection, metaobject and text


- [#11531](#11531)
[`78ed5fe0d`](78ed5fe)
Thanks [@j-wanita](https://github.com/j-wanita)! - Updated metaobject,
metaobject reference, and metaobject filled icons

## @shopify/polaris-migrator@0.28.0

### Minor Changes

- [#11596](#11596)
[`c8fabc011`](c8fabc0)
Thanks [@lgriffee](https://github.com/lgriffee)! - Created migration to
replace deprecated `font` custom properties in polaris-react v13.0.0

### Patch Changes

- [#11603](#11603)
[`2c53d6476`](2c53d64)
Thanks [@lgriffee](https://github.com/lgriffee)! - Updated migration to
replace deprecated `font` custom properties in polaris-react v13.0.0

## @shopify/polaris@12.16.0

### Minor Changes

- [#11585](#11585)
[`1ba3181b6`](1ba3181)
Thanks [@tauthomas01](https://github.com/tauthomas01)! - Added a
`disabled` prop to `ResourceItem`


- [#11568](#11568)
[`525194767`](5251947)
Thanks [@mrcthms](https://github.com/mrcthms)! - Updated the stacking
logic of multiple Toasts to take up less screen real estate


- [#11587](#11587)
[`5ab254b3b`](5ab254b)
Thanks [@sainihas](https://github.com/sainihas)! - Update dropzone
container background color when no Outline

### Patch Changes

- [#11581](#11581)
[`47dac1b2e`](47dac1b)
Thanks [@kyledurand](https://github.com/kyledurand)! - Fixed an issue
where scrollbars weren't showing up in IndexTable on mac os when show
when scrolling preference is selected


- [#11560](#11560)
[`0b38b6115`](0b38b61)
Thanks [@apliano](https://github.com/apliano)! - Fixed `Combobox` not
rendering `Popover` until the second firing of the `onChange` event


- [#11584](#11584)
[`23d8297ff`](23d8297)
Thanks [@mrcthms](https://github.com/mrcthms)! - Updated
`useIsSelectAllActionsSticky` logic to not set any sticky behaviour if
we do not have access to the root element


- [#11543](#11543)
[`165bc6eae`](165bc6e)
Thanks [@mrcthms](https://github.com/mrcthms)! - Fixed `IndexFilters`
height changing when toggling between default and filtering modes


- [#11563](#11563)
[`3937739d2`](3937739)
Thanks [@chloerice](https://github.com/chloerice)! - Fixed
`FormLayout.Item` overflowing viewport at xs breakpoint when user
settings enlarge text size


- [#11595](#11595)
[`f829ed487`](f829ed4)
Thanks [@oksanashopify](https://github.com/oksanashopify)! - Updated
DropZone minimum size from 50px to 40px to fit within a small Thumbnail

- Updated dependencies
\[[`b65f1e679`](b65f1e6),
[`78ed5fe0d`](78ed5fe)]:
    -   @shopify/polaris-icons@8.3.0

## polaris.shopify.com@0.63.0

### Minor Changes

- [#11596](#11596)
[`c8fabc011`](c8fabc0)
Thanks [@lgriffee](https://github.com/lgriffee)! - Created migration to
replace deprecated `font` custom properties in polaris-react v13.0.0


- [#11568](#11568)
[`525194767`](5251947)
Thanks [@mrcthms](https://github.com/mrcthms)! - Updated the stacking
logic of multiple Toasts to take up less screen real estate

### Patch Changes

- Updated dependencies
\[[`b65f1e679`](b65f1e6),
[`47dac1b2e`](47dac1b),
[`0b38b6115`](0b38b61),
[`23d8297ff`](23d8297),
[`1ba3181b6`](1ba3181),
[`165bc6eae`](165bc6e),
[`78ed5fe0d`](78ed5fe),
[`3937739d2`](3937739),
[`f829ed487`](f829ed4),
[`525194767`](5251947),
[`5ab254b3b`](5ab254b)]:
    -   @shopify/polaris-icons@8.3.0
    -   @shopify/polaris@12.16.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
AnnaCheba pushed a commit to AnnaCheba/polaris that referenced this pull request Apr 22, 2024
<!--
  ☝️How to write a good PR title:
- Prefix it with [ComponentName] (if applicable), for example: [Button]
  - Start with a verb, for example: Add, Delete, Improve, Fix…
  - Give as much context as necessary and as little as possible
  - Open it as a draft if it’s a work in progress
-->

### WHY are these changes introduced?

Fixes Shopify/polaris-internal#1360

The goal of this PR is to add a new `disabled` prop in the
`ResourceItem` component. We want to have a disabled state in this
component because one of our page is displaying it as a list of items
and when we click on a `ResourceItem`, it's loading the same template
along with the same list of `ResourceItem`. In that case, if we have a
disabled state on the current item, it would be great to prevent users
from clicking on it again because it would load the same page.

### WHAT is this pull request doing?

When `disabled` prop is `true` in the `ResourceItem`:
- We hide the `UnstyledLink`/button as well as its accessibility
attributes as it's no longer an interactive element. This should read as
a regular text.
- The `onClick` should not be triggered when we hit `onKeyUp` or `click`
on the disabled element
- The `cursor` style is now `default` + font color follows the
`disabled` state [like
IndexTable.Row](https://github.com/Shopify/polaris/blob/9019cab93e6f0f04cbe1901ceaa22921a5612791/polaris-react/src/components/IndexTable/IndexTable.module.scss#L695)
- The hover state is removed
- `onClick` or `url` prop won't be triggered as long as `disabled: true`
- The checkbox `selectable` state is true

Here is a Playground code snippet below to test. In the example, I've
added checkboxes in the `ResourceList` to make sure it still works as
expected.

<details>

<summary>Code snippet for playground</summary>

```js
import React, {useState} from 'react';
import type {ResourceListProps} from '@shopify/polaris';

import {
  Page,
  LegacyCard,
  ResourceList,
  ResourceItem,
  Text,
  Avatar,
} from '../src';

export function Playground() {
  const [selectedItems, setSelectedItems] = useState<
    ResourceListProps['selectedItems']
  >([]);

  return (
    <Page title="Playground">
      <LegacyCard>
        <ResourceList
          resourceName={{singular: 'customer', plural: 'customers'}}
          selectable
          selectedItems={selectedItems}
          onSelectionChange={setSelectedItems}
          items={[
            {
              id: '145',
              url: '#',
              avatarSource:
                'https://burst.shopifycdn.com/photos/freelance-designer-working-on-laptop.jpg?width=746',
              name: 'Yi So-Yeon',
              location: 'Gwangju, South Korea',
            },
            {
              id: '146',
              url: '#',
              avatarSource:
                'https://burst.shopifycdn.com/photos/woman-standing-in-front-of-yellow-background.jpg?width=746',
              name: 'Jane Smith',
              location: 'Manhattan, New York',
            },
            {
              id: '147',
              url: '#',
              avatarSource:
                'https://burst.shopifycdn.com/photos/relaxing-in-headphones.jpg?width=746',
              name: 'Grace Baker',
              location: 'Los Angeles, California',
            },
          ]}
          renderItem={(item) => {
            const {id, url, avatarSource, name, location} = item;

            return (
              <ResourceItem
                disabled={id === '145'}
                id={id}
                url={url}
                media={
                  <Avatar
                    customer
                    size="md"
                    name={name}
                    source={avatarSource}
                  />
                }
                accessibilityLabel={`View details for ${name}`}
                name={name}
                onClick={() => console.log('clicked')}
              >
                <h3>
                  <Text fontWeight="bold" as="span">
                    {name}
                  </Text>
                </h3>
                <div>{location}</div>
              </ResourceItem>
            );
          }}
        />
      </LegacyCard>
    </Page>
  );
}
```
</details>



https://github.com/Shopify/polaris/assets/658169/72207888-a7dd-48f8-acf7-2c1f11068d1d


### How to 🎩

🖥 [Local development
instructions](https://github.com/Shopify/polaris/blob/main/README.md#install-dependencies-and-build-workspaces)
🗒 [General tophatting
guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md)
📄 [Changelog
guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog)

### 🎩 checklist

- [x] Tested a
[snapshot](https://github.com/Shopify/polaris/blob/main/documentation/Releasing.md#-snapshot-releases)
- [x] Tested on
[mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing)
- [x] Tested on [multiple
browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers)
- [x] Tested for
[accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md)
- [x] Updated the component's `README.md` with documentation changes
- [x] [Tophatted
documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md)
changes in the style guide
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2024 Community contribution tracking for year 2024 Component Contribution Tracking contribution in conjuction with year and type, e.g., "Component" + "Contribution" + "2023"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants