Merged in feat/SW-1526-select-room-rate-focus (pull request #1732)
fix(SW-1526): adjusted scroll position when selecting a rate * fix: adjusted scroll position when selecting a rate * fix Approved-by: Michael Zetterberg
This commit is contained in:
@@ -16,15 +16,19 @@ export default function ScrollToList() {
|
|||||||
// Required to prevent the history.pushState on the first selection
|
// Required to prevent the history.pushState on the first selection
|
||||||
// to scroll user back to top
|
// to scroll user back to top
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
const SCROLL_OFFSET = 100
|
const SCROLL_OFFSET = 173 // summary on mobile is 163px
|
||||||
const selectedInputRoomCard = document.querySelector(
|
|
||||||
`.${styles.roomList} li:has(input[type=radio]:checked)`
|
const selectedRateCard: HTMLElement | null = document.querySelector(
|
||||||
|
`.${styles.roomList} label:has(input[type=radio]:checked)`
|
||||||
)
|
)
|
||||||
if (selectedInputRoomCard) {
|
|
||||||
const elementPosition =
|
if (selectedRateCard) {
|
||||||
selectedInputRoomCard.getBoundingClientRect().top
|
const elementPosition = selectedRateCard.getBoundingClientRect().top
|
||||||
|
const windowHeight = window.innerHeight
|
||||||
const offsetPosition =
|
const offsetPosition =
|
||||||
elementPosition + window.scrollY - SCROLL_OFFSET
|
elementPosition +
|
||||||
|
window.scrollY -
|
||||||
|
(windowHeight - selectedRateCard.offsetHeight - SCROLL_OFFSET)
|
||||||
|
|
||||||
window.scrollTo({
|
window.scrollTo({
|
||||||
top: offsetPosition,
|
top: offsetPosition,
|
||||||
|
|||||||
Reference in New Issue
Block a user