Skip to content

fix(table): fix toggle vertical alignment#7722

Merged
nicolethoen merged 3 commits intopatternfly:mainfrom
mcoker:issue-7699
Aug 5, 2025
Merged

fix(table): fix toggle vertical alignment#7722
nicolethoen merged 3 commits intopatternfly:mainfrom
mcoker:issue-7699

Conversation

@mcoker
Copy link
Contributor

@mcoker mcoker commented Aug 4, 2025

fixes #7699

The general stragy in this PR:

  • Remove the custom padding that is on the .#{$table}__th.#{$table}__toggle element (the <th> that wraps the toggle button in <thead>), so that the padding matches the adjacent <th> cells

    --#{$table}__thead__toggle--PaddingBlockStart: var(--#{$table}--cell--Padding--base); // TODO - remove thead toggle custom padding in breaking change
    --#{$table}__thead__toggle--PaddingBlockEnd: var(--#{$table}--cell--Padding--base); // TODO - remove thead toggle custom padding in breaking change

  • Assign negative block margins to the button that are equal to the button's padding, so that only the button's content (the text/icon) takes up space in the cell. This should match other stuff in adjacent <th> cells since <th> cells either have text or the .#{$table}__button element, which also uses a negative block margin to make it align with adjacent cells.

    @at-root .#{$table}__thead & {
    .#{$button} {
    margin-block-start: calc(var(--#{$button}--PaddingBlockStart) * -1);
    margin-block-end: calc(var(--#{$button}--PaddingBlockEnd) * -1);

  • Give the button a line-height of 1lh, which will make its line-height the computed line-height of its parent. This handles the font-size discrepancy between a plain button (font-size: 14px) and the <th> cells (font-size: 12px). Previously the text box in the plain button was 21px (14px * 1.5lh), now it's 18px (12px * 1.5lh), which matches adjacent cells. The icon is still technically bigger but it doesn't take up more space than smaller text around it.

  • Applied the same line-height fix as abive to the column sort help button because it was causing the cell it's in to be slightly misaligned with adjacent cells.

    .#{$button} {
    --#{$button}--LineHeight: 1lh;
    }


I tested the following

  1. Regular, non-sortable tables with the expand toggle
  2. Sortable tables with the expand toggle
  3. 1 & 2 with .pf-m-compact. For this you need to be make sure .pf-m-small is on the toggle button (reduces the padding) since that variant is used with compact tables. Looks like the [the change to use pf-m-small in react(https://github.com/fix(table): add pf-m-small to expandable toggle on small tables patternfly-react#11947) is going in with the patch release. It shouldn't matter what size the button is though, it's always offset by its own padding, so it should work with whatever padding is on the button.

@patternfly-build
Copy link
Collaborator

patternfly-build commented Aug 4, 2025

@nicolethoen
Copy link
Contributor

When I compare this demo in your PR to the equivalent demo in pf-core-staging, the alignment doesn't appear improved in your PR.

Is this updated spacing what you'd expect in your PR?

Copy link
Member

@evwilkin evwilkin left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for the clear description of changes & inline notes for future breaking changes 👏

@mcoker
Copy link
Contributor Author

mcoker commented Aug 5, 2025

@nicolethoen thanks! The vertical alignment should have been good, but there was a bug in the button width causing a horizontal alignment issue. Would you mind giving it another look?

@mcoker mcoker requested a review from nicolethoen August 5, 2025 15:08
Copy link
Member

@srambach srambach left a comment

Choose a reason for hiding this comment

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

Looks good now - regression test report (for tables) at https://drive.google.com/file/d/1N3X-Q7P4fSbSnA9WkoxpahmKh-D0Zbe2/view?usp=sharing just shows expected differences

@nicolethoen nicolethoen merged commit 642c3ee into patternfly:main Aug 5, 2025
4 checks passed
nicolethoen pushed a commit that referenced this pull request Aug 5, 2025
* fix(table): fix toggle vertical alignment

* chore(table): fix lh for column help button

* chore(table): fix thead expand button min-width
@patternfly-build
Copy link
Collaborator

🎉 This PR is included in version 6.3.0-prerelease.47 🎉

The release is available on:

Your semantic-release bot 📦🚀

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 (expandable) - toggle misalignment in THead

7 participants