Skip to content

fix: Rigorizing the isStuck logic in container use-sticky-header#3239

Merged
dpitcock merged 7 commits intomainfrom
denpitco-table-sticky-header-fix
Feb 6, 2025
Merged

fix: Rigorizing the isStuck logic in container use-sticky-header#3239
dpitcock merged 7 commits intomainfrom
denpitco-table-sticky-header-fix

Conversation

@dpitcock
Copy link
Contributor

@dpitcock dpitcock commented Jan 31, 2025

Description

The previous isStuck logic was causing some unintended visual issues. When the isStuck condition was falsey set to true, it was removing the border radius on an internal element. This caused that element to overlay on top of its parent container, hiding the curved borders on the corners. This problem became more noticeable when the screen was viewed at different zoom levels.

The isStuck was being falsely set to true because why the top pixel values from sequentially calling .getBoundingClientRect() on a parent and nested child element might not return the same values, even if they are in the same position. Here are some reasons as to why:

  • Timing issues: The .getBoundingClientRect() method returns the size and position of the element relative to the viewport, and this can change slightly between the two calls if the element is being scrolled or resized during that time. This is especially true if the function is being called on scroll, as the element's position may have shifted slightly between the two calls.
  • Pixel differences and rounding: The values returned by .getBoundingClientRect() are in pixels, but there can be small differences in the decimal places due to browser rounding and the way floating-point numbers are represented in JavaScript. This can result in slight discrepancies, even if the elements are in the same position.
  • Subpixel rendering: Modern browsers use subpixel rendering to improve the appearance of text and graphics on high-resolution displays. This can result in slightly different bounding rectangle values, even for elements that appear to be in the same position.

To mitigate the issue, I wrap the returned values in a Math.round() function as I noticed the differences were often in the .00001's of pixels. This seems to resolve the issue.

broken-corner

Related links, issue #, if available: AWSUI-60267

How has this been tested?

  • unit test cases have been added for more conditionals
  • integ passes test
  • visual regression tests pass in dev pipeline
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.

@dpitcock dpitcock requested a review from a team as a code owner January 31, 2025 12:08
@dpitcock dpitcock requested review from johannes-weber and removed request for a team January 31, 2025 12:08
@dpitcock dpitcock marked this pull request as draft January 31, 2025 12:08
@codecov
Copy link

codecov bot commented Jan 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.44%. Comparing base (03d0574) to head (a51ee04).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3239   +/-   ##
=======================================
  Coverage   96.44%   96.44%           
=======================================
  Files         791      791           
  Lines       22568    22568           
  Branches     7385     7385           
=======================================
  Hits        21765    21765           
  Misses        796      796           
  Partials        7        7           

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

@dpitcock dpitcock changed the title fix: Removing top border radiuses of 0 in sticky header fix: Rigorizing the isStuck logic in container use-sticky-header Feb 5, 2025
@dpitcock dpitcock marked this pull request as ready for review February 5, 2025 19:14
@dpitcock dpitcock requested a review from avinashbot February 5, 2025 19:16
@dpitcock dpitcock marked this pull request as draft February 5, 2025 19:30
@dpitcock dpitcock added this pull request to the merge queue Feb 6, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 6, 2025
@dpitcock dpitcock added this pull request to the merge queue Feb 6, 2025
Merged via the queue into main with commit 6c6453d Feb 6, 2025
39 checks passed
@dpitcock dpitcock deleted the denpitco-table-sticky-header-fix branch February 6, 2025 18:09
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.

2 participants