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

Table resizing docs #3840

Merged
merged 13 commits into from
Dec 16, 2022
Merged

Table resizing docs #3840

merged 13 commits into from
Dec 16, 2022

Conversation

LFDanLu
Copy link
Member

@LFDanLu LFDanLu commented Dec 13, 2022

Closes

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

Look at the docs here: https://reactspectrum.blob.core.windows.net/reactspectrum/43562aa419ee35d11e0bec0f881f0039661718b7/docs/react-spectrum/TableView.html#column-resizing

🧢 Your Project:

RSP

@LFDanLu LFDanLu changed the base branch from main to refactor-column-resizing December 13, 2022 01:46
Base automatically changed from refactor-column-resizing to main December 13, 2022 22:01
@LFDanLu LFDanLu force-pushed the table_resizing_docs branch from 440ea93 to 25433e0 Compare December 13, 2022 22:30
@LFDanLu LFDanLu changed the title (WIP) Table resizing docs Table resizing docs Dec 13, 2022
Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

We need an example that shows how to control the widths as well. It's not trivial since you have to create new column objects for the virtualizer to pick them up. See https://github.com/adobe/react-spectrum/blob/main/packages/%40react-spectrum/table/stories/ControllingResize.tsx#L58 and https://github.com/adobe/react-spectrum/blob/main/packages/%40react-spectrum/table/stories/ControllingResize.tsx#L67

Would it be easy to setup some code that uses onResizeEnd to store the column widths locally, then when they refresh the page, we could set the table to its previously resized column widths? Otherwise, maybe we can do that in a codesandbox

packages/@react-spectrum/table/docs/TableView.mdx Outdated Show resolved Hide resolved
packages/@react-spectrum/table/docs/TableView.mdx Outdated Show resolved Hide resolved
an `onResizeEnd` prop as well, triggered when the user finishes a column resize operation. Both events receive a Map object containing the widths of every column in the TableView.

The example below illustrates how each of the aforementioned column width properties affects their respective column's resize behavior. It also demonstrates when `onResize` and `onResizeEnd` fire when resizing and the prints the values provided to each.

Copy link
Member

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

Copy link
Member Author

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?

packages/@react-spectrum/table/docs/TableView.mdx Outdated Show resolved Hide resolved
@LFDanLu
Copy link
Member Author

LFDanLu commented Dec 14, 2022

@snowystinger

We need an example that shows how to control the widths as well. It's not trivial since you have to create new column objects for the virtualizer to pick them up. See https://github.com/adobe/react-spectrum/blob/main/packages/%40react-spectrum/table/stories/ControllingResize.tsx#L58 and https://github.com/adobe/react-spectrum/blob/main/packages/%40react-spectrum/table/stories/ControllingResize.tsx#L67
Would it be easy to setup some code that uses onResizeEnd to store the column widths locally, then when they refresh the page, we could set the table to its previously resized column widths? Otherwise, maybe we can do that in a codesandbox

Sounds good, thanks for bringing it up. Can you expand on store the column widths locally?

@snowystinger
Copy link
Member

Sounds good, thanks for bringing it up. Can you expand on store the column widths locally?

I just mean in localStorage or something equivalent https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

snowystinger
snowystinger previously approved these changes Dec 15, 2022
Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

Ah, that's so cool!

@dannify
Copy link
Member

dannify commented Dec 15, 2022

DanniBot docs: https://reactspectrum.blob.core.windows.net/reactspectrum/43562aa419ee35d11e0bec0f881f0039661718b7/docs/react-spectrum/TableView.html#column-resizing

localStorage.setItem('RSPWidths', finalWidths);
};

// Create new columns object when tracked widths change so Virtualizer rerenders the new column widths
Copy link
Member

@devongovett devongovett Dec 15, 2022

Choose a reason for hiding this comment

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

Not sure anyone will know what Virtualizer is since it is internal, so probably shouldn't highlight that.

I think we could potentially refactor this to store the widths in the column object itself rather than a separate map.

Untested, but possible solution:

let [columns, setColumns] = React.useState(() => {
  let localStorageWidths = localStorage.getItem('RSPWidths');
  if (localStorageWidths) {
    let widths = JSON.parse(localStorageWidths);
    return columnsData.map(col => ({...col, width: widths[col.id]}));
  } else {
    return columnsData;
  }
});

let onResize = (widths) => {
  setColumns(columns => columns.map(col => ({...col, width: widths.get(col.id)})));
};

let onResizeEnd = (widths) => {
  localStorage.setItem('RSPWidths', JSON.stringify(Object.fromEntries(widths)));
};

}

<ResizableTable />
```
Copy link
Member

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

Copy link
Member Author

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

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
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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

Copy link
Member

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?

Copy link
Member Author

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)

Copy link
Member

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

Comment on lines 610 to 611
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` prop as well, triggered when the user finishes a column resize operation. Both events receive a Map object containing the widths of every column in the TableView.
Copy link
Member

Choose a reason for hiding this comment

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

also...as well

Suggested change
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` prop as well, triggered when the user finishes a column resize operation. Both events receive a Map object containing the widths of every column in the TableView.
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` 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.


### 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 (`fr`) units as well.
Copy link
Member

Choose a reason for hiding this comment

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

We might need to explain what an fr is somewhere.


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 (`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 sets its width to the value provided to it, making it unaffected by other columns' widths. `minWidth` and `maxWidth` allows you to restrict a Column's
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
by the `width` prop. Providing a non-fractional value `width` to a Column sets its width to the value provided to it, making it unaffected by other columns' widths. `minWidth` and `maxWidth` allows you to restrict a Column's
by the `width` prop. Providing a non-fractional value `width` to a Column will make it unaffected by other columns' widths upon resize. `minWidth` and `maxWidth` allows you to restrict a Column's

snowystinger
snowystinger previously approved these changes Dec 15, 2022
@devongovett
Copy link
Member

reidbarber
reidbarber previously approved these changes Dec 15, 2022
let onResizeEnd = (widths) => {
localStorage.setItem('RSPWidths', JSON.stringify(Object.fromEntries(widths)));
};
/*- end highlight -*/
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/*- end highlight -*/
/*- end highlight -*/

};
/*- end highlight -*/
return (
<Flex direction="column">
Copy link
Member

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?

Copy link
Member Author

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

### 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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

@LFDanLu LFDanLu dismissed stale reviews from reidbarber and snowystinger via 0ae0ac7 December 15, 2022 23:45
snowystinger
snowystinger previously approved these changes Dec 15, 2022
reidbarber
reidbarber previously approved these changes Dec 16, 2022
@devongovett devongovett dismissed stale reviews from reidbarber and snowystinger via 618e9ed December 16, 2022 16:27
@devongovett
Copy link
Member

I thought maybe it would be better to move the Column widths section above column resizing and put the description of those props there since they are not specific to resizing. Then the resizing section can be shortened and reference it. Pushed an attempt at this - lmk what you think.

@snowystinger snowystinger mentioned this pull request Dec 16, 2022
61 tasks
@devongovett devongovett merged commit 9704b0e into main Dec 16, 2022
@devongovett devongovett deleted the table_resizing_docs branch December 16, 2022 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants