-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[IndexTable] Fix checkboxes rendering when selectable=false #4376
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] Fix checkboxes rendering when selectable=false #4376
Conversation
size-limit report
|
56a2724 to
686059a
Compare
|
I wasn't aware the Thanks for your contribution and for getting the API working ❤️ I'm removing myself as a reviewer since I'll be on vacation and won't be able to review. |
@brendanatshopify is there an issue for this already / if not could you add one and stick a link here? Sounds fun ;) |
| hasMoreLeftColumns && styles['Table-scrolling'], | ||
| selectMode && styles.disableTextSelection, | ||
| selectMode && shouldShowBulkActions && styles.selectMode, | ||
| isSelectableIndex === false && styles['Table-unselectable'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] for consistency with how it's used elsewhere, [c/sh]ould this be !isSelectableIndex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*provided we're defaulting this value to true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, updated, also renamed isSelectableIndex to selectable for better readability
| hovered && styles['TableRow-hovered'], | ||
| status && styles[variationName('status', status)], | ||
| ); | ||
| const getPrimaryLinkElement = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] this should maybe be memoized since (1) it's doing a DOM lookup, (2) it's called 3x on each rerender, and (3) the value isn't that likely to change on rerender
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea– it's a little tricky to memoize the function here since its dependencies aren't based on a state value, but I updated it to use a callback ref which will set primaryLinkElement.current only once when the tableRowRef mounts, which should have the same effect.
| event.stopPropagation(); | ||
| event.preventDefault(); | ||
|
|
||
| const primaryLinkElement = getPrimaryLinkElement(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] esp. if you don't memoize, this could be pulled above line 84 to remove a lookup
| expect(onSelectionChangeSpy).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('does not fire onClick handler when row is clicked and no primary link child present and table is not selectable', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[suggestion] could also add tests for checkbox is shown when selectable is true and not shown when selectable is false
| }); | ||
| }); | ||
|
|
||
| it('does not render checkboxes when selectable is set to false', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I see, you're testing checkboxes here. There's an argument to be made for unit testing this Row checkbox functionality only within the Row component but it's more down to your testing philosophy 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, moved this and added a couple more tests in Row.test.tsx to validate the checkbox presence
|
Mostly LGTM! Biggest concern is the hover color, everything else is nits. Ping me when I can 🎩 again! |
|
@brendanatshopify @lhoffbeck This might be a bit out of scope, but what do we think about making the fist column not sticky on small viewports when unselectable? I realize this table uses the pattern of leaving the first column sticky, but it seems a bit disastrous on the smaller viewports in cases where we need the table to be scrolling for whatever reason, as opposed to leveraging the first-col-sticky.mov |
|
@pamelahicks 100% agree that's worth looking into in a different PR :) Do you know if there's a ticket already? |
Good call, issue opened at #4428 |
Related to #4012 |
ee4b3e7 to
739aad9
Compare
|
I want my row to be selectable but if i click on the button on my row it won't be selected and just toggles the button is that possible? |
Hi @sandysameh! You should be able to do this by capturing the click event and using |
|
Any ETA on when this is going to be published? |
|
Hi @FredyC, it's out as of the v7 release :) |
WHY are these changes introduced?
Currently in the
IndexTablecomponent when theselectableprop isfalsetheIndexTableremains selectable and the checkboxes still show.This PR builds off of @chloerice's branch at #4367.
Fixes: #4076 and #4332
WHAT is this pull request doing?
This updates the IndexTable component to hide the checkboxes when the
selectableprop is set tofalse. AnybulkActionsandprimaryBulkActionssupplied to the component will also have no effect whenselectable={false}.Noteable changes
selectedItemsCountandonSelectionChangeprops are now optional inIndexProviderselectable={false}theSelectbutton does not appear in the condensed view.selectable={true}the first two columns are sticky on tablet, and only the checkbox column is sticky on mobile. Whenselectable={false}only the first column is sticky in both screens.Row clickability
If
selectable={false}and theRowdoes not havedata-primary-linkthe row will not respond to clicks. As such the cursor will be set toautoand any links in the row's cells will be individually clickable.To make the entire row clickable to another url, one of the elements in the
TableRowmust be wrapped in anatag with adata-primary-linkattribute. Note that this is unchanged functionality.Notes
There is some wonkiness in the sticky columns when scrolling left inside a table with a horizontal scrollbar. If a user scrolls left fast enough the sticky columns don't have the correct styles applied in time, which can sometimes produce an effect where the user can see the moving columns underneath the sticky columns. In addition, when moving left the
headercolumns sometime lag behind the non-header columns in going left. This is also an issue onmainbut I wanted to call it out here in case this is something we want to address now/soon.Videos
Demo of a full screen IndexTable when selectable=false
Demo of a full screen IndexTable when selectable=true
Demo of an IndexTable when selectable=false with a left scrollbar
Demo of an IndexTable when selectable=true with a left scrollbar
Demo of an IndexTable when selectable=false with a left scrollbar on a small screen
Demo of an IndexTable when selectable=true with a left scrollbar on a small screen
Demo of an IndexTable when selectable=false and condensed=true
Demo of an IndexTable when selectable=true and condensed=true
Demo of an IndexTable when selectable=false and rows don't have a data-primary-link
Demo of an IndexTable when selectable=false and rows have a data-primary-link
Demo of an IndexTable when selectable=false and rows don't have a data-primary-link but have an individual link
How to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
Copy-paste this code in
playground/Playground.tsxto test **unselectable**:Copy-paste this code in
playground/Playground.tsxto test **selectable**:🎩 checklist
README.mdwith documentation changes