-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Table resizing docs #3840
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
Table resizing docs #3840
Changes from 10 commits
a8dbe75
25433e0
e1a7524
7db052b
43562aa
f54965c
7549e58
5a58576
fe58f6b
e558a5d
fd475a4
0ae0ac7
618e9ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,7 +12,7 @@ export default Layout; | |||||||
|
|
||||||||
| import docs from 'docs:@react-spectrum/table'; | ||||||||
| import tableTypes from 'docs:@react-types/table/src/index.d.ts'; | ||||||||
| import {HeaderInfo, PropTable, PageDescription} from '@react-spectrum/docs'; | ||||||||
| import {HeaderInfo, PropTable, PageDescription, VersionBadge} from '@react-spectrum/docs'; | ||||||||
| import {Keyboard} from '@react-spectrum/text'; | ||||||||
| import packageData from '@react-spectrum/table/package.json'; | ||||||||
|
|
||||||||
|
|
@@ -560,6 +560,118 @@ function AsyncSortTable() { | |||||||
| } | ||||||||
| ``` | ||||||||
|
|
||||||||
| ## Column Resizing <VersionBadge version="beta" style={{marginLeft: 4, verticalAlign: 'bottom'}} /> | ||||||||
|
|
||||||||
| TableView supports resizable columns, allowing users to dynamically adjust the width of a column. To designate that a Column is resizable, provide it with the `allowsResizing` prop. This will render a draggable | ||||||||
| resizer handle that becomes visible on hover. Keyboard, touch, and screen reader users can start resizing by interacting with the target column's header and selecting the "Resize column" option | ||||||||
| from the dropdown. | ||||||||
|
|
||||||||
| ### Width values | ||||||||
|
|
||||||||
| Columns support four different width props: `defaultWidth`, `width`, `minWidth`, and `maxWidth`. Each of these props accepts fixed values or percentages, with `width` and `defaultWidth` accepting [fractional](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/Basic_Concepts_of_Grid_Layout#the_fr_unit) | ||||||||
| (`fr`) units as well. An initial, uncontrolled width can be provided to a Column using the `defaultWidth` prop. This allows the column width to freely shrink and grow in relation to other column widths. Alternatively, a controlled value can be provided | ||||||||
| by the `width` prop. Providing a non-fractional value `width` to a Column will make it unaffected by other columns' widths on resize. `minWidth` and `maxWidth` allows you to restrict a Column's | ||||||||
| width to a minimum and maximum value respectively. TableView prioritizes columns with defined widths and divides the remaining space evenly amongst the other columns. | ||||||||
|
|
||||||||
| The example below illustrates how each of the aforementioned column width properties affects their respective column's resize behavior. | ||||||||
|
|
||||||||
| ```tsx example | ||||||||
| <TableView | ||||||||
| aria-label="TableView with resizable columns" | ||||||||
| maxWidth={320} | ||||||||
| height={200} > | ||||||||
| <TableHeader> | ||||||||
| {/*- begin highlight -*/} | ||||||||
| <Column key="file" allowsResizing maxWidth={500}>File Name</Column> | ||||||||
| <Column key="size" width={80}>Size</Column> | ||||||||
| <Column key="date" allowsResizing minWidth={100}>Date Modified</Column> | ||||||||
| {/*- end highlight -*/} | ||||||||
| </TableHeader> | ||||||||
| <TableBody> | ||||||||
| <Row> | ||||||||
| <Cell>2022-Roadmap-Proposal-Revision-012822-Copy(2)</Cell> | ||||||||
| <Cell>214 KB</Cell> | ||||||||
| <Cell>November 27, 2022 at 4:56PM</Cell> | ||||||||
| </Row> | ||||||||
| <Row> | ||||||||
| <Cell>62259692_p0_master1200</Cell> | ||||||||
| <Cell>120 KB</Cell> | ||||||||
| <Cell>January 27, 2021 at 1:56AM</Cell> | ||||||||
| </Row> | ||||||||
| </TableBody> | ||||||||
| </TableView> | ||||||||
| ``` | ||||||||
|
|
||||||||
| ### Resize events | ||||||||
|
|
||||||||
| TableView accepts an `onResize` prop which is triggered whenever a column resizer is moved by the user. This can be used in combination with the `width` prop to update a Column's width in a controlled fashion. TableView also accepts | ||||||||
| an `onResizeEnd` props, which is triggered when the user finishes a column resize operation. Both events receive a Map object containing the widths of every column in the TableView. | ||||||||
|
||||||||
| an `onResizeEnd` props, which is triggered when the user finishes a column resize operation. Both events receive a Map object containing the widths of every column in the TableView. | |
| an `onResizeEnd` prop, which is triggered when the user finishes a column resize operation. Both events receive a Map object containing the widths of every column in the TableView. |
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 should mention somewhere in here that a resize event locks all columns to the left of the resizing column to a pixel width, so it's not just one column that changes at a time
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.
Hm, IMO this feels a bit specific and potentially confusing the reader. Do you feel that this might be a common question a user of column resize might ask?
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.
| /*- end highlight -*/ | |
| /*- end highlight -*/ | |
Outdated
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.
What's the extra flex for?
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.
Ah derp, hold over from when the example had pre elements to show what widths were being provided to the event handlers, thanks for catching
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.
These examples are too wide on mobile and mess up scrolling
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.
Updated. Also got rid of one of the columns since the table's columns were almost all the same due to the width restraint, I think the three columns should show how the widths work a bit better without immediately making the TableView scrollable right away
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 guess the width configuration isn't really specific to column resizing. Wonder if people will miss it because it is a sub-heading?
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'll keep this section here and restore the old width values section we had down in visual options then
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.
Not sure, it was more of a question for everyone
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'd worry about people missing how to define widths if it was under resizing only. Can we invert it and have resizing be a sub header?
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.
IMO, it would be good to preserve the old section and keep the resizing as the main header. I feel like most people who are looking for column resizing will look specifically for "Resizing" as a header and keeping the old section as will also keep the page layout familiar to old users (no confusion as to if that visual option has disappeared and old links will still work)
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 agree, I would like width to be it's own heading/sub-heading and it could be referenced from the resizing section that seems ok