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

[IndexTable] Allow row click when onClick is passed in on non-selectable tables #11763

Merged
merged 3 commits into from
Mar 20, 2024

Conversation

sydturn
Copy link
Contributor

@sydturn sydturn commented Mar 19, 2024

WHY are these changes introduced?

Resolves #11518 and Relates to https://github.com/Shopify/credit/issues/1252 which needs to use clickable IndexTables but without checkboxes.

Here is the Figma I'm working off of. Currently these tables exist in Shopify Balance and Credit already but they're using our own custom css/html alongside ResourceList and it's
a) hard to manage (the columns don't have the context of the other columns and don't automatically adjust so we have to hardcode the column widths which is a pain whenever we need to add a new column
b) doesn't conform to Polaris aesthetics
So we're trying to migrate to using IndexTables to make maintenance on these tables easier, the transition to the new Figma easier, and the aesthetics of the tables look more like Polaris.
I have it mostly implemented but the only thing is that the rows need to be clickable without the checkboxes.

There are no aesthetic changes in this PR for including a screenshot.

WHAT is this pull request doing?

This pull requests makes it so that if an onClick event is provided to a IndexTable.Row that is in an IndexTable that has selectable={false} the onClick will still be called. Rows being selectable vs. clickable should not be mutually exclusive.

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

☝️ TLDR;

  1. git clone https://github.com/Shopify/polaris.git
  2. yarn install && cd polaris-react
  3. dev up && dev server

I have provided a code snippet that you can put in your playground for testing. Where in main clicking a row would do nothing, with the changes in this PR clicking on a row will log to the console.

    <Page title="Playground">
      <IndexTable
        itemCount={2}
        selectable={false}
        headings={[{title: 'date'}, {title: 'description'}, {title: 'amount'}]}
      >
        <IndexTable.Row onClick={handleOnClick} position={1} id="1">
          <IndexTable.Cell>Today</IndexTable.Cell>
          <IndexTable.Cell>Dollarama</IndexTable.Cell>
          <IndexTable.Cell>$30</IndexTable.Cell>
        </IndexTable.Row>
      </IndexTable>
    </Page>

You can also test it on this spin instance (the transaction table shown utilizes non-selectable but yes clickable)

🎩 checklist

I'm not so sure this needs to be added to the changeset, documentation, or readme, as it is just implementing a fix for something that should already exist but doesn't? I'm not sure. This isn't a new feature, it's just a fix for an existing one that rarely gets used I guess?

@sydturn sydturn force-pushed the handle-index-row-click branch 2 times, most recently from 0ff4e76 to 1ebd94c Compare March 19, 2024 16:30
@etlgfx
Copy link

etlgfx commented Mar 19, 2024

Oh I fixed this too here: #11652 but feel free to ship this if you have time to dedicate to it.

