MeDo

Generatore di Barra di Ricerca IA.

Descrivi cosa cercano le persone e MeDo genera l'intero widget — query con debounce, menu typeahead, navigazione con le frecce, ricerche recenti, stati di caricamento e nessun risultato, e una scorciatoia cmd+K per il focus.

Barra di ricerca
Barra di ricerca

La barra di ricerca è l'unico input in cui focus visivo e focus del DOM non coincidono

Tutto il resto in una pagina mantiene focus ed evidenziazione nello stesso punto. Un typeahead non può: il cursore deve restare nel campo di testo per poter continuare a digitare, mentre l'evidenziazione scende lungo l'elenco dei suggerimenti. Il pattern corretto è aria-activedescendant, in cui l'input conserva il focus del DOM e punta all'opzione attiva tramite id. Le implementazioni che invece spostano il focus reale nell'elenco rompono immediatamente la digitazione, ed è per questo che tante barre di ricerca fatte a mano funzionano col mouse e crollano con la tastiera. Generare campo ed elenco come un unico widget significa che quella relazione è collegata dall'inizio anziché rattoppata dopo una segnalazione di bug.

6 modelli

Modelli di Barra di ricerca che puoi generare

Ogni modello è un prompt reale, non uno screenshot. Copialo in qualsiasi editor IA, oppure eseguilo in MeDo e ottieni codice React + Tailwind.

BasicInput + Clear

Plain Search Field With Submit

No dropdown, no fetch — just a field that submits to a results page. Start here when the corpus is large enough that suggestions would be guesses rather than shortcuts.

Create a search field: a 40px-tall rounded input inside a real form with role="search", type="search" on the input, enterkeyhint="search" for mobile keyboards, and a visible label or aria-label since a magnifier icon is not an accessible name. Put a 16px magnifier on the left with aria-hidden, and a clear button on the right that appears only once there is text, is a real button with an accessible label, and returns focus to the input after clearing. Enter submits the raw query through the form so search still works with JavaScript disabled. Escape clears the field when it has text. Show a focus-visible ring on the wrapper, not the bare input, so the icon and field read as one control.

Prova in MeDo
ComboboxTypeahead

Debounced Suggestions Listbox

The full combobox: debounce, listbox, aria-activedescendant. The critical rule is that DOM focus never leaves the input, or typing stops working the moment someone presses Arrow Down.

Create a typeahead search bar using the ARIA combobox pattern: aria-expanded, aria-controls and aria-activedescendant on the input, role="listbox" on the panel, role="option" with a unique id on each row. DOM focus must stay in the text field at all times — move the visual highlight by updating aria-activedescendant, never by focusing an option, or typing breaks. Debounce queries at 250ms and cancel in-flight requests so a slow earlier response cannot overwrite a newer one. Arrow Down and Up move the active option and wrap at the ends, Home and End jump to the first and last, Enter selects the active option or submits the raw query when none is active, Escape closes the panel and restores the typed text, and Tab closes and moves on rather than walking the options.

Prova in MeDo
cmd+KCommand Palette

Modal Search Overlay

Search as primary navigation, opened from anywhere with cmd+K. It is a modal dialog, which means a focus trap and focus restoration — the part most palette clones skip.

Create a command-palette search overlay opened by cmd+K and ctrl+K: a centered dialog with a backdrop, using the native dialog element or role="dialog" with aria-modal="true". Trap focus inside it, place initial focus in the input, close on Escape and backdrop click, and return focus to the element that was focused before opening. Ignore the shortcut while the user is typing in another input or a contenteditable region. Inside, run the ARIA combobox pattern with aria-activedescendant, group results under headed sections such as Pages, Docs and Actions, and let Arrow Down and Up move across group boundaries while skipping the group headings. Show a visible cmd+K hint in the trigger and keyboard hints in the dialog footer.

Prova in MeDo
StatesRecent + Empty

Search With Recent Queries and No-Results

Three panels, not one: recent searches on an empty query, skeleton rows in flight, a no-results row with a fallback. Leave any out and the dropdown flickers blank between keystrokes.

Create a search bar that renders three distinct dropdown states rather than one panel that empties. On an empty query, show up to five recent searches from localStorage under a Recent heading, each with a small remove button and a Clear all action. While a request is in flight, keep the previous results visible and overlay three skeleton rows, and swap the magnifier for an inline spinner rather than blanking the panel. On zero matches, show a no-results row naming the query plus a "Search everything" fallback action that submits the raw text. Announce the outcome in an aria-live="polite" region — "8 results available" or "No results" — debounced so intermediate counts are not read out. Arrow keys, Enter and Escape behave identically in all three states.

Prova in MeDo
FiltersScoped Search

Search With Scope Chips and Filters

A scope chip inside the field narrows the query before it runs. Make Backspace on an empty query remove the chip — anything else and people are hunting for a tiny × with the mouse.

Create a scoped search bar: removable scope chips render inside the input wrapper to the left of the text caret, each a button with an accessible label such as "Remove filter: Invoices". Pressing Backspace with an empty query removes the last chip rather than doing nothing, and typing a known prefix followed by a colon converts it into a chip. Keep the chips out of the input value itself and send them as separate query parameters. Below the field, render filter pills that are toggle buttons with aria-pressed, and re-run the debounced query on every change. Preserve the caret position when a chip is added, keep the ARIA combobox wiring for the suggestion listbox, and reflect the active scope in the aria-live result-count announcement.

Prova in MeDo
Media rowsRich Results

Suggestions With Thumbnails and Prices

Product and media rows where each suggestion carries an image, title and price. Reserve the thumbnail box explicitly, or every keystroke reflows the panel as images resolve.

Create a search bar with rich suggestion rows: each row is a role="option" containing a 40px thumbnail with explicit width and height attributes so the panel does not reflow as images load, a title with the matched substring bolded, and a secondary line with price or category. Because the row holds several elements, give each option an aria-label describing the whole row so a screen reader hears one coherent option rather than fragments. Cap the panel at 320px with internal scroll, and scroll the active option into view with block nearest as aria-activedescendant moves. Keep the last row a "See all results for <query>" action that submits the raw text. Highlight matches by wrapping the substring, never by injecting HTML from the response.

Prova in MeDo

Come personalizzare il tuo Barra di ricerca

Indica l'intervallo di debounce

Di' "debounce a 250ms" invece di "applica il debounce all'input". Sotto i 150ms circa invii una richiesta per ogni tasto premuto; oltre i 400ms circa il menu sembra rotto. Abbinalo alla cancellazione, così una risposta precedente lenta non può sovrascrivere una più recente.

Descrivi separatamente tutti e tre gli stati vuoti

Query vuota, query in corso e zero risultati sono tre schermate diverse. Chiedi le ricerche recenti per la prima, uno spinner o righe skeleton per la seconda e una riga di nessun risultato con azione di fallback per la terza. Ometterne una produce un pannello che lampeggia vuoto.

Specifica se Enter invia o seleziona

Con un suggerimento evidenziato, Enter deve selezionarlo; senza nulla evidenziato, Enter deve inviare la query grezza a una pagina di risultati. Descrivi entrambi i rami e chiedi un form reale con role="search" così che il percorso di invio funzioni senza JavaScript.

Chiedi che il numero di risultati venga annunciato

Gli utenti vedenti vedono crescere l'elenco. Gli utenti di screen reader hanno bisogno di una regione aria-live="polite" che dica qualcosa come "8 risultati disponibili". Richiedi esplicitamente la regione live e chiedi che abbia anch'essa il debounce, così non legge ogni conteggio intermedio.

Chi usa il componente Barra di ricerca

Sito di documentazione

Una barra di ricerca cmd+K che si apre sopra la pagina, raggruppa i risultati per sezione, mostra la riga corrispondente sotto ogni titolo e conserva le ultime cinque query per tornare a una pagina ricordata a metà.

Negozio e-commerce

Suggerimenti di prodotto con miniatura, nome e prezzo per riga, scorciatoie di categoria sopra e una riga finale "Vedi tutti i risultati per..." che invia la query grezza alla pagina completa dei risultati.

Dashboard o strumento di amministrazione

Un unico campo che cerca tra clienti, fatture e impostazioni, con risultati raggruppati per tipo e un chip di ambito nell'input per restringere a una singola entità prima di digitare.

Libreria di contenuti o media

Una barra di ricerca ampia con pillole di filtro accanto, righe skeleton durante l'esecuzione della query e uno stato di nessun risultato che suggerisce correzioni ortografiche anziché mostrare un pannello vuoto.

Pattern di Barra di ricerca per siti web diversi

Lo stesso componente barra di ricerca, calibrato sul tipo di sito su cui viene pubblicato.

01 / 06

Documentation Search

A cmd+K palette that groups hits by section and shows the matching line under each title, since a page title alone rarely tells a reader whether the answer is on it. Keep the last five queries — docs search is mostly people returning to a page they half remember.

Stili e varianti di Barra di ricerca

Scegli la variante che si adatta al resto della pagina, poi generala.

01 / 06

Inline Field Search

A permanent bordered input in the header or page body. The most discoverable option and the only one that works without JavaScript, since a real form with role="search" submits on Enter regardless. Give the wrapper the focus ring so the icon and field read as one control.

Barra di ricerca in React, Next.js, Vue e Svelte

React, Next.js, Vue 3, SvelteKit, Astro o HTML puro: lo stesso barra di ricerca, sei modi per integrarlo.

01 / 06

React Search Bar

Track the active index as a number and derive aria-activedescendant from it — that is the entire highlight mechanism, with no focus moves. Abort the previous fetch in the effect cleanup so a slow response cannot land after a newer one.

src/components/SearchBar.tsx

const [active, setActive] = useState(-1)
const debounced = useDebounce(query, 250)

<input
  type="search"
  role="combobox"
  aria-expanded={open}
  aria-controls="search-listbox"
  aria-activedescendant={active >= 0 ? `opt-${active}` : undefined}
  onKeyDown={onArrowKeys}
/>

Come aggiungere il tuo Barra di ricerca a un progetto

Quattro passaggi, dalla scelta di un modello di barra di ricerca alla messa in produzione.

01~30s

Pick a Search Pattern

Decide whether you need suggestions at all. A plain field posting to a results page is often the honest answer; reach for the typeahead or the cmd+K palette only when search is a primary navigation path.

02~10s

Copy the Prompt

Take the prompt into MeDo, Lovable, Bolt, v0 or Cursor, then set two numbers: the debounce interval and how many suggestions the panel shows. Name what is being searched too, since that decides how a result row is shaped.

03~1min

Generate and Refine

You get React + Tailwind back with a live preview. Follow up in plain English — "add recent searches", "group results by type", "announce the result count politely" — rather than rewriting the keydown handler.

04~2min

Connect Your Index and Ship

Point the query at your real endpoint, then test with the keyboard only: type, Arrow Down, Enter, Escape. If typing stops working after Arrow Down, focus was moved into the list and the highlight needs to go back to aria-activedescendant.

Domande comuni su Barra di ricerca

Come genero una barra di ricerca con l'IA?

Descrivi cosa viene cercato, da dove arrivano i suggerimenti e quali stati ti servono — ricerche recenti, caricamento, nessun risultato. MeDo genera l'input, il menu dei suggerimenti, la gestione delle query con debounce e le associazioni da tastiera come un unico componente, non un campo di testo nudo da collegare dopo.

Qual è la differenza tra una barra di ricerca e un autocompletamento?

Una barra di ricerca invia una query a testo libero e tratta i suggerimenti come scorciatoie, quindi digitare qualcosa senza corrispondenze è comunque valido. Un autocompletamento vincola il valore a un elenco, perciò l'input viene confermato solo scegliendo un'opzione. La distinzione cambia il markup: una barra di ricerca va in un form con role="search", mentre un autocompletamento vincolato è un combobox legato a un valore del form.

L'IA può generare una barra di ricerca accessibile?

Sì, se chiedi il pattern per nome. MeDo implementa il pattern ARIA combobox con aria-expanded, aria-controls e aria-activedescendant sull'input, role="listbox" e role="option" sul pannello e una regione live polite per il numero di risultati. Il focus resta nel campo di testo per tutto il tempo, ed è questo che fa funzionare insieme digitazione e frecce.

Come deve funzionare la navigazione da tastiera in un menu di ricerca?

Freccia giù passa al primo suggerimento e continua a scendere nell'elenco, freccia su torna indietro e può riportare il focus alla query grezza, Enter seleziona l'elemento evidenziato ed Escape chiude il pannello ripristinando ciò che la persona ha digitato. Home e End sono un'aggiunta utile per elenchi lunghi. Tab dovrebbe chiudere il pannello e proseguire, non attraversare le opzioni.

Devo usare type="search" sull'input?

Sì. Ti dà il pulsante di cancellazione del browser su alcune piattaforme, segnala l'intento alle tecnologie assistive e si abbina a un enterkeyhint "search" sulle tastiere mobili. Racchiudilo in un form reale con role="search" così la query viene inviata anche se lo scripting fallisce, e dai all'input un'etichetta o un aria-label, perché la sola icona della lente non è un nome accessibile.

Una barra di ricerca ha bisogno di una scorciatoia cmd+K?

Aiuta dove la ricerca è un percorso di navigazione primario, come documentazione, dashboard e strumenti per sviluppatori. Associa sia cmd+K sia ctrl+K, ignora la scorciatoia mentre l'utente digita in un altro input e mostra il suggerimento dentro il campo così è individuabile. Menzionala nel tuo prompt a MeDo e listener e suggerimento visibile vengono generati insieme.