mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-25 03:18:54 +08:00
### Summary
This PR introduces a modern component-based API for the `d-autocomplete`
modifier, enabling developers to use Glimmer components instead of
template strings for rendering the autocomplete results.
The existing autocomplete system relied on template strings
(`userAutocomplete`, `groupAutocomplete`) which had several limitations:
- Required manual HTML escaping with `escapeExpression()`
- Used unsafe `iconHTML()` with triple-stache `{{{ }}}` syntax
- Tight coupling between rendering and data logic
### Changes
**New Component-Based API**
- Added `component` parameter to `DAutocompleteModifier` (takes
precedence over `template`)
- Updated `d-autocomplete-results.gjs` to conditionally render either:
- Custom component (via `@data.component`) for new API
- Template HTML (via `@data.template`) for legacy API
- Component receives properly structured args: `@results`,
`@selectedIndex`, `@onSelect`, `@onRender`
**New Component for each type of Autocomplete result**
- Safer `{{icon}}` helper instead of `{{{iconHTML}}}`
- Automatic HTML escaping via Glimmer `{{}}`
- `scrollIntoView` modifier for keyboard navigation
- Declarative `{{#each}}` with reactive index tracking
- Matches exact CSS structure of legacy template
---
We'll add new ones for Hashtag and Emoji Autocompletes in upcoming PRs.
|
||
|---|---|---|
| .. | ||
| javascripts | ||
| stylesheets | ||