AI Prompt for an Accessible React Autocomplete Combobox
This prompt is for developers asking Claude, ChatGPT, or Gemini to generate a React autocomplete combobox component, the input-plus-dropdown pattern used for things like city pickers, tag selectors, and command inputs. It's aimed at frontend engineers who need the component to actually meet accessibility requirements (correct ARIA roles, keyboard navigation, screen reader announcements) rather than just look right visually.
Most AI-generated autocomplete components work fine with a mouse and fail under keyboard-only or screen reader use, because the model defaults to a plain text input with a floating list and skips the ARIA combobox pattern entirely. The prompt below specifies the exact roles (combobox, listbox, option), the keyboard behavior (arrow keys, Enter, Escape, Home/End), and asks for debounced filtering so the component performs well with large option lists.
If you're generating several related form components in one sitting, running the filled-in prompt through the Prompt Optimizer in Coding mode first can tighten the structure before you send it to the model, especially the accessibility and state-management constraints that are easy to leave vague.
Prompt template
Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.
Example input
When to use it
- You need a React autocomplete or combobox input that works correctly with keyboard-only navigation and screen readers
- You're replacing a plain
<select>with a searchable dropdown for a long list of options like cities, products, or tags - You want debounced, client-side filtering built in so the component doesn't re-render on every keystroke
- You're standardizing a form component that multiple teams will reuse and need it to meet WCAG keyboard and ARIA requirements from the start
Best practices
- Specify the exact ARIA roles and attributes you expect (combobox, listbox, option, aria-activedescendant) instead of leaving accessibility implicit
- Describe every keyboard interaction explicitly: arrow keys to move, Enter to select, Escape to close, Home/End to jump to the first or last option
- Ask for debounced filtering with a stated delay so the model doesn't default to filtering on every keystroke with no debounce at all
- Request that the component accept controlled props (value, onChange) rather than managing all state internally, so it fits into existing forms
Common mistakes
- Accepting a combobox built with a plain
<input>and a<div>dropdown with no ARIA roles, which looks correct but is invisible to screen readers - Not specifying what happens when the filtered list is empty, leaving the model to either hide the dropdown silently or show nothing useful
- Forgetting to ask for debounce, resulting in a filter function that runs on every keystroke against a large option list
- Leaving click-outside-to-close behavior unspecified, which often gets skipped entirely in the generated code
FAQs
How do I make a React autocomplete component accessible to screen readers?
Use the ARIA 1.2 combobox pattern with role="combobox" on the input, role="listbox" and role="option" on the dropdown and its items, and aria-activedescendant to track which option is currently highlighted.
What keyboard shortcuts should an autocomplete combobox support?
At minimum, arrow keys to move between options, Enter to select the highlighted one, Escape to close the dropdown, and Home/End to jump to the first or last option.
Why does my AI-generated autocomplete work with a mouse but not a keyboard?
Most default implementations use a plain input and div dropdown with no ARIA roles or keyboard handlers, so explicitly specifying both in your prompt is what gets the model to include them.
Should autocomplete filtering be debounced?
Yes, for any list beyond a handful of options, debouncing by 100 to 200ms prevents the filter function from running on every single keystroke.
Which Cuelara tool can help me tighten this prompt before using it?
Prompt Optimizer — its Coding mode is built for turning loose component requests like this into a structured prompt with explicit accessibility and state-management constraints.