MeDo

منشئ شريط البحث بالذكاء الاصطناعي.

صِف ما يبحث عنه الناس ويُنشئ MeDo العنصر بالكامل — استعلامات مؤجّلة، قائمة اقتراحات تلقائية، تنقل بمفاتيح الأسهم، عمليات البحث الأخيرة، حالات التحميل وعدم وجود نتائج، واختصار cmd+K للتركيز.

شريط البحث
شريط البحث

شريط البحث هو حقل الإدخال الوحيد الذي يختلف فيه التركيز البصري عن تركيز DOM

كل شيء آخر في الصفحة يُبقي التركيز والتمييز في المكان نفسه. أما البحث التلقائي فلا يستطيع ذلك: يجب أن يبقى المؤشر في حقل النص حتى يتمكن الناس من متابعة الكتابة، بينما ينتقل التمييز نزولاً في قائمة الاقتراحات. النمط الصحيح هو aria-activedescendant، حيث يحتفظ الحقل بتركيز DOM ويشير إلى الخيار النشط بواسطة المعرّف id. أما التطبيقات التي تنقل التركيز الفعلي إلى القائمة فتُعطّل الكتابة فوراً، ولهذا تعمل كثير من أشرطة البحث المكتوبة يدوياً بالفأرة وتنهار مع لوحة المفاتيح. إنشاء الحقل والقائمة كعنصر واحد يعني أن هذه العلاقة مربوطة من البداية بدلاً من ترقيعها بعد تقرير خطأ.

6 قالبًا

قوالب شريط البحث التي يمكنك توليدها

كل قالب هو طلب حقيقي لا صورة. انسخه إلى أي محرّر ذكاء اصطناعي، أو شغّله في 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 الاستعلام الخام إلى صفحة النتائج. اشرح الفرعين بوضوح، واطلب form حقيقياً بـ role="search" حتى يعمل مسار الإرسال دون 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.

أسئلة شائعة حول شريط البحث

كيف أُنشئ شريط بحث بالذكاء الاصطناعي؟

صِف ما يجري البحث عنه، ومن أين تأتي الاقتراحات، وأي الحالات تحتاجها — عمليات البحث الأخيرة، التحميل، عدم وجود نتائج. يُنشئ MeDo حقل الإدخال وقائمة الاقتراحات ومعالجة الاستعلامات المؤجّلة وارتباطات لوحة المفاتيح كمكوّن واحد بدلاً من حقل نصي مجرّد عليك ربطه لاحقاً.

ما الفرق بين شريط البحث والإكمال التلقائي؟

شريط البحث يُرسل استعلاماً نصياً حراً ويتعامل مع الاقتراحات كاختصارات، لذا تبقى كتابة شيء بلا مطابقات صالحة. أما الإكمال التلقائي فيقيّد القيمة بقائمة، فلا تُعتمد القيمة إلا عند اختيار خيار. هذا الفرق يغيّر الترميز: شريط البحث ينتمي إلى form بـ role="search"، بينما الإكمال التلقائي المقيّد هو combobox مرتبط بقيمة نموذج.

هل يمكن للذكاء الاصطناعي إنشاء شريط بحث سهل الوصول؟

نعم، إذا طلبت النمط باسمه. ينفّذ MeDo نمط ARIA combobox مع aria-expanded وaria-controls وaria-activedescendant على الحقل، وrole="listbox" وrole="option" على اللوحة، ومنطقة حيّة polite لعدد النتائج. يبقى التركيز في حقل النص طوال الوقت، وهذا ما يجعل الكتابة ومفاتيح الأسهم تعملان معاً.

كيف ينبغي أن يعمل التنقل بلوحة المفاتيح في قائمة البحث؟

السهم للأسفل ينتقل إلى الاقتراح الأول ويستمر نزولاً في القائمة، والسهم للأعلى يرجع ويمكنه إعادة التركيز إلى الاستعلام الخام، وEnter يختار العنصر المميّز، وEscape يغلق اللوحة مع استعادة ما كتبه الشخص. ومفتاحا Home وEnd إضافة مفيدة للقوائم الطويلة. أما Tab فينبغي أن يغلق اللوحة وينتقل للعنصر التالي بدلاً من المرور على الخيارات.

هل أستخدم type="search" على حقل الإدخال؟

نعم. فهو يمنحك زر المسح الخاص بالمتصفح على بعض المنصات، ويوصل النية إلى التقنيات المساعدة، ويتلاءم مع enterkeyhint بقيمة "search" على لوحات مفاتيح الجوّال. ضعه داخل form حقيقي بـ role="search" حتى يُرسل الاستعلام إن فشلت البرمجة النصية، وأعطِ الحقل تسمية أو aria-label لأن أيقونة العدسة وحدها ليست اسماً سهل الوصول.

هل يحتاج شريط البحث إلى اختصار cmd+K؟

يفيد في كل مكان يكون البحث فيه مسار تنقل رئيسياً، مثل التوثيق ولوحات التحكم وأدوات المطوّرين. اربط cmd+K وctrl+K معاً، وتجاهل الاختصار أثناء كتابة المستخدم في حقل آخر، واعرض التلميح داخل الحقل ليكون قابلاً للاكتشاف. اذكره في موجّهك إلى MeDo وسيُنشأ المستمع والتلميح المرئي معاً.