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

only make order summary sticky when it's not longer than view #47680

Merged
merged 9 commits into from
May 22, 2024

Conversation

senadir
Copy link
Member

@senadir senadir commented May 21, 2024

This PR changes when we mark an element as sticky, for the order summary, we should only make it sticky if its height is smaller than the viewport. For this, I created a new hook useObservedViewport that should help detect its height and other elements' height. This will be needed once we start solving other zoom issues https://github.com/woocommerce/woocommerce/issues?q=is:open+is:issue+label:%22focus:+accessibility%22+label:%22team:+Rubik%22+zoom

How to test the changes in this Pull Request:

  1. Add some items to cart and go to Checkout.
  2. Reduce the window height so that it's smaller than the order summary.
  3. Try scrolling, the order summary should not be sticky.
  4. Collapse the items in order summary and expand the window height.
  5. Try scrolling now, the order summary should be sticky.

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Comment

This is a follow up to another PR not yet shipped.

@senadir senadir self-assigned this May 21, 2024
@woocommercebot woocommercebot requested review from a team and wavvves and removed request for a team May 21, 2024 16:22
@senadir senadir added type: bug The issue is a confirmed bug. focus: accessibility The issue/PR is related to accessibility. focus: checkout Issues related to checkout page. team: Rubik Store API checkout endpoints, Mini-Cart, Cart and Checkout related issues labels May 21, 2024
Copy link
Contributor

github-actions bot commented May 21, 2024

Hi @nielslange, @wavvves,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

Copy link
Contributor

Hi @wavvves,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

Comment on lines 42 to 50
const element = observedRef.current;
const resizeObserver = new ResizeObserver( ( entries ) => {
entries.forEach( ( entry ) => {
if ( entry.target === element ) {
const { height, width } = entry.contentRect;
setObservedElement( { height, 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 resizer will track the element height changes (collapse vs expand, add items to it...).

Comment on lines +52 to +72
const intersectionObserver = new IntersectionObserver(
( entries ) => {
entries.forEach( ( entry ) => {
const { height, width } = entry.boundingClientRect;
setObservedElement( { height, width } );
if ( entry.target.ownerDocument.defaultView ) {
setViewWindow( {
height: entry.target.ownerDocument.defaultView
?.innerHeight,
width: entry.target.ownerDocument.defaultView
?.innerWidth,
} );
}
} );
},
{
root: null,
rootMargin: '0px',
threshold: 1,
}
);
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 will observe the element when it intersect with the page and is visible in it, useful for cases where the page size changes.

Copy link
Contributor

github-actions bot commented May 21, 2024

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

@@ -0,0 +1,4 @@
Significance: patch
Type: fix
Comment: This is a follow up to another PR not yet shipped.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi Nadir, quick question, can you link the other PR please? Can this be reviewed and merged first?

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 other PR is already merged

Copy link
Member Author

Choose a reason for hiding this comment

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

@senadir senadir requested a review from wavvves May 22, 2024 13:43
@senadir senadir closed this May 22, 2024
@senadir senadir reopened this May 22, 2024
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label May 22, 2024
@senadir senadir force-pushed the fix/only-sticky-summary-if-smaller-than-screen branch from 5140f0f to 3746955 Compare May 22, 2024 15:25
@nielslange nielslange self-requested a review May 22, 2024 15:33
Copy link
Member

@nielslange nielslange left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, @senadir. I've tested this PR against the following browsers:

  • Chrome 14.3
  • Firefox 126.0
  • Safari 17.3
  • Microsoft Edge 125.0.2535.51

The behaviour is consistent across all browsers. However, there is a variation in behaviour depending on whether the user is logged in or a guest.

Guest user:

Screen Capture on 2024-05-23 at 00-07-01

Logged-in user:

Screen Capture on 2024-05-23 at 00-04-21

@senadir senadir enabled auto-merge (squash) May 22, 2024 21:20
Copy link
Contributor

@opr opr 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 to me - please add a followup issue to fix the TS error on line 19 of checkout-totals-block/frontend

@senadir senadir merged commit 34f8c65 into trunk May 22, 2024
36 checks passed
@senadir senadir deleted the fix/only-sticky-summary-if-smaller-than-screen branch May 22, 2024 22:09
@github-actions github-actions bot added this to the 9.0.0 milestone May 22, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label May 22, 2024
@nigeljamesstevenson nigeljamesstevenson added needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: accessibility The issue/PR is related to accessibility. focus: checkout Issues related to checkout page. needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris team: Rubik Store API checkout endpoints, Mini-Cart, Cart and Checkout related issues type: bug The issue is a confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants