AI搜尋列生成器。

描述用戶會搜尋什麼,MeDo即生成完整元件 — 防抖查詢、即時建議下拉選單、方向鍵操作、最近搜尋、載入與沒有結果狀態,以及用來聚焦的 cmd+K 快捷鍵。

搜尋列
搜尋列

搜尋列是唯一一個視覺焦點與 DOM 焦點不一致的輸入元件

頁面上其他所有元素的焦點和高亮都停留在同一處。即時建議做不到:游標必須留在文字框裡,用戶才能繼續輸入,而高亮要沿著建議清單往下移動。正確的模式是 aria-activedescendant,輸入框保留 DOM 焦點,並透過 id 指向目前啟用的選項。那些把真實焦點移入清單的做法會即刻破壞輸入,這也是為何許多自行撰寫的搜尋列用滑鼠可用、用鍵盤就失靈。把輸入框和清單當作一個元件一起生成,意味著這層關係從一開始就接好了,而不是等收到問題回報後才補救。

6 個模板

可以產生的 搜尋列 模板

每個模板都是真實的提示詞,而非截圖。複製到任何 AI 編輯器,或在 MeDo 中執行,直接取得 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.

在 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.

在 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.

在 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.

在 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.

在 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.

在 MeDo 中試試

如何自訂你的 搜尋列

明確講出防抖間隔

說「防抖250ms」,而不是「為輸入框加防抖」。低於約150ms,每按一個鍵就會發一次請求;超過約400ms,下拉選單會讓人覺得壞了。同時加上請求取消,避免較慢的舊回應蓋掉較新的結果。

分別描述三種空狀態

查詢為空、請求進行中、結果為零是三個不同的畫面。第一種要最近搜尋,第二種要載入指示器或骨架列,第三種要無結果列加備用操作。少寫任何一種,你就會得到一個閃成空白的面板。

說明 Enter 是送出還是選取

有建議處於高亮時,Enter 應選取它;沒有任何高亮時,Enter 應把原始查詢送到結果頁。把兩條分支都寫清楚,並要求使用帶 role="search" 的真實 form,讓送出路徑在沒有 JavaScript 時也能運作。

要求播報結果數量

視力正常的用戶能看到清單變長。螢幕閱讀器用戶需要一個 aria-live="polite" 區域播報類似「有8個結果」的訊息。明確要求這個即時區域,並要求它同樣做防抖,以免把每個中途數量都唸出來。

誰在使用 搜尋列 組件

文件網站

一個 cmd+K 搜尋列,覆蓋在頁面之上開啟,按章節歸類命中結果,在每個標題下顯示相符的那一行,並保留最近五次查詢,方便用戶跳回只記得大概的頁面。

電商商店

每列含縮圖、名稱和價格的商品建議,上方是分類快捷入口,底部有一列「查看…的全部結果」,把原始查詢送到完整結果頁。

儀表板或後台工具

一個輸入框同時搜尋客戶、發票和設定,結果按類型歸類,輸入框內帶範圍標籤,讓用戶在輸入前先收窄到單一實體。

內容或媒體庫

一條寬搜尋列,旁邊是篩選膠囊,查詢執行時顯示骨架列,沒有結果時提供拼字修正建議,而不是擺一個空面板。

不同網站的 搜尋列 方案

同一個 搜尋列 組件,針對它所在網站的類型作調整。

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.

搜尋列 的風格與變體

挑選與頁面其餘部分相襯的變體,然後產生它。

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.

在 React、Next.js、Vue 與 Svelte 中使用 搜尋列

React、Next.js、Vue 3、SvelteKit、Astro 或純 HTML —— 同一個 搜尋列,六種接入方式。

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}
/>

如何把 搜尋列 加入專案

四個步驟,從挑選 搜尋列 模板到推上生產環境。

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.

關於 搜尋列 的常見問題

如何用AI生成搜尋列?

描述搜尋的對象、建議資料從何而來,以及你需要哪些狀態 — 最近搜尋、載入中、沒有結果。MeDo會把輸入框、建議下拉選單、防抖查詢處理和鍵盤綁定當作一個元件一起生成,而不是給你一個還得自己接線的純文字框。

搜尋列和自動完成有甚麼分別?

搜尋列送出自由文字查詢,把建議當作快捷方式,因此輸入沒有相符項目的內容仍然有效。自動完成會把取值限制在一個清單內,只有選取某個選項時輸入才算確定。這個分別會改變標記結構:搜尋列應放在帶 role="search" 的 form 中,而受限的自動完成是一個綁定到表單值的 combobox。

AI能生成無障礙的搜尋列嗎?

可以,只要你點名要這個模式。MeDo實作 ARIA combobox 模式:輸入框使用 aria-expanded、aria-controls 和 aria-activedescendant,面板使用 role="listbox" 與 role="option",並為結果數量提供 polite 即時區域。焦點始終留在文字框內,這正是讓輸入和方向鍵同時可用的關鍵。

搜尋下拉選單的鍵盤操作應該怎樣設計?

向下方向鍵移到第一條建議並繼續往下走,向上方向鍵回退並可把焦點交還給原始查詢,Enter 選取高亮項,Escape 關閉面板並還原用戶輸入的內容。長清單還可以加上 Home 和 End。Tab 應關閉面板並移到下一個元件,而不是逐個走過選項。

輸入框應該用 type="search" 嗎?

應該。它在部分平台上提供瀏覽器自帶的清除功能,向輔助技術傳達意圖,並可與行動裝置鍵盤上的 enterkeyhint="search" 搭配。把它包在帶 role="search" 的真實 form 中,這樣腳本失效時查詢仍能送出;同時給輸入框加上 label 或 aria-label,因為單獨的放大鏡圖示並不構成無障礙名稱。

搜尋列需要 cmd+K 快捷鍵嗎?

在搜尋屬於主要導覽路徑的場景中很有幫助,例如文件、儀表板和開發者工具。同時綁定 cmd+K 和 ctrl+K,用戶正在其他輸入框打字時忽略該快捷鍵,並在輸入框內顯示提示以便被發現。在給 MeDo 的提示詞中提到它,監聽器和可見提示會一起生成。