Skip to content
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

[lit-html] Add svg tagged template literal documentation #2479

Merged
merged 8 commits into from
Feb 4, 2022
6 changes: 6 additions & 0 deletions .changeset/silly-donuts-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'lit-html': patch
'lit': patch
---

Expand JSDocs for the `svg` tagged template literal (TTL). The new documentation makes it more clear that the `svg` TTL should only be used for SVG fragments, and not for the svg html element.
20 changes: 19 additions & 1 deletion packages/lit-html/src/lit-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,26 @@ const tag =
export const html = tag(HTML_RESULT);

/**
* Interprets a template literal as an SVG template that can efficiently
* Interprets a template literal as an SVG fragment that can efficiently
* render to and update a container.
*
* ```ts
* const rect = svg`<rect width="10" height="10"></rect>`;
*
* const myImage = html`
* <svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">
* ${rect}
* </svg>`;
* ```
*
* The `svg` tagged template literal (TTL) should only be used for SVG
* fragments, or elements that would be contained within an `<svg>` html tag. A
AndrewJakubowicz marked this conversation as resolved.
Show resolved Hide resolved
* common error is wrapping `<svg>` with the svg TTL. The `<svg>` element is an
AndrewJakubowicz marked this conversation as resolved.
Show resolved Hide resolved
* html element and should be used within a {@linkcode html} TTL.
AndrewJakubowicz marked this conversation as resolved.
Show resolved Hide resolved
*
* In LitElement usage, it's rare to return an svg fragment from the `render()`
* method, as the svg fragment will be contained within the element's shadow
* root and thus cannot be used within an `<svg>` html tag.
AndrewJakubowicz marked this conversation as resolved.
Show resolved Hide resolved
*/
export const svg = tag(SVG_RESULT);

Expand Down