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

feat(table): added support for sticky column on right #5393

Merged
merged 5 commits into from Mar 7, 2023

Conversation

mattnolting
Copy link
Contributor

closes #5391

This PR adds right: var(--pf-c-table__sticky-column--Right, revert); to support righthand sticky column. If the table cell is the first child, --pf-c-table__sticky-column--Left is set to 0. If the table cell is the last child, --pf-c-table__sticky-column--Right is set to 0. There are no other instances in which either value should be 0.

@mattnolting mattnolting changed the base branch from v5 to main February 17, 2023 21:38
@patternfly-build
Copy link

patternfly-build commented Feb 17, 2023

@mcoker mcoker changed the title Fix table 5391 fix(table): added support for sticky column on right Feb 20, 2023
Copy link
Contributor

@mcoker mcoker left a comment

Choose a reason for hiding this comment

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

Left a comment - I'm wondering if the move to targeting the first-last child might break someone.

Comment on lines 22 to 31
&:where(:first-child) {
--pf-c-table__sticky-column--Left: 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just another option. I'm not tied to either way, but figured I'd mention it


I'm not super familiar with sticky tables, but is it a use case that a sticky column could not be the first child of the row? Either the previous children are hidden in some way or maybe aren't sticky, but some child in the middle of the row is? Here is an example with the third column sticky- https://codesandbox.io/s/great-christian-69uy1g?file=/index.htmlhttps://codesandbox.io/s/lucid-ardinghelli-7fnkro?file=/style.css

Another use case is where multiple columns are sticky, with regular positioned columns in-between. Here is an example with the first and third columns sticky - https://codesandbox.io/s/great-christian-69uy1g?file=/index.html

Those will break with this update, since it's going into main.

It looks like the first sticky (not necessarily first child) should be left: 0 by default, and any subsequent sticky (left) columns should have a left value set - assuming so, I wonder if it's better with a default of left: 0. I know that will mess up a right sticky column, since that will need to be unset, but with the page component, we have pf-m-sticky-top and pf-m-sticky-bottom. I'm wondering if maybe we could have left and right sticky, or maybe just .pf-m-sticky-column is left, and pf-m-sticky-column-right is right? Either now (to avoid breaking things), or for the long-term. I'm thinking it could be both, but I'm curious your opinion.

Looking at the react API, we set this for positioning:

First sticky column

isStickyColumn

Sticky siblings

isStickyColumn 
stickyLeftOffset="120px" // default is "0" from CSS

With this change as it is in the PR, I'm assuming we might do something like this?

First sticky column (on either side)

// Left
// ----
isStickyColumn 
// stickyLeftOffset="0" - would be needed if first sticky column isn't first-child

// Right
// -----
isStickyColumn 
// stickyRightOffset="0" - would be needed if first sticky column isn't last-child

Sticky siblings

// Left
// ----
isStickyColumn 
stickyLeftOffset="120px" // default is unset

// Right
// ----
isStickyColumn 
stickyRightOffset="120px" // default is unset

If we left the existing way it works as it is, and enabled isStickyColumnRight (or whatever), that could unset left, and set right: 0; and you'd have this API, and the codesandboxes I posted above would work as is.

First sticky column

// Left
// ----
isStickyColumn 

// Right
// -----
isStickyColumnRight

Sticky siblings

// Left
// ----
isStickyColumn 
stickyOffset="120px" // --pf-c-table__sticky-column--offset applies to left or right based on the modifier class

// Right
// ----
isStickyColumnRight
stickyOffset="120px" // --pf-c-table__sticky-column--offset applies to left or right based on the modifier class

To keep it from being breaking, we could keep stickyLeftOffset as it is and remove in v5, if that seems like an ok approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since React is resetting left/right variables, I think we can move this to v5 pf-c-table__sticky-left/right

Copy link
Contributor

Choose a reason for hiding this comment

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

In the CSS, I see __sticky-left, __sticky-right grouped with common styles, then both classes modify the same left property later in different selectors, and the vars are named --pf-c-table__sticky--cell - that says to me that sticky is the element, the sticky direction is the modifier, and then the vars could match:

[...]
--pf-c-table__sticky-header--Left: auto;
--pf-c-table__sticky-header--Right: auto;
--pf-c-table__sticky-header--m-left--Left: 0;
--pf-c-table__sticky-header--m-right--Right: 0;
[...]

.pf-c-table__sticky-header {
  // common styles
  position: var(--pf-c-table__sticky-header--Position);
  left: var(--pf-c-table__sticky-header--Left); // or just omit this
  right: var(--pf-c-table__sticky-header--Right); // or just omit this
  [...]
  
  &.pf-m-left {
    --pf-c-table__sticky-header--Left: var(--pf-c-table__sticky-header--m-left--Left); // or style as `left: var(--pf-c-table__sticky-header--m-left--Left);` if `left` is omitted on the parent.
  }

  &.pf-m-right {
    --pf-c-table__sticky-header--Right: var(--pf-c-table__sticky-header--m-right--Right); // or style as `right: var(--pf-c-table__sticky-header--m-right--Right);` if `right` is omitted on the parent.  }
}

That also implies a sticky element can be either variant, which I don't see why it couldn't be - in the same way sections and things are sticky when you reach them in scrollable regions - https://codesandbox.io/s/recursing-tristan-co5vc4?file=/fonts.css

Or are there other reasons you think they should be separate BEM elements?

@@ -13,12 +12,21 @@

.pf-c-table__sticky-column {
Copy link
Contributor

Choose a reason for hiding this comment

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

unrelated - does this need to be scoped in .pf-c-table?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it needs a higher specificity

src/patternfly/components/Table/table-scrollable.scss Outdated Show resolved Hide resolved
Comment on lines 22 to 31
&:where(:first-child) {
--pf-c-table__sticky-column--Left: 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In the CSS, I see __sticky-left, __sticky-right grouped with common styles, then both classes modify the same left property later in different selectors, and the vars are named --pf-c-table__sticky--cell - that says to me that sticky is the element, the sticky direction is the modifier, and then the vars could match:

[...]
--pf-c-table__sticky-header--Left: auto;
--pf-c-table__sticky-header--Right: auto;
--pf-c-table__sticky-header--m-left--Left: 0;
--pf-c-table__sticky-header--m-right--Right: 0;
[...]

.pf-c-table__sticky-header {
  // common styles
  position: var(--pf-c-table__sticky-header--Position);
  left: var(--pf-c-table__sticky-header--Left); // or just omit this
  right: var(--pf-c-table__sticky-header--Right); // or just omit this
  [...]
  
  &.pf-m-left {
    --pf-c-table__sticky-header--Left: var(--pf-c-table__sticky-header--m-left--Left); // or style as `left: var(--pf-c-table__sticky-header--m-left--Left);` if `left` is omitted on the parent.
  }

  &.pf-m-right {
    --pf-c-table__sticky-header--Right: var(--pf-c-table__sticky-header--m-right--Right); // or style as `right: var(--pf-c-table__sticky-header--m-right--Right);` if `right` is omitted on the parent.  }
}

That also implies a sticky element can be either variant, which I don't see why it couldn't be - in the same way sections and things are sticky when you reach them in scrollable regions - https://codesandbox.io/s/recursing-tristan-co5vc4?file=/fonts.css

Or are there other reasons you think they should be separate BEM elements?

@mattnolting mattnolting force-pushed the fix-table-5391 branch 4 times, most recently from 51cae1a to cacb6ba Compare March 6, 2023 21:05
@mattnolting mattnolting requested a review from mcoker March 6, 2023 21:08
@mattnolting
Copy link
Contributor Author

@mcoker Updated. sticky-header is being used to define a thead, so sticky-cell is more descriptive. LMK your thoughts.

Copy link
Contributor

@mcoker mcoker left a comment

Choose a reason for hiding this comment

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

Just one nit - LGTM!

src/patternfly/components/Table/table-scrollable.scss Outdated Show resolved Hide resolved
@mcoker mcoker changed the title fix(table): added support for sticky column on right feat(table): added support for sticky column on right Mar 7, 2023
@mcoker mcoker merged commit 000420a into patternfly:v5 Mar 7, 2023
@patternfly-build
Copy link

🎉 This PR is included in version 5.0.0-alpha.29 🎉

The release is available on:

Your semantic-release bot 📦🚀

mattnolting added a commit to mattnolting/patternfly that referenced this pull request May 18, 2023
mattnolting added a commit to mattnolting/patternfly that referenced this pull request Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug - Table - Sticky column th needs right value
4 participants