Skip to content

Commit

Permalink
Issue: #1211 (#1212)
Browse files Browse the repository at this point in the history
Clear suggestions on mismatch: If the user types a phone number or custom domain, the suggestions disappear.

Hide suggestions on blur: If the user doesn’t select a suggestion and clicks outside the field, the suggestions are cleared.
  • Loading branch information
kingpranav21 authored Sep 24, 2024
1 parent bb4f6ba commit f5353da
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/components/Signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,27 @@ const Signin = () => {
...prevState,
emailReq: false,
}));

// Check if the input is a phone number
const phoneNumberRegex = /^[0-9]{10}$/;
if (phoneNumberRegex.test(value)) {
setSuggestedDomains([]); // Clear suggestions for phone numbers
return;
}

if (!value.includes('@')) {
setSuggestedDomains(emailDomains);
return;
}

const [, currentDomain] = value.split('@');

// Clear suggestions if domain doesn't match
if (!currentDomain || !emailDomains.some((domain) => domain.startsWith(currentDomain))) {
setSuggestedDomains([]); // Hide suggestions for mismatched domains
return;
}

// Check for exact matches and filter for partial matches
const exactMatch = emailDomains.find((domain) => domain === currentDomain);
if (exactMatch) {
Expand Down Expand Up @@ -175,6 +189,7 @@ const Signin = () => {
value={email.current}
onChange={handleEmailChange}
onKeyDown={handleKeyDown}
onBlur={() => setSuggestedDomains([])} // Hide suggestions on blur
/>
{email.current && suggestedDomains.length > 0 && (
<ul
Expand Down

0 comments on commit f5353da

Please sign in to comment.