-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(autocomplete-js): enable HTML templating #920
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 40035ff:
|
628e069
to
78a0479
Compare
74e16bf
to
91940e5
Compare
91940e5
to
11c7922
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 👏 👏
3742273
to
f7c51d6
Compare
I'll merge once the docs are ready (so we don't hog potential bug fixes if needed in the meantime). |
Hi @sarahdayan! I have problem like this 1209
|
Solution!
|
This PR introduces HTML templating to Autocomplete.
Try HTML templates in the sandbox →
Summary
The
autocomplete-js
package is an agnostic virtual DOM renderer, to be used in JavaScript, Preact, React, or Vue projects. It expects virtual nodes to describe UIs, which means Autocomplete users are expected to provide templates as virtual node trees.Building virtual nodes can be done either with
createElement
(provided in every template) or using JSX. However, none of these options are user-friendly to vanilla JavaScript users, especially those who don't have a build step.HTML templating in Autocomplete allows users to:
createElement
function or on JSX__dangerouslySetInnerHTML
to provide HTML templatesUnder the hood,
autocomplete-js
still uses a virtual DOM. It still works with JSX andcreateElement
, and still provides the same speed and safety for all template usages.Usage
Templates now expose an
html
function. This function is a tagged template, which lets users provide templates as interpolated strings. This generates a virtual node tree (just like JSX orcreateElement
) while providing a simple HTML string.One benefit over classic HTML templates injected in a container is that these templates accept inline event handlers (e.g.,
onClick
), just like JSX. It facilitates interactivity and garbage collection of event handlers in many situations.The
html
function is also available in therender
andrenderNoresults
options, so users can customize the layout of their Autocomplete panel before rendering. Both options also expose arender
function, so there's no need to install any virtual DOM dependency at all on the user's end.IE 11 compatibility
Tagged templates aren't compatible with Internet Explorer 11, but there are ways to use the
html
function in IE 11. If you need to support IE 11, please refer to the Autocomplete templates documentation to either transform your code, or use an IE 11-compatible shim.