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

fix: Fixes table editable cell styles and simplifies it #3061

Merged
merged 5 commits into from
Dec 16, 2024

Conversation

pan-kot
Copy link
Member

@pan-kot pan-kot commented Nov 26, 2024

Description

The PR refactors table body cell styles with the focus on editable cells. That is needed for the follow-up task to move editable cell style from the cell element to the cell content instead. This would allow having both row expand toggle and editable cell trigger in a single cell (in 1st column).

How has this been tested?

  • Screenshot tests
  • Manual testing on the cell-permutations page
Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.35%. Comparing base (606beea) to head (9836e89).
Report is 36 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3061   +/-   ##
=======================================
  Coverage   96.34%   96.35%           
=======================================
  Files         778      780    +2     
  Lines       21908    21971   +63     
  Branches     7507     7472   -35     
=======================================
+ Hits        21108    21170   +62     
- Misses        748      749    +1     
  Partials       52       52           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pan-kot pan-kot force-pushed the editable-cells-wrapper branch from 1845521 to c0e7ae6 Compare December 2, 2024 05:52
@pan-kot pan-kot changed the title fix: Fixes table editable cell styles and simplifies it [WIP] fix: Fixes table editable cell styles and simplifies it Dec 3, 2024
$cell-offset: calc(#{awsui.$space-m} + #{awsui.$space-xs});

// Ensuring enough space for absolute-positioned focus outlines of focus-able cell content elements.
$cell-negative-space-vertical: 2px;
Copy link
Member Author

Choose a reason for hiding this comment

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

This negative space was used to virtually enlarge the cell-content element. That is because the element has overflow: hidden but when there are interactive elements inside such a link or a button dropdown - the focus outline is being cut off.

The negative space is no longer needed because now the cell content size matches cell size. This way the outline can use the available cell space while the content is still truncated correctly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Update: the negative space is still needed at least for the compact mode.

align-content: center;

&.body-cell-align-top {
align-content: baseline;
Copy link
Member Author

Choose a reason for hiding this comment

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

Now the cell content takes the entire cell size so the alignment must be attached to it instead of the cell.

align-content: baseline;
}

&:not(.body-cell-wrap) {
Copy link
Member Author

Choose a reason for hiding this comment

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

The .body-cell-wrap only takes effect on the cell-content element so attaching the style to it directly.

// That is to prevent focus outline on cell content from being cut out.
> .body-cell-content {
padding-inline-start: awsui.$border-divider-list-width;
margin-inline-start: calc(-1 * #{awsui.$border-divider-list-width});
Copy link
Member Author

Choose a reason for hiding this comment

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

This negative space shenanigans are no longer needed because there is plenty of space for the focus outline.

@@ -380,19 +373,6 @@ $cell-negative-space-vertical: 2px;
color: awsui.$color-text-button-normal-active;
}

&-form {
Copy link
Member Author

@pan-kot pan-kot Dec 3, 2024

Choose a reason for hiding this comment

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

For editing cells we used overflow: visible on cell content together with negative margins so that the editor can take more space inside a cell and its focus outline is not cut off. Instead, in the refactored versions we just use different paddings for editing cells and there is no longer an issue with the outline.

Copy link
Member Author

Choose a reason for hiding this comment

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

Update: the overflow visible is still needed for editable content that includes dropdowns. I will contribute a new screenshot test to capture that.

@@ -90,6 +90,7 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem
collapseButtonLabel,
verticalAlign,
resizableColumns,
resizableStyle,
Copy link
Member Author

Choose a reason for hiding this comment

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

The resizableStyle replaces style to make the cell API better predictable so that no unexpected attributes can be assigned from the outside.

@@ -53,6 +53,7 @@

.table {
inline-size: 100%;
block-size: 100%;
Copy link
Member Author

Choose a reason for hiding this comment

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

This change does not affect the table itself - the size of the table is determined by the size of its content.

However, the table element needs the height set for cells height to take an effect, see discussion: https://stackoverflow.com/questions/3215553/make-a-div-fill-an-entire-table-cell.

white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
block-size: 100%;
Copy link
Member Author

Choose a reason for hiding this comment

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

Making cell content span to the entire cell height.

@pan-kot pan-kot marked this pull request as ready for review December 3, 2024 13:06
@pan-kot pan-kot requested a review from a team as a code owner December 3, 2024 13:06
@pan-kot pan-kot requested review from YueyingLu and removed request for a team December 3, 2024 13:06
@@ -101,6 +102,8 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem
const Element = isRowHeader ? 'th' : 'td';
const isVisualRefresh = useVisualRefresh();

resizableStyle = resizableColumns ? {} : resizableStyle;
Copy link
Contributor

Choose a reason for hiding this comment

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

this condition looks counterintuitive. you apply resizableStyle only when resizableColumns is false. why is that?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is taken as is from the current impl: https://github.com/cloudscape-design/components/blob/main/src/table/internal.tsx#L627

When resizable columns is on, the styles are assigned directly to cell nodes in src/table/column-widths-utils.ts and I think the properties like min-width and max-width are ignored.

I think there are further opportunities for refactoring and maybe this condition can be just removed but I'd not include this into the current PR.

@YueyingLu
Copy link
Member

Found 2 issues with manual testing:

  1. can not open select dropdown
Screen.Recording.2024-12-09.at.22.31.19.mov
  1. the input position seems a bit off
Screenshot 2024-12-09 at 22 28 15

@pan-kot
Copy link
Member Author

pan-kot commented Dec 9, 2024

@georgylobko, @YueyingLu

I added a new commit with the following changes:

  1. Reverted changes to negative vertical space. That is because in classic+compact the focus outline can be still cut off if the button is rendered inside content and the rows only have text content. The vertical paddings we use for table cell are under 2px whilst the focus outline offset for buttons is 2px - hence we need to do a trick so that the focus outline can fit.
  2. Reverted changes to visible overflow in editable cells. When a cell is editing the overflow is allowed so that components with dropdown like Select can be displayed correctly.

I will re-run the screenshot tests for these changes, too.

@pan-kot pan-kot added this pull request to the merge queue Dec 16, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 16, 2024
@pan-kot pan-kot added this pull request to the merge queue Dec 16, 2024
Merged via the queue into main with commit 468db9e Dec 16, 2024
39 checks passed
@pan-kot pan-kot deleted the editable-cells-wrapper branch December 16, 2024 20:23
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.

3 participants