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.

autofocus subdomain on toggle

Steven Tey134b0da9abd2
diff --git a/apps/web/ui/modals/add-edit-domain-modal/domain-input.tsx b/apps/web/ui/modals/add-edit-domain-modal/domain-input.tsx
index 8e782539aa..488f39c3a4 100644
--- a/apps/web/ui/modals/add-edit-domain-modal/domain-input.tsx
+++ b/apps/web/ui/modals/add-edit-domain-modal/domain-input.tsx
@@ -7,7 +7,7 @@ import {
getSubdomain,
getUrlFromString,
} from "@dub/utils";
-import { useEffect, useMemo, useState } from "react";
+import { useEffect, useMemo, useRef, useState } from "react";
import { useDebounce } from "use-debounce";
import { motion } from "framer-motion";
import { InfoTooltip } from "@dub/ui/src/tooltip";
@@ -40,12 +40,22 @@ export default function DomainInput({
[domain],
);
+ const domainRef = useRef<HTMLInputElement>(null);
+ const subdomainRef = useRef<HTMLInputElement>(null);
+
+ useEffect(() => {
+ if (domainType === "website") {
+ subdomainRef.current?.focus();
+ }
+ }, [domainType]);
+
return (
<>
<div className="relative mt-2 flex rounded-md shadow-sm">
{domainType === "website" ? (
<div className="relative flex w-full rounded-md shadow-sm">
<input
+ ref={subdomainRef}
name="subdomain"
id="subdomain"
type="text"
@@ -68,6 +78,7 @@ export default function DomainInput({
</div>
) : (
<input
+ ref={domainRef}
name="domain"
id="domain"
type="text"