Skip to content

Commit a53a8c0

Browse files
committed
feat: avoid rendering MobileCloseBar on desktop
1 parent 9d69741 commit a53a8c0

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

src/components/LanguagePicker/index.tsx

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import {
1919
import { Button } from "@/components/Buttons"
2020
import { BaseLink } from "@/components/Link"
2121

22+
import { isMobile } from "@/lib/utils/isMobile"
23+
2224
import MenuItem from "./MenuItem"
2325
import NoResultsCallout from "./NoResultsCallout"
2426
import { useLanguagePicker } from "./useLanguagePicker"
@@ -59,6 +61,23 @@ const LanguagePicker = ({
5961
inputRef.current?.focus()
6062
})
6163

64+
const MobileCloseBar = () => {
65+
return (
66+
<Flex
67+
justifyContent="end"
68+
hideFrom="md"
69+
position="sticky"
70+
zIndex="sticky"
71+
top="0"
72+
bg="background.base"
73+
>
74+
<Button p="4" variant="ghost" alignSelf="end" onClick={() => onClose()}>
75+
{t("common:close")}
76+
</Button>
77+
</Flex>
78+
)
79+
}
80+
6281
return (
6382
<Menu isLazy placement={placement} autoSelect={false} {...disclosure}>
6483
{children}
@@ -76,23 +95,8 @@ const LanguagePicker = ({
7695
{...props}
7796
>
7897
{/* Mobile Close bar */}
79-
<Flex
80-
justifyContent="end"
81-
hideFrom="md"
82-
position="sticky"
83-
zIndex="sticky"
84-
top="0"
85-
bg="background.base"
86-
>
87-
<Button
88-
p="4"
89-
variant="ghost"
90-
alignSelf="end"
91-
onClick={() => onClose()}
92-
>
93-
{t("common:close")}
94-
</Button>
95-
</Flex>
98+
{/* avoid rendering mobile only feature on desktop */}
99+
{isMobile() && <MobileCloseBar />}
96100

97101
{/* Main Language selection menu */}
98102
<Box
@@ -146,10 +150,7 @@ const LanguagePicker = ({
146150
}}
147151
onFocus={handleInputFocus}
148152
/>
149-
<InputRightElement
150-
hideBelow="md"
151-
cursor="text"
152-
>
153+
<InputRightElement hideBelow="md" cursor="text">
153154
<Kbd
154155
fontSize="sm"
155156
lineHeight="none"

0 commit comments

Comments
 (0)