Skip to content

feat: custom item templates (renderOption / renderCreate) — v3.1.0 - #1

Merged
michaeljfalk merged 1 commit into
mainfrom
feat/custom-item-templates
Jun 17, 2026
Merged

michaeljfalk merged 1 commit into
mainfrom
feat/custom-item-templates

Conversation

@michaeljfalk

Copy link
Copy Markdown
Owner

Summary

Adds two options to render arbitrary content for dropdown rows, including the [+ Add] create row:

  • renderOption(option, ctx) — custom content for each result row
  • renderCreate(query, ctx) — custom content for the [+ Add] row

Each may return a DOM Node (XSS-safe), an HTML string (caller owns escaping; ctx.escapeHtml / LiveSelect.escapeHtml provided), or null to fall back to the default escaped label/sublabel. The control still owns the outer <button>, so ARIA roles, keyboard navigation, and click delegation are unchanged. _renderMenu now builds rows as DOM nodes rather than one innerHTML string — default rendering is behaviorally identical.

Changes

  • dist/liveselect.js — renderOption/renderCreate, _fillOption/_fillCreate/_applyRendered helpers, LiveSelect.escapeHtml export, updated options doc comment
  • test/client.test.js — 4 new jsdom tests (DOM-node template, string template via escapeHtml, null fallback stays escaped, custom create row)
  • README.md — "Custom item templates" section + options-table rows
  • examples/vanilla.html — templated people-picker (avatar · email · tier badge) demoing both contracts
  • CHANGELOG.md + package.json — bump to 3.1.0 (additive → minor)

Test plan

  • npm test → 26/26 pass (was 22)
  • Existing XSS-escaping regression still passes (default path unchanged)

🤖 Generated with Claude Code

Add two options to render arbitrary content for dropdown rows:

- renderOption(option, ctx) — per result row
- renderCreate(query, ctx)  — the [+ Add] row

Each may return a DOM Node (XSS-safe), an HTML string (caller owns
escaping; ctx.escapeHtml / LiveSelect.escapeHtml provided), or null to
fall back to the default escaped label/sublabel. The control still owns
the outer <button>, so ARIA roles, keyboard nav, and click delegation
are unchanged. _renderMenu now builds rows as DOM nodes instead of one
innerHTML string; default rendering is behaviorally identical.

Also: expose LiveSelect.escapeHtml, 4 new jsdom tests, README section +
options-table rows, a templated people-picker in examples/vanilla.html,
and CHANGELOG/version bump to 3.1.0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@michaeljfalk
michaeljfalk merged commit 3bcdc1a into main Jun 17, 2026
1 check passed
@michaeljfalk
michaeljfalk deleted the feat/custom-item-templates branch June 17, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant