Autocomplete example

Email domains without restricting the address.

Build domain suggestions from the typed local part while keeping native email validation. A valid address outside the suggestions remains valid; sending an invitation belongs to the application.

Complete React client module · MIT · Next.js and Vite

Interactive example

Email domains without restricting the address

Build domain suggestions from the typed local part while keeping native email validation. A valid address outside the suggestions remains valid; sending an invitation belongs to the application.

Keyboard

  • Type the local part, then Arrow Down and Enter to complete a suggested address.
  • Native text selection, deletion and paste continue to work.
  • Submitting an invalid address returns focus to the native email input.

States covered

  • Dynamic suggestions
  • Native email constraint
  • Required field
  • Custom domain
  • Field error

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-autocomplete-email.json
Complete source
React / TypeScript
/*!
MIT License

Copyright (c) 2026 Jaison

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import {useState} from 'react';
import {Autocomplete} from '@bld8/ui/autocomplete';
import {Button} from '@bld8/ui';
const domains=['example.com','outlook.com','gmail.com'];
export default function EmailSuggestionExample(){
  const [email,setEmail]=useState(''),[error,setError]=useState(''),[status,setStatus]=useState('');
  const local=email.split('@')[0];
  const options=local?domains.map(domain=>({id:domain,label:local+'@'+domain,description:'Suggested email domain'})).filter(option=>option.label.toLowerCase().startsWith(email.toLowerCase())):[];
  return <form aria-label="Invitation address" style={{display:'grid',gap:12}} onSubmit={event=>{event.preventDefault();setError('');setStatus('Invitation address: '+email);}}>
    <Autocomplete label="Invite email" type="email" autoComplete="email" name="inviteEmail" required value={email} onValueChange={value=>{setEmail(value);setError('');setStatus('');}} options={options} filter={null} error={error} onInvalid={()=>setError('Enter a complete email address.')} hint="Use a suggested domain or any other valid email address."/>
    <div><Button type="submit">Prepare invitation</Button></div>
    <p role="status" aria-label="Invitation address status">{status}</p>
  </form>;
}