Skip to content

Commit

Permalink
fix: sticky buttons on scroll for better user experience
Browse files Browse the repository at this point in the history
  • Loading branch information
dyersituations committed Jun 19, 2024
1 parent 159c2d5 commit 67c3ea8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/components/WwwFrame/WwwPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<slot name="tertiary"></slot>
<slot></slot>
</main>
<the-footer :style="footerStyle" />
<the-footer />
<the-basket-bar />
<cookie-banner />
</div>
Expand Down Expand Up @@ -58,10 +58,6 @@ export default {
type: [Object, String],
default: '',
},
footerStyle: {
type: [Object, String],
default: '',
},
},
data() {
return {
Expand Down
20 changes: 18 additions & 2 deletions src/pages/Checkout/CheckoutPage.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<www-page :footer-style="{ ...(showCheckoutStickyExperiment && { 'padding-bottom': '125px' }) }">
<www-page>
<kv-page-container
id="checkout-slim"
data-testid="checkout"
Expand Down Expand Up @@ -98,6 +98,8 @@

<basket-verification />

<div ref="checkoutActionsThreshold"></div>

<div
id="checkout-actions"
class="checkout-actions md:tw-text-right"
Expand Down Expand Up @@ -308,6 +310,7 @@
import { gql } from '@apollo/client';
import _get from 'lodash/get';
import _filter from 'lodash/filter';
import _throttle from 'lodash/throttle';
import numeral from 'numeral';
import { readBoolSetting } from '@/util/settingsUtils';
import { preFetchAll } from '@/util/apolloPreFetch';
Expand Down Expand Up @@ -458,6 +461,8 @@ export default {
depositIncentiveAmountToLend: 0,
depositIncentiveExperimentEnabled: false,
checkoutStickyExperimentEnabled: false,
isAboveCheckoutActions: false,
checkIsAboveCheckoutActionsThrottled: _throttle(this.checkIsAboveCheckoutActions, 100),
};
},
apollo: {
Expand Down Expand Up @@ -665,13 +670,20 @@ export default {
});
// end challenge code
}
this.checkIsAboveCheckoutActions();
window.addEventListener('scroll', this.checkIsAboveCheckoutActionsThrottled);
},
beforeDestroy() {
window.removeEventListener('scroll', this.checkIsAboveCheckoutActionsThrottled);
},
computed: {
showCheckoutStickyExperiment() {
return this.checkoutStickyExperimentEnabled
&& !this.checkingOutAsGuest
&& !this.showKivaCreditButton
&& !this.isLoggedIn;
&& !this.isLoggedIn
&& this.isAboveCheckoutActions;
},
isUpsellUnder100() {
const amountLeft = this.upsellLoan?.loanAmount
Expand Down Expand Up @@ -798,6 +810,10 @@ export default {
},
},
methods: {
checkIsAboveCheckoutActions() {
const thresholdClientRectTop = this.$refs?.checkoutActionsThreshold?.getBoundingClientRect()?.top;
this.isAboveCheckoutActions = thresholdClientRectTop > window?.innerHeight;
},
openMatchedLoansLightbox() {
this.$kvTrackEvent('Basket', 'click-must-deposit-message-cta', 'Learn more');
this.showMatchedLoansLightbox = true;
Expand Down

0 comments on commit 67c3ea8

Please sign in to comment.