From 684fb0c4d3af8c3cdeae0b90bebb8c637af71099 Mon Sep 17 00:00:00 2001 From: Pontus Dreij Date: Mon, 2 Dec 2024 13:00:52 +0100 Subject: [PATCH] fix(SW-1003): Moved tooltip on mobile and fixed bug with touch/click --- .../SelectRate/RoomFilter/index.tsx | 67 ++++++++++++++----- components/TempDesignSystem/Tooltip/index.tsx | 16 ++++- types/components/tooltip.ts | 1 + 3 files changed, 66 insertions(+), 18 deletions(-) diff --git a/components/HotelReservation/SelectRate/RoomFilter/index.tsx b/components/HotelReservation/SelectRate/RoomFilter/index.tsx index f2ae9d57f..c800c3cc9 100644 --- a/components/HotelReservation/SelectRate/RoomFilter/index.tsx +++ b/components/HotelReservation/SelectRate/RoomFilter/index.tsx @@ -4,8 +4,10 @@ import { zodResolver } from "@hookform/resolvers/zod" import { useCallback, useEffect, useMemo } from "react" import { FormProvider, useForm } from "react-hook-form" import { useIntl } from "react-intl" +import { useMediaQuery } from "usehooks-ts" import { z } from "zod" +import { InfoCircleIcon } from "@/components/Icons" import CheckboxChip from "@/components/TempDesignSystem/Form/FilterChip/Checkbox" import Body from "@/components/TempDesignSystem/Text/Body" import Caption from "@/components/TempDesignSystem/Text/Caption" @@ -25,6 +27,8 @@ export default function RoomFilter({ onFilter, filterOptions, }: RoomFilterProps) { + const isAboveMobile = useMediaQuery("(min-width: 768px)") + const initialFilterValues = useMemo( () => filterOptions.reduce( @@ -55,6 +59,8 @@ export default function RoomFilter({ id: "Pet-friendly rooms have an additional fee of 20 EUR per stay", }) + const showTooltip = isAboveMobile && petFriendly + const submitFilter = useCallback(() => { const data = getValues() onFilter(data) @@ -77,19 +83,50 @@ export default function RoomFilter({
- - {intl.formatMessage({ id: "Filter" })} - - - {Object.entries(selectedFilters) - .filter(([_, value]) => value) - .map(([key]) => intl.formatMessage({ id: key })) - .join(", ")} - + {!isAboveMobile ? ( + + + + + {intl.formatMessage({ id: "Filter" })} + + + {Object.entries(selectedFilters) + .filter(([_, value]) => value) + .map(([key]) => intl.formatMessage({ id: key })) + .join(", ")} + + + ) : ( + <> + + {intl.formatMessage({ id: "Filter" })} + + + {Object.entries(selectedFilters) + .filter(([_, value]) => value) + .map(([key]) => intl.formatMessage({ id: key })) + .join(", ")} + + + )}
{intl.formatMessage( @@ -118,11 +155,11 @@ export default function RoomFilter({ disabled={isDisabled} selected={getValues(code)} Icon={getIconForFeatureCode(code)} - hasTooltip={isPetRoom} + hasTooltip={isPetRoom && isAboveMobile} /> ) - return isPetRoom ? ( + return showTooltip ? ( ({ position, arrow, children, + isTouchable = false, }: PropsWithChildren>) { const className = tooltipVariants({ position, arrow }) const [isActive, setIsActive] = useState(false) function handleToggle() { - setIsActive(!isActive) + setIsActive((prevState) => !prevState) + } + + function handleKeyDown(event: React.KeyboardEvent) { + if (event.key === "Enter" || event.key === " ") { + event.preventDefault() + handleToggle() + } } return ( @@ -27,8 +35,10 @@ export function Tooltip

({ className={styles.tooltipContainer} role="tooltip" aria-label={text} - onClick={handleToggle} - onTouchStart={handleToggle} + tabIndex={0} + onClick={isTouchable ? undefined : handleToggle} + onTouchStart={isTouchable ? handleToggle : undefined} + onKeyDown={handleKeyDown} data-active={isActive} >

diff --git a/types/components/tooltip.ts b/types/components/tooltip.ts index ff7ed6ecc..622db4c2c 100644 --- a/types/components/tooltip.ts +++ b/types/components/tooltip.ts @@ -18,4 +18,5 @@ export interface TooltipProps

{ text?: string position: P arrow: ValidArrow

+ isTouchable?: boolean }