Merged in fix/SW-1122-breakfast-text-equal-height (pull request #1098)
fix(SW-1122): fix equal breakfast text height for non availability cards * fix(SW-1122): fix equal breakfast text height for non availability cards Approved-by: Pontus Dreij Approved-by: Niclas Edenvin
This commit is contained in:
@@ -8,7 +8,9 @@ import RateSummary from "./RateSummary"
|
||||
import RoomCard from "./RoomCard"
|
||||
import {
|
||||
getHotelReservationQueryParams,
|
||||
rateCardEqualHeightSelector,
|
||||
RATE_CARD_EQUAL_HEIGHT_CLASS,
|
||||
RATE_CARDS_AVAILABLE_HEIGHT_CLASS,
|
||||
RATE_CARDS_NOT_AVAILABLE_HEIGHT_CLASS,
|
||||
} from "./utils"
|
||||
|
||||
import styles from "./roomSelection.module.css"
|
||||
@@ -34,41 +36,44 @@ export default function RoomSelection({
|
||||
const equalizePriceOptionHeights = useCallback(() => {
|
||||
if (!roomRefs.current.length) return
|
||||
|
||||
const optionsSelector = `.${RATE_CARD_EQUAL_HEIGHT_CLASS}`
|
||||
const availableSelector = `.${RATE_CARDS_AVAILABLE_HEIGHT_CLASS}`
|
||||
const notAvailableSelector = `.${RATE_CARDS_NOT_AVAILABLE_HEIGHT_CLASS}`
|
||||
const DEFAULT_RATE_CARD_HEIGHT = 420
|
||||
|
||||
const maxOptionHeights: number[] = []
|
||||
let maxPriceCardHeight = DEFAULT_RATE_CARD_HEIGHT
|
||||
|
||||
roomRefs.current.forEach((room) => {
|
||||
const options = room.querySelectorAll<HTMLDivElement>(
|
||||
`.${rateCardEqualHeightSelector}`
|
||||
)
|
||||
options.forEach((option) => {
|
||||
const options = room.querySelectorAll<HTMLDivElement>(optionsSelector)
|
||||
options.forEach((option, i) => {
|
||||
option.style.height = "auto"
|
||||
const optionHeight = option.getBoundingClientRect().height
|
||||
maxOptionHeights[i] = Math.max(maxOptionHeights[i] || 0, optionHeight)
|
||||
})
|
||||
|
||||
const priceCard = room.querySelector(availableSelector) as HTMLElement
|
||||
if (priceCard) {
|
||||
const priceCardHeight = priceCard.getBoundingClientRect().height
|
||||
maxPriceCardHeight = Math.max(maxPriceCardHeight, priceCardHeight)
|
||||
}
|
||||
})
|
||||
|
||||
const numOptions =
|
||||
roomRefs.current[0]?.querySelectorAll<HTMLDivElement>(
|
||||
`.${rateCardEqualHeightSelector}`
|
||||
).length || 0
|
||||
|
||||
for (let i = 0; i < numOptions; i++) {
|
||||
let maxHeight = 0
|
||||
|
||||
roomRefs.current.forEach((room) => {
|
||||
const option = room.querySelectorAll<HTMLDivElement>(
|
||||
`.${rateCardEqualHeightSelector}`
|
||||
)[i]
|
||||
roomRefs.current.forEach((room) => {
|
||||
const options = room.querySelectorAll<HTMLDivElement>(optionsSelector)
|
||||
options.forEach((option, i) => {
|
||||
if (option) {
|
||||
maxHeight = Math.max(maxHeight, option.offsetHeight)
|
||||
option.style.height = `${maxOptionHeights[i]}px`
|
||||
}
|
||||
})
|
||||
|
||||
roomRefs.current.forEach((room) => {
|
||||
const option = room.querySelectorAll<HTMLDivElement>(
|
||||
`.${rateCardEqualHeightSelector}`
|
||||
)[i]
|
||||
if (option) {
|
||||
option.style.height = `${maxHeight}px`
|
||||
}
|
||||
})
|
||||
}
|
||||
const noPriceCard = room.querySelector(
|
||||
notAvailableSelector
|
||||
) as HTMLElement
|
||||
if (noPriceCard) {
|
||||
noPriceCard.style.height = `${maxPriceCardHeight}px`
|
||||
}
|
||||
})
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user