Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix input-select

Steven Tey3b6884642e5f
diff --git a/apps/web/ui/analytics/domain-selector.tsx b/apps/web/ui/analytics/domain-selector.tsx
index 62fd7a140d..ea839493e5 100644
--- a/apps/web/ui/analytics/domain-selector.tsx
+++ b/apps/web/ui/analytics/domain-selector.tsx
@@ -1,5 +1,4 @@
import useDomains from "@/lib/swr/use-domains";
-import useWorkspace from "@/lib/swr/use-workspace";
import { InputSelect, useRouterStuff } from "@dub/ui";
import { DUB_LOGO, GOOGLE_FAVICON_URL, getApexDomain } from "@dub/utils";
import { Globe } from "lucide-react";
@@ -9,7 +8,6 @@ import { ModalContext } from "../modals/provider";
export default function DomainSelector() {
const { queryParams } = useRouterStuff();
- const { slug } = useWorkspace();
const { allWorkspaceDomains: domains } = useDomains();
const searchParams = useSearchParams();
@@ -40,7 +38,6 @@ export default function DomainSelector() {
: undefined,
}}
setSelectedItem={(domain) => {
- console.log(domain);
if (domain && typeof domain !== "function" && domain.value) {
queryParams({
set: { domain: domain.value },
diff --git a/packages/ui/src/input-select.tsx b/packages/ui/src/input-select.tsx
index 828bee610d..7263274ea1 100644
--- a/packages/ui/src/input-select.tsx
+++ b/packages/ui/src/input-select.tsx
@@ -65,13 +65,6 @@ export function InputSelect({
}
}, [commandRef, openCommandList]);
- // hacks the input value to be empty when the selectedItem is empty
- useEffect(() => {
- if (!selectedItem?.value) {
- setInputValue("");
- }
- }, [selectedItem?.value]);
-
const { isMobile } = useMediaQuery();
const CommandInput = memo(() => {
@@ -103,20 +96,32 @@ export function InputSelect({
);
});
- const CloseButton = () => (
+ const CloseChevron = memo(() => (
<button
onClick={() => {
+ setOpenCommandList((prev) => !prev);
setSelectedItem(null);
setInputValue("");
}}
- className="absolute inset-y-0 right-0 my-auto"
+ className="absolute inset-y-0 right-0 my-auto pr-3"
>
- <X className="h-7 w-7 pr-3 text-gray-400" />
+ {inputValue.length > 0 ? (
+ <X className="h-4 w-4 text-gray-400 transition-all hover:text-gray-700" />
+ ) : (
+ <ChevronDown
+ className={cn(
+ "h-4 w-4 text-gray-400 transition-all hover:text-gray-700",
+ {
+ "rotate-180 transform": openCommandList,
+ },
+ )}
+ />
+ )}
</button>
- );
+ ));
// renders a reusable list of items
- const SelectorList = () =>
+ const SelectorList = memo(() =>
items.map((item) => (
<Command.Item
key={item.id}
@@ -162,7 +167,8 @@ export function InputSelect({
<Check className="invisible h-5 w-5 text-gray-500 aria-selected:visible" />
</Command.Item>
- ));
+ )),
+ );
// when adjustForMobile is true, render the input as a drawer
if (isMobile && adjustForMobile) {
@@ -189,11 +195,7 @@ export function InputSelect({
</div>
<div className="flex h-10 px-8">
<CommandInput />
- {inputValue || selectedItem?.value !== "" ? (
- <CloseButton />
- ) : (
- <ChevronDown className="absolute inset-y-0 right-0 my-auto h-7 w-7 pr-3 text-gray-400 transition-all" />
- )}
+ <CloseChevron />
</div>
</div>
</Command>
@@ -221,11 +223,7 @@ export function InputSelect({
</div>
<div className="flex h-10 px-8">
<CommandInput />
- {inputValue || selectedItem?.value !== "" ? (
- <CloseButton />
- ) : (
- <ChevronDown className="absolute inset-y-0 right-0 my-auto h-7 w-7 rotate-180 pl-3 text-gray-400 transition-all" />
- )}
+ <CloseChevron />
</div>
</div>
{openCommandList && (
@@ -279,16 +277,7 @@ export function InputSelect({
</div>
<div className="flex h-10 px-8">
<CommandInput />
- {inputValue || selectedItem?.value !== "" ? (
- <CloseButton />
- ) : (
- <ChevronDown
- onClick={() => setOpenCommandList((prev) => !prev)}
- className={`absolute inset-y-0 right-0 my-auto mr-3 h-4 w-4 cursor-pointer text-gray-400 transition-all ${
- openCommandList && "rotate-180"
- }`}
- />
- )}
+ <CloseChevron />
</div>
</div>
{openCommandList && (