From 493fb7ac724d4af2f3e466d20126b973a69a66ef Mon Sep 17 00:00:00 2001 From: Aqib Zaib Date: Fri, 13 Sep 2024 14:49:09 +0500 Subject: [PATCH 1/2] Fix dropdown cutoff issue for long text in mobile view (#7035) --- apps/site/components/Common/Select/index.tsx | 31 ++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/apps/site/components/Common/Select/index.tsx b/apps/site/components/Common/Select/index.tsx index 3d12632e7ed20..79567c2289e53 100644 --- a/apps/site/components/Common/Select/index.tsx +++ b/apps/site/components/Common/Select/index.tsx @@ -4,7 +4,7 @@ import { ChevronDownIcon } from '@heroicons/react/24/outline'; import * as ScrollPrimitive from '@radix-ui/react-scroll-area'; import * as SelectPrimitive from '@radix-ui/react-select'; import classNames from 'classnames'; -import { useId, useMemo } from 'react'; +import { useEffect, useId, useMemo, useRef, useState } from 'react'; import type { FC } from 'react'; import type { FormattedMessage } from '@/types'; @@ -51,7 +51,9 @@ const Select: FC = ({ ariaLabel, }) => { const id = useId(); - + const spanRef = useRef(null); + const [elementWidth, setElementWidth] = useState(0); + const [windowWidth, setWindowWidth] = useState(window.innerWidth); const mappedValues = useMemo(() => { let mappedValues = values; @@ -66,6 +68,24 @@ const Select: FC = ({ return mappedValues; }, [values]); + useEffect(() => { + const handleResize = () => { + setWindowWidth(window.innerWidth); + }; + + window.addEventListener('resize', handleResize); + + return () => { + window.removeEventListener('resize', handleResize); + }; + }, []); + + useEffect(() => { + if (spanRef.current) { + setElementWidth(spanRef.current.offsetWidth); + } + }, [windowWidth]); + return ( = ({ { [styles.inline]: inline }, className )} + ref={spanRef} > {label && (