-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[DataTable] Add fixedFirstColumns prop
#6976
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
Conversation
|
/snapit |
size-limit report 📦
|
|
/snapit |
This comment was marked as outdated.
This comment was marked as outdated.
afb8c75 to
6befc7d
Compare
|
/snapit |
| }, | ||
| } as ComponentMeta<typeof DataTable>; | ||
|
|
||
| function sortRows(rows, index, direction) { |
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.
We also wanted to fix these examples since the sorting doesn't really work.
This comment was marked as outdated.
This comment was marked as outdated.
6befc7d to
346500a
Compare
|
/snapit |
346500a to
5febd6e
Compare
This comment was marked as outdated.
This comment was marked as outdated.
|
/snapit |
|
🫰✨ Thanks @nickpresta! Your snapshots have been published to npm. Test the snapshots by updating your yarn add @shopify/polaris@0.0.0-snapshot-release-20220818200014yarn add @shopify/polaris-tokens@0.0.0-snapshot-release-20220818200014yarn add @shopify/stylelint-polaris@0.0.0-snapshot-release-20220818200014 |
fixedFirstColumns prop
e957733 to
c096ff5
Compare
c096ff5 to
836af11
Compare
836af11 to
a890b01
Compare
|
I left comments on the stories that changed in Chromatic -- it would be great for someone else to take a look and verify my comments and accept the changes. |
| content, | ||
| contentType, | ||
| firstColumn, | ||
| nthColumn, |
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.
Wondering if this should just be called fixed or fixedColumn
ryanpdaley
left a comment
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.
Looks good to me.
783adf0 to
c923912
Compare
|
Just leaving a comment about a UI issue that potentially could happen if you pass a number of |
chloerice
left a comment
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.
Hey @tylernoseworthy 👋🏽 This works great on large screen but needs to be limited to 1 fixed column (or none at all) on small screens. Currently the table breaks on small screens:
.changeset/lazy-nails-relax.md
Outdated
| '@shopify/polaris': minor | ||
| --- | ||
|
|
||
| Added `fixedFirstColumns` prop to `DataTable` so that multiple columns can be fixed |
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.
| Added `fixedFirstColumns` prop to `DataTable` so that multiple columns can be fixed | |
| - Added a `fixedFirstColumns` prop to `DataTable` so that multiple columns can be fixed | |
| - Deprecated the `DataTable` `fixedFirstColumn` prop |
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.
Looks like this caused a bit of a kerfuffle in the generated changelog. Can we reduce this to a single line without bullets? Not as fancy, but might improve how changesets renders it
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.
@samrose3 Am I able to make that change directly on that branch? or is there a special command I have to run?
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.
You can just modify the changeset file directly (.changeset/lazy-nails-relax.md) no command needed 👍
|
@chloerice Thanks for the feedback! I'd like to understand a bit better -- is there a reason this needs to be baked into Polaris? The We don't seem to take a stance of overriding props when certain combinations wouldn't look great on small screens - for example grid, button group, index table require the consumer to make an explicit choice about how to handle small screens. For the data table, it would mean changing the Thanks for any context! |
Hey @nickpresta! I think that approach of putting the onus on consumers is fine, as long the documentation for that prop calls it out and its examples show how to implement it. |
| ], | ||
| ]; | ||
| const [sortedRows, setSortedRows] = useState(rows); | ||
| const showFixedColumns = useMedia('screen and (max-width: 850px)'); |
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.
I noticed this will not work when editing in codesandbox because of the useMedia hook. Is this something we should be worried about?
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.
Hey @tylernoseworthy you'll need to copy and paste the hook into the bottom of the example instead of importing it.
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.
Forgot to do it before merging 😅. I'll follow up with a another PR to fix the example for codesandbox.
#### Related PR: #6976 <!-- ☝️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 - Prefix it with [WIP] while it’s a work in progress --> ### WHY are these changes introduced? A `useMedia` hook was introduced for a `DataTable` example as an import. This however breaks the example when a user want's to view this within codesandbox. <!-- Context about the problem that’s being addressed. --> ### WHAT is this pull request doing? This adds a `useMedia` hook to the bottom of the example ### How to 🎩 🖥 [Local development instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development) 🗒 [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 - [ ] 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 - [x] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide
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@6.0.0 ### Major Changes - [#7012](#7012) [`bd00ef4ed`](bd00ef4) Thanks [@leileu](https://github.com/leileu)! - Adding Metafields icon to polaris ### Minor Changes - [#7013](#7013) [`1e0645f33`](1e0645f) Thanks [@jpmarra](https://github.com/jpmarra)! - Added IdentityCard icon - [#7028](#7028) [`635bcfeb7`](635bcfe) Thanks [@joelzwarrington](https://github.com/joelzwarrington)! - add vertical viewport icon variations ## @shopify/polaris@10.1.0 ### Minor Changes - [#6976](#6976) [`ae7345f0c`](ae7345f) Thanks [@tylernoseworthy](https://github.com/tylernoseworthy)! - - Added a `fixedFirstColumns` prop to `DataTable` so that multiple columns can be fixed - Deprecated the `DataTable` `fixedFirstColumn` prop - [#7043](#7043) [`60086a61f`](60086a6) Thanks [@philschoefer](https://github.com/philschoefer)! - Updates to `DataTable` - Fixed `DataTable` cell content not wrapping when the `truncate` prop is `false` - Added support for setting the `DataTable` `truncate` prop without having to set the `fixedFirstColumns` prop ### Patch Changes - [#7022](#7022) [`716956df6`](716956d) Thanks [@QuintonC](https://github.com/QuintonC)! - Fixed visual bug for avatar shape prop - [#7038](#7038) [`d1a33d8b0`](d1a33d8) Thanks [@kyledurand](https://github.com/kyledurand)! - Applied default background color to image avatar - [#6993](#6993) [`fa840e4a9`](fa840e4) Thanks [@kyledurand](https://github.com/kyledurand)! - Removed deprecation from Layout.AnnotatedSection - [#7003](#7003) [`2b5f7d0fc`](2b5f7d0) Thanks [@mrcthms](https://github.com/mrcthms)! - Fix visual bug for sortable, selectable index table headings - Updated dependencies \[[`bd00ef4ed`](bd00ef4), [`1e0645f33`](1e0645f), [`635bcfeb7`](635bcfe)]: - @shopify/polaris-icons@6.0.0 ## polaris.shopify.com@0.14.0 ### Minor Changes - [#7018](#7018) [`a8087a358`](a8087a3) Thanks [@alex-page](https://github.com/alex-page)! - Generate assets once with a seperate script - [#6934](#6934) [`793e26f4d`](793e26f) Thanks [@alex-page](https://github.com/alex-page)! - Use @shopify/polaris-icons instead of /icons and copy-icons - [#7049](#7049) [`7a548a00a`](7a548a0) Thanks [@alex-page](https://github.com/alex-page)! - Move search to the server side ### Patch Changes - [#7015](#7015) [`e612cbccb`](e612cbc) Thanks [@lgriffee](https://github.com/lgriffee)! - Update navigation column in breakpoints table for MD breakpoint - [#7027](#7027) [`a805116a6`](a805116) Thanks [@sarahill](https://github.com/sarahill)! - Updated design guidance for typography - Updated dependencies \[[`716956df6`](716956d), [`ae7345f0c`](ae7345f), [`60086a61f`](60086a6), [`bd00ef4ed`](bd00ef4), [`d1a33d8b0`](d1a33d8), [`fa840e4a9`](fa840e4), [`2b5f7d0fc`](2b5f7d0), [`1e0645f33`](1e0645f), [`635bcfeb7`](635bcfe)]: - @shopify/polaris@10.1.0 - @shopify/polaris-icons@6.0.0 ## polaris-for-figma@0.0.11 ### Patch Changes - Updated dependencies \[[`716956df6`](716956d), [`ae7345f0c`](ae7345f), [`60086a61f`](60086a6), [`d1a33d8b0`](d1a33d8), [`fa840e4a9`](fa840e4), [`2b5f7d0fc`](2b5f7d0)]: - @shopify/polaris@10.1.0 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>



WHY are these changes introduced?
We are currently using the
DataTable, but there was a requirement in our current project for the first 2 columns within the table to be fixed.WHAT is this pull request doing?
This PR adds a
fixFirstColumnsprop in favour of thehasFixedFirstColumnprop, which now has a deprecation warning if still being used in development. In the event thathasFixedFirstColumnis still being used, we will default to showing 1 fixed column. Additionally, if a number defined infixFirstColumnsexceeds or is equal to the amount of columns within the table, no fixed columns will be rendered.Before
After
Without sticky header
With sticky header
How to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
Copy-paste this code in
playground/Playground.tsx:🎩 checklist
README.mdwith documentation changes