I took a slightly different approach, but also found a user created issue that I linked in my description.
(I'm not on Polaris team)

@sydturn
Copy link
Contributor Author

sydturn commented Mar 19, 2024

Oh I fixed this too here: #11652 but feel free to ship this if you have time to dedicate to it.

I took a slightly different approach, but also found a user created issue that I linked in my description. (I'm not on Polaris team)

Oh nice! Yours makes a lot more sense, of course we would want to skip all the other "selectable" functionality if selectable={false} and only do the onClick stuff 🤦‍♀️

I added the extra check to mine too 😄 good callout!

@sydturn sydturn changed the title Allow row click when onClick is passed in [IndexTable] Allow row click when onClick is passed in on non-selectable tables Mar 19, 2024
@sydturn sydturn marked this pull request as ready for review March 19, 2024 17:36
@sydturn sydturn requested review from a team March 19, 2024 17:37
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.

Thanks for contributing @sydturn! Changes 👀 👍🏽

.changeset/odd-swans-teach.md Outdated Show resolved Hide resolved
Co-authored-by: Chloe Rice <chloerice@users.noreply.github.com>
@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 Mar 19, 2024
@sydturn
Copy link
Contributor Author

sydturn commented Mar 19, 2024

/snapit

Copy link
Contributor

🫰✨ Thanks @sydturn! Your snapshot has been published to npm.

Test the snapshot by updating your package.json with the newly published version:

yarn add @shopify/polaris@0.0.0-snapshot-20240319183006

@etlgfx
Copy link

etlgfx commented Mar 19, 2024

@sydturn Looks great so far, thanks for taking this on!!

@sydturn sydturn requested a review from etlgfx March 19, 2024 20:07
Copy link
Contributor

@itwasmattgregg itwasmattgregg left a comment

Choose a reason for hiding this comment

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

Looks great!

@sydturn sydturn merged commit e7ab4a8 into main Mar 20, 2024
23 checks passed
@sydturn sydturn deleted the handle-index-row-click branch March 20, 2024 16:01
kyledurand pushed a commit that referenced this pull request Mar 21, 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@12.22.0

### Minor Changes

- [#11677](#11677)
[`f6ba2b2a8`](f6ba2b2)
Thanks [@jesstelford](https://github.com/jesstelford)! - Migrated
@shopify/polaris from SASS to CSS using postcss plugins


- [#11723](#11723)
[`4699bb229`](4699bb2)
Thanks [@mrcthms](https://github.com/mrcthms)! - Updated `BulkActions`
to only show actions when selectMode is `true`


- [#11727](#11727)
[`c3ba6ae1b`](c3ba6ae)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Removed the
responsive logic that disabled the Card bevel on mobile. Removing this
until we are ready to rollout bevel changes across all components.

### Patch Changes

- [#11757](#11757)
[`e0ae9565c`](e0ae956)
Thanks [@sophschneider](https://github.com/sophschneider)! - Added
dynamicTopBarAndReframe feature flag type


- [#11733](#11733)
[`9c24a465c`](9c24a46)
Thanks [@jesstelford](https://github.com/jesstelford)! - Convert
SASS-style inline comments to CSS-style multiline comments.


- [#11724](#11724)
[`1543246b7`](1543246)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Updated
responsive styles for `Text` component


- [#11765](#11765)
[`42c298ea7`](42c298e)
Thanks [@jesstelford](https://github.com/jesstelford)! - Fix build
performance regression from using postcss-mixins.


- [#11725](#11725)
[`3e011e3b6`](3e011e3)
Thanks [@kyledurand](https://github.com/kyledurand)! - Fixed a bug where
iOS 16 font patch wasn't added for mobile app web views


- [#11763](#11763)
[`e7ab4a8f5`](e7ab4a8)
Thanks [@sydturn](https://github.com/sydturn)! - Fixed `IndexTable.Row`
`onClick` not being called when `selectable` is `false`


- [#11745](#11745)
[`831a683a2`](831a683)
Thanks [@kyledurand](https://github.com/kyledurand)! - Fixed bug in
math.ts for popover with position cover


- [#11735](#11735)
[`6d8ef8c99`](6d8ef8c)
Thanks [@sam-b-rose](https://github.com/sam-b-rose)! - Used `Text`
component to apply text styles for `Button`


- [#11592](#11592)
[`ad6315845`](ad63158)
Thanks [@SMAKSS](https://github.com/SMAKSS)! - Passed missing `id` prop
to the root element of `BlockStack`

## @shopify/stylelint-polaris@15.4.0

### Minor Changes

- [#11677](#11677)
[`f6ba2b2a8`](f6ba2b2)
Thanks [@jesstelford](https://github.com/jesstelford)! - Add `--pg-` as
a disallowed CSS Custom Property prefix (these are "global" Custom
Properties used within @shopify/polaris-react).

## @shopify/polaris-migrator@0.28.2

### Patch Changes

- [#11754](#11754)
[`f57db81df`](f57db81)
Thanks [@jesstelford](https://github.com/jesstelford)! - Move migrations
to v14 since the node v20 requirement will be the only change in v13

- Updated dependencies
\[[`f6ba2b2a8`](f6ba2b2)]:
    -   @shopify/stylelint-polaris@15.4.0

## polaris.shopify.com@0.66.0

### Minor Changes

- [#11720](#11720)
[`97184dc80`](97184dc)
Thanks [@sarahill](https://github.com/sarahill)! - Added common action
guidance.


- [#11690](#11690)
[`c78f125c7`](c78f125)
Thanks [@heyjoethomas](https://github.com/heyjoethomas)! - Updates
images for icon design guidance

### Patch Changes

- [#11747](#11747)
[`5cff96245`](5cff962)
Thanks [@sarahill](https://github.com/sarahill)! - Updated card layout
patterns to match common action patterns.

- Updated dependencies
\[[`e0ae9565c`](e0ae956),
[`9c24a465c`](9c24a46),
[`f6ba2b2a8`](f6ba2b2),
[`4699bb229`](4699bb2),
[`c3ba6ae1b`](c3ba6ae),
[`1543246b7`](1543246),
[`42c298ea7`](42c298e),
[`3e011e3b6`](3e011e3),
[`e7ab4a8f5`](e7ab4a8),
[`831a683a2`](831a683),
[`6d8ef8c99`](6d8ef8c),
[`ad6315845`](ad63158)]:
    -   @shopify/polaris@12.22.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
chloerice added a commit that referenced this pull request Mar 21, 2024
#11773)

### WHAT is this pull request doing?

This PR reverts a change made in #11763, unrelated to the bug fixed,
that caused an unintended regression: breaking `onNavigation` behavior
for unselectable tables. This needs to ship in a patch asap because it
is live in v12.20.0.
AnnaCheba pushed a commit to AnnaCheba/polaris that referenced this pull request Apr 22, 2024
…ble tables (Shopify#11763)

<!--
  ☝️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?

Resolves Shopify#11518 and Relates to
Shopify/credit#1252 which needs to use
clickable IndexTables but without checkboxes.

Here is the
[Figma](https://www.figma.com/file/LtoBWJzLY17yfm9fYxRHrD/Finances-unification?type=design&node-id=4145-35105&mode=design&t=0WNE8MDZa62DwdMj-0)
I'm working off of. Currently these tables exist in Shopify Balance and
Credit already but they're using our own custom css/html alongside
ResourceList and it's
a) hard to manage (the columns don't have the context of the other
columns and don't automatically adjust so we have to hardcode the column
widths which is a pain whenever we need to add a new column
b) doesn't conform to Polaris aesthetics
So we're [trying to
migrate](Shopify/credit#1252) to using
IndexTables to make maintenance on these tables easier, the transition
to the new Figma easier, and the aesthetics of the tables look more like
Polaris.
I have it [mostly implemented
](Shopify/web#120937 the only thing is that
the rows need to be clickable without the checkboxes.

There are no aesthetic changes in this PR for including a screenshot.

### WHAT is this pull request doing?

<!--
  Summary of the changes committed.

Before / after screenshots are appreciated for UI changes. Make sure to
include alt text that describes the screenshot.

  Include a video if your changes include interactive content.

If you include an animated gif showing your change, wrapping it in a
details tag is recommended. Gifs usually autoplay, which can cause
accessibility issues for people reviewing your PR:

  <details>
    <summary>Summary of your gif(s)</summary>
    <img src="..." alt="Description of what the gif shows">
  </details>
-->

This pull requests makes it so that if an `onClick` event is provided to
a `IndexTable.Row` that is in an `IndexTable` that has
`selectable={false}` the `onClick` will still be called. Rows being
selectable vs. clickable should not be mutually exclusive.

### 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)

☝️ TLDR; 
1. `git clone https://github.com/Shopify/polaris.git`
2. `yarn install && cd polaris-react`
3. `dev up && dev server`

I have provided a code snippet that you can put in your playground for
testing. Where in `main` clicking a row would do nothing, with the
changes in this PR clicking on a row will log to the console.

```
    <Page title="Playground">
      <IndexTable
        itemCount={2}
        selectable={false}
        headings={[{title: 'date'}, {title: 'description'}, {title: 'amount'}]}
      >
        <IndexTable.Row onClick={handleOnClick} position={1} id="1">
          <IndexTable.Cell>Today</IndexTable.Cell>
          <IndexTable.Cell>Dollarama</IndexTable.Cell>
          <IndexTable.Cell>$30</IndexTable.Cell>
        </IndexTable.Row>
      </IndexTable>
    </Page>
```

You can also test it on
[this](https://admin.web.banking-credit-f7h4.sydney-rhude.us.spin.dev/store/shop3/credit?referrer=finances-nav&modalView=receiptView)
spin instance (the transaction table shown utilizes non-selectable but
yes clickable)

### 🎩 checklist

I'm not so sure this needs to be added to the changeset, documentation,
or readme, as it is just implementing a fix for something that should
already exist but doesn't? I'm not sure. This isn't a new feature, it's
just a fix for an existing one that rarely gets used I guess?

- [x] Tested a
[snapshot](https://github.com/Shopify/polaris/blob/main/documentation/Releasing.md#-snapshot-releases)
- [ ] Tested on
[mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing)
- [ ] Tested on [multiple
browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers)
- [ ] Tested for
[accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md)
- [ ] Updated the component's `README.md` with documentation changes
- [ ] [Tophatted
documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md)
changes in the style guide

---------

Co-authored-by: Chloe Rice <chloerice@users.noreply.github.com>
AnnaCheba pushed a commit to AnnaCheba/polaris that referenced this pull request Apr 22, 2024
Shopify#11773)

### WHAT is this pull request doing?

This PR reverts a change made in Shopify#11763, unrelated to the bug fixed,
that caused an unintended regression: breaking `onNavigation` behavior
for unselectable tables. This needs to ship in a patch asap because it
is live in v12.20.0.
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.

onClick Disabled on IndexTable.Row when IndexTable prop 'selectable' is set to false
4 participants