Repository navigation
feat: custom item templates (renderOption / renderCreate) — v3.1.0 - #1
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two options to render arbitrary content for dropdown rows, including the
[+ Add]create row:renderOption(option, ctx)— custom content for each result rowrenderCreate(query, ctx)— custom content for the[+ Add]rowEach may return a DOM
Node(XSS-safe), an HTML string (caller owns escaping;ctx.escapeHtml/LiveSelect.escapeHtmlprovided), ornullto fall back to the default escapedlabel/sublabel. The control still owns the outer<button>, so ARIA roles, keyboard navigation, and click delegation are unchanged._renderMenunow builds rows as DOM nodes rather than oneinnerHTMLstring — default rendering is behaviorally identical.Changes
dist/liveselect.js—renderOption/renderCreate,_fillOption/_fillCreate/_applyRenderedhelpers,LiveSelect.escapeHtmlexport, updated options doc commenttest/client.test.js— 4 new jsdom tests (DOM-node template, string template viaescapeHtml,nullfallback stays escaped, custom create row)README.md— "Custom item templates" section + options-table rowsexamples/vanilla.html— templated people-picker (avatar · email · tier badge) demoing both contractsCHANGELOG.md+package.json— bump to 3.1.0 (additive → minor)Test plan
npm test→ 26/26 pass (was 22)🤖 Generated with Claude Code