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

Tabs: Prevent accidental overflow in indicator #61979

Merged
merged 9 commits into from
Jun 4, 2024

Conversation

t-hamano
Copy link
Contributor

@t-hamano t-hamano commented May 25, 2024

What?

This PR takes the decimal point into account when calculating the indicator's style (top, left, width, height) to prevent the indicator from overflowing.

Why?

My understanding is that offset{top|left|width|height} rounds the decimal point. This error may cause the indicator to overflow.

One problem I've seen is that inspector controls overflow on Windows OS.

inspector-controls-overflow

The reasons why this occurs are as follows.

  • The sidebar including inspector controls is 280px wide.
  • If the inspector control's content height is higher than the box height, a vertical scrollbar will appear.
  • In my Chrome, the scrollbar width is 17px. As a result, the width of the inspector control is 263px.
    image
  • Tab button width is 131.5px.
    image
  • The current logic rounds the decimal point in the indicator's style calculation, so when the button on the right is selected, the CSS variable has a value like this:
    image
  • The left and top values should be 131.5px, but they are actually 132px, so the indicator overflows by 1px.

How?

This could easily be solved by applying overflow:hidden to the TabListWrapper, but I chose to use getBoundingClientRect() to generate an accurate indicator style that takes decimal points into account.

In response to the feedback, a different approach was adopted - see the comments starting here for more details.

Testing Instructions

On MacOS, scrollbars have no physical width, so you won't be able to reproduce this problem by default. However, you should be able to reproduce the horizontal scroll bar issue on MacOS by following the steps below.

  • Set the value here to 279
  • Change OS settings to always display scroll bars
  • Select any block and open the block sidebar
  • Select the "Style" tab
    • trunk: CSS variable has the following value and causes an overflow.
      image
    • This PR: CSS variables contain decimal values and overflow should not occur
      image

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components OS Issues Issues or PRs that are related to OS specific problems labels May 25, 2024
@t-hamano t-hamano self-assigned this May 25, 2024
@t-hamano t-hamano requested a review from a team May 25, 2024 10:57
@t-hamano t-hamano marked this pull request as ready for review May 25, 2024 10:58
@t-hamano t-hamano requested a review from ajitbohra as a code owner May 25, 2024 10:58
Copy link

github-actions bot commented May 25, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: DaniGuardiola <daniguardiola@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

Flaky tests detected in 7d82754.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9234935079
📝 Reported issues:

@DaniGuardiola
Copy link
Contributor

DaniGuardiola commented May 25, 2024

Good catch, this won't work though. The use of offset sizes is intentional since the bounding rect approach causes glitches when combined with transformations and such. Offset sizing properties are not affected by this, and though subpixel precision would be nice it doesn't really seem that important. As a fix for this, I would simply propose doing -1 to the height and width so there's never an accidental overflow.

Thanks for noticing and sending a fix! Want to try my suggestion here?

@t-hamano
Copy link
Contributor Author

t-hamano commented May 26, 2024

Want to try my suggestion here?

Of course, please feel free to push 👍

@t-hamano
Copy link
Contributor Author

t-hamano commented Jun 3, 2024

@DaniGuardiola Is it possible to move the PR forward? I believe this issue needs to be fixed in WP6.6.

@DaniGuardiola
Copy link
Contributor

@t-hamano ah, yes, missed your last comment. Happy to push my proposed fix in a bit.

@DaniGuardiola
Copy link
Contributor

@t-hamano I've pushed the "naive" solution I proposed, but I am exploring a better solution where we could still have subpixel precision: https://stackblitz.com/edit/solidjs-templates-oerxnc?file=index.html,src%2FApp.tsx,src%2Findex.tsx

@DaniGuardiola
Copy link
Contributor

DaniGuardiola commented Jun 3, 2024

@t-hamano okay, this is the best I could do. I've tested it and it fixes the issue. I wish we could find a "perfect" solution with completely accurate values, but this'll have to do.

FYI, if you want to give it a last try, the goal is to get a computed "top" value that is accurate in the stackblitz I created (linked in the previous comment) - has to remain accurate also when transformed.

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Code-wise this makes sense to me 👍 Thanks!

@t-hamano if you could confirm this resolves the horizontal scroll issue in your testing, feel free to 🚢 .

@t-hamano
Copy link
Contributor Author

t-hamano commented Jun 4, 2024

@DaniGuardiola Thanks for the update!

In my environment, the width of the sidebar with the scrollbar is 263px, and I think it works as expected. The values ​​of each CSS variable changed by this PR are correct, right?

Before

image

After

image

@t-hamano t-hamano changed the title Tabs: Consider decimal point in indicator style Tabs: Prevent accidental overflow in indicator Jun 4, 2024
@DaniGuardiola
Copy link
Contributor

@t-hamano seems correct, yes.

@t-hamano t-hamano added the Backport to WP 6.6 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Jun 4, 2024
@t-hamano t-hamano merged commit a9fd33c into trunk Jun 4, 2024
62 checks passed
@t-hamano t-hamano deleted the tabs/decimal-point-indicator branch June 4, 2024 13:49
@github-actions github-actions bot added this to the Gutenberg 18.6 milestone Jun 4, 2024
westonruter added a commit that referenced this pull request Jun 4, 2024
…dd/on-async-directives

* 'trunk' of https://github.com/WordPress/gutenberg: (72 commits)
  Top toolbar: fix half a pixel artifacting of the bottom border. (#62225)
  Fix UI order for theme.json spacing sizes (#62199)
  Chore: Simplify a padding style on global styles. (#62291)
  Editor: Avoid remounts of `DocumentBar` (#62214)
  Add `default-spacing-sizes` and `default-font-sizes` options for classic themes (#62252)
  Editor: Cleanup styles and classnames (#62237)
  Scripts: Pin the @wordpress/scripts version to a version supported by WP 6.5 (#62234)
  Documentation: Better changelogs for the JSX transform upgrade (#62265)
  Chore: Simplify a padding style on dataviews. (#62276)
  MediaUpload: Remove dialog markup on close (#62168)
  Tabs: Prevent accidental overflow in indicator (#61979)
  Make edit site pagination buttons accessibly disabled. (#62267)
  Fix: Remove unused code from dataviews styles. (#62275)
  Re-enable React StrictMode (#61943)
  Inserter: Return the same items when the state and parameters don't change (#62263)
  Update instances of text-wrap: pretty to fall back to balance (#62233)
  Update: Slotfill documentation samples (links, code, and rephrase). (#62271)
  Try: Fix mover positioning. (#62226)
  [Mobile] - Image corrector - Check the path extension is a valid one (#62190)
  Update: Block styles documentation.
  ...
ellatrix pushed a commit that referenced this pull request Jun 11, 2024
* Tabs: Consider decimal point in indicator style

* Update changelog

* Naive solution.

* Subpixel size and position workaround.

* Add comment.

* Move CHANGELOG entry to Unreleased section

---------

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: DaniGuardiola <daniguardiola@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
ellatrix pushed a commit that referenced this pull request Jun 11, 2024
* Tabs: Consider decimal point in indicator style

* Update changelog

* Naive solution.

* Subpixel size and position workaround.

* Add comment.

* Move CHANGELOG entry to Unreleased section

---------

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: DaniGuardiola <daniguardiola@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
patil-vipul pushed a commit to patil-vipul/gutenberg that referenced this pull request Jun 17, 2024
* Tabs: Consider decimal point in indicator style

* Update changelog

* Naive solution.

* Subpixel size and position workaround.

* Add comment.

* Move CHANGELOG entry to Unreleased section

---------

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: DaniGuardiola <daniguardiola@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
@ellatrix ellatrix removed the Backport to WP 6.6 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Jun 18, 2024
@ellatrix
Copy link
Member

This was cherry-picked to the wp/6.6 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS Issues Issues or PRs that are related to OS specific problems [Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants