diff --git a/jest.config.js b/jest.config.js index 82b2b587e..0749f4f71 100644 --- a/jest.config.js +++ b/jest.config.js @@ -27,6 +27,7 @@ module.exports = { "!src/layouts/address-vehicles/address-vehicles-question/address-vehicles-question.vue", "!src/common-components/dropdown-question/dropdown-question.vue", "!src/common-components/textbox-question/textbox-question.vue", + "!src/ux-components/alert\alert.vue", "!src/helpers/validation-rules.js", // END ], // ! means exclude from coverage. diff --git a/src/common-components/funnel-footer/funnel-footer.spec.js b/src/common-components/funnel-footer/funnel-footer.spec.js index 30dc14fd3..198fa5657 100644 --- a/src/common-components/funnel-footer/funnel-footer.spec.js +++ b/src/common-components/funnel-footer/funnel-footer.spec.js @@ -62,6 +62,7 @@ describe("funnel-footer.vue", () => { const mockMixin = { methods: { - getCmsContent: jest.fn() + getCmsContent: jest.fn(), + getFooterInfoBoxHeight: jest.fn(()=>80) } } \ No newline at end of file diff --git a/src/common-components/funnel-footer/funnel-footer.vue b/src/common-components/funnel-footer/funnel-footer.vue index a09aa9cd2..9c98a78b8 100644 --- a/src/common-components/funnel-footer/funnel-footer.vue +++ b/src/common-components/funnel-footer/funnel-footer.vue @@ -63,7 +63,7 @@ export default { } }, mounted() { - this.paddingHeight = document.querySelector(".footer #infoBox").offsetHeight + 24; + this.paddingHeight = this.getFooterInfoBoxHeight() + 24; this.$nextTick(() => { window.addEventListener('resize', this.onResize); }) diff --git a/src/layouts/address-lookup/address-lookup.vue b/src/layouts/address-lookup/address-lookup.vue index 0152b94fd..fca2b500c 100644 --- a/src/layouts/address-lookup/address-lookup.vue +++ b/src/layouts/address-lookup/address-lookup.vue @@ -12,27 +12,27 @@
- - - -
- - @@ -32,7 +32,7 @@ diff --git a/src/mixins/base-mixin.js b/src/mixins/base-mixin.js index d8df53281..b24370911 100644 --- a/src/mixins/base-mixin.js +++ b/src/mixins/base-mixin.js @@ -42,6 +42,9 @@ export default { el && el.focus(); } }, + getFooterInfoBoxHeight() { + return document.querySelector(".footer #infoBox").offsetHeight; + } }, computed: { storeActions() { diff --git a/src/ux-components/alert/alert.spec.js b/src/ux-components/alert/alert.spec.js index 6f4bb9822..59becf922 100644 --- a/src/ux-components/alert/alert.spec.js +++ b/src/ux-components/alert/alert.spec.js @@ -66,6 +66,7 @@ describe("alert.vue", () => { const mockMixin = { methods: { - getCmsContent: jest.fn() + getCmsContent: jest.fn(), + getFooterInfoBoxHeight: jest.fn(()=> 80), } } \ No newline at end of file diff --git a/src/ux-components/alert/alert.vue b/src/ux-components/alert/alert.vue index faff0861c..5c0d7a270 100644 --- a/src/ux-components/alert/alert.vue +++ b/src/ux-components/alert/alert.vue @@ -52,6 +52,10 @@ export default { cmsWidgetName: String, manualHeadline: String, manualCopy: String, + shouldScrollToOnMount: { + type: Boolean, + default: true + }, }, computed: { alertHeadline(){ @@ -85,8 +89,35 @@ export default { // first split would return 'estimate,provide your VIN' // second split would return 'provide your VIN' return copy.split(':')[1].split(',')[1]; - } + }, + ensureAlertIsInViewPort() { + if (this.shouldScrollToOnMount && this.$el.style.display != 'none') { + var footerHeight = this.getFooterInfoBoxHeight(); + if (!this.isAlertInViewport(footerHeight)) { + this.scrollContainerToAlert(footerHeight); + } + } + }, + isAlertInViewport(footerHeight) { + const rect = this.$el.getBoundingClientRect(); + return ( + rect.top >= 0 && + // remove footerHeight from window height to avoid items being hidden behind footer + rect.bottom <= (window.innerHeight - footerHeight || document.documentElement.clientHeight - footerHeight) + ); + }, + scrollContainerToAlert(footerHeight) { + // alert position on page + height of alert + footer height + var scrollToHeight = this.$el.scrollHeight + this.$el.offsetHeight + footerHeight; + // find the div wrapped by the form element - this is the scrollable container + // should be a more future-proof selector in case of CSS class changes + var pageContainerScrollable = document.querySelector('form > div'); + pageContainerScrollable.scrollTo(0, scrollToHeight); + }, }, + mounted() { + this.ensureAlertIsInViewPort(); + } };