Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 1c3a4a1

Browse files
committed
Add a note about kwarg names in component invocation.
1 parent d3cddaa commit 1c3a4a1

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ Boolean attributes are supported too. Just use a boolean value in the attribute
8585

8686
```python
8787
form_button = html(t"<button disabled={True} hidden={False}>Submit</button>")
88-
print(form_button)
8988
# <button disabled>Submit</button>
9089
```
9190

@@ -285,13 +284,15 @@ Because attributes are passed as keyword arguments, you can explicitly provide t
285284
```python
286285
from typing import Any
287286

288-
def Link(*, href: str, text: str, **props: Any) -> Template:
289-
return t'<a href="{href}" {props}>{text}</a>'
287+
def Link(*, href: str, text: str, data_value: int, **attrs: Any) -> Template:
288+
return t'<a href="{href}" {attrs}>{text}: {data_value}</a>'
290289

291-
result = html(t'<{Link} href="https://example.com" text="Example" target="_blank" />')
292-
# <a href="https://example.com" target="_blank">Example</a>
290+
result = html(t'<{Link} href="https://example.com" text="Example" data-value={42} target="_blank" />')
291+
# <a href="https://example.com" target="_blank">Example: 42</a>
293292
```
294293

294+
Note that attributes with hyphens (like `data-value`) are converted to underscores (`data_value`) in the function signature.
295+
295296
In addition to returning a `Template` directly, component functions may also return any `Node` type found in [`html_tstring.nodes`](https://github.com/t-strings/html-tstring/blob/main/html_tstring/nodes.py). This allows you to build more complex components that manipulate the HTML structure programmatically.
296297

297298
#### SVG Support

0 commit comments

Comments
 (0)