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
|
||||
// to scroll user back to top
|
||||
requestAnimationFrame(() => {
|
||||
const SCROLL_OFFSET = 100
|
||||
const selectedInputRoomCard = document.querySelector(
|
||||
`.${styles.roomList} li:has(input[type=radio]:checked)`
|
||||
const SCROLL_OFFSET = 173 // summary on mobile is 163px
|
||||
|
||||
const selectedRateCard: HTMLElement | null = document.querySelector(
|
||||
`.${styles.roomList} label:has(input[type=radio]:checked)`
|
||||
)
|
||||
if (selectedInputRoomCard) {
|
||||
const elementPosition =
|
||||
selectedInputRoomCard.getBoundingClientRect().top
|
||||
|
||||
if (selectedRateCard) {
|
||||
const elementPosition = selectedRateCard.getBoundingClientRect().top
|
||||
const windowHeight = window.innerHeight
|
||||
const offsetPosition =
|
||||
elementPosition + window.scrollY - SCROLL_OFFSET
|
||||
elementPosition +
|
||||
window.scrollY -
|
||||
(windowHeight - selectedRateCard.offsetHeight - SCROLL_OFFSET)
|
||||
|
||||
window.scrollTo({
|
||||
top: offsetPosition,
|
||||
|
||||
Reference in New Issue
Block a user