Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useState } from "react"
import { useLocale } from "next-intl"

import { FilterInputState, Lang } from "@/lib/types"

import Input from "@/components/ui/input"
import {
Select,
SelectContent,
Expand Down Expand Up @@ -34,9 +36,10 @@ const FindWalletLanguageSelectInput = ({
updateFilterState,
}: FindWalletLanguageSelectInputProps) => {
const locale = useLocale()
const [searchQuery, setSearchQuery] = useState("")
const { t } = useTranslation("page-wallets-find-wallet")
const languageCountWalletsData = getLanguageCountWalletsData(locale as string)
const countSortedLanguagesCount = languageCountWalletsData.sort(
const countSortedLanguagesCount = [...languageCountWalletsData].sort(
(a, b) => b.count - a.count
)

Expand All @@ -51,15 +54,36 @@ const FindWalletLanguageSelectInput = ({
eventName: getLanguageCodeName(e, locale!),
})
updateFilterState(filterIndex, itemIndex, e)
setSearchQuery("") // Reset search when selection is made
}}
>
<SelectTrigger className="w-full">
<SelectValue />
</SelectTrigger>
<SelectContent>
<div
className="sticky top-0 z-10 bg-background p-2"
onKeyDown={(e) => e.stopPropagation()}
onClick={(e) => e.stopPropagation()}
>
<Input
type="search"
placeholder={t("page-find-wallet-search-languages")}
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="w-full"
/>
</div>
{languageCountWalletsData.map((language) => {
const isVisible = language.name
.toLowerCase()
.includes(searchQuery.toLowerCase())
return (
<SelectItem key={language.langCode} value={language.langCode}>
<SelectItem
key={language.langCode}
value={language.langCode}
className={!isVisible ? "hidden" : ""}
>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using hidden here instead of filtering the array directly, to avoid SelectValue losing its value and in turn leads to Input losing focus when searchQuery changes

{`${language.name} (${language.count})`}
</SelectItem>
)
Expand Down
3 changes: 2 additions & 1 deletion src/intl/en/page-wallets-find-wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,6 @@
"page-find-wallet-social-links": "Links",
"page-find-wallet-empty-results-title": "No results",
"page-find-wallet-empty-results-desc": "There are no wallets matching your criteria, try removing some filters.",
"page-find-wallet-see-wallets": "See wallets"
"page-find-wallet-see-wallets": "See wallets",
"page-find-wallet-search-languages": "Search languages..."
}