Skip to content

Commit ed6f610

Browse files
committed
Allow tag to be set only on the root node
1 parent c54f356 commit ed6f610

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 0.13.0
22
- **BREAKING** Refactor Tag and implementation to significantly reduce memory usage
3-
- The Tag's `tag` is now a ClassVar instead of an atom member. Use a subclass to change tags.
3+
- The Tag's `tag` is now a ClassVar instead of an atom member. Only the tag of the "root" html node can be changed per instance. Use a subclass to change tags of child nodes.
44
- The Tag's `clickable` and `draggable` are now removed. `clickable` is automatically inferred if a `clicked` handler is defined. `draggable` is inferred if `dragstart` is defined.
55
- Due to their minimal usage `onclick`, `ondragstart`, `ondragover`, `ondragend`, `ondragenter` and `ondragleave` are removed. Use
66
the `attrs` dict to define these instead.

tests/test_html.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,23 @@ def test_html_change(app, tag, attr, default, change, query):
157157
assert len(view.proxy.widget.xpath(query)) == 1
158158

159159

160+
def test_root_tag_render(app):
161+
"""Test rendering a root component with a custom tag"""
162+
source = dedent(
163+
"""
164+
from web.components.api import *
165+
166+
enamldef Toast(Html):
167+
tag = "toast"
168+
"""
169+
)
170+
print(source)
171+
Toast = compile_source(source, "Toast")
172+
toast = Toast()
173+
print(toast.render())
174+
assert len(toast.proxy.widget.xpath("//toast")) == 1
175+
176+
160177
def test_tag_proxy(app):
161178
# To make cov happy
162179
from web.components.html import ProxyTag

web/components/html.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,12 @@ def render(
301301

302302

303303
class Html(Tag):
304+
"""Html is a root tag. It can be created without a parent and handles all modified events"""
305+
304306
__slots__ = ("__weakref__",)
305307

306-
#: Set the tag name
307-
tag = "html"
308+
#: The xml tag of the root node.
309+
tag = d_(Str("html"))
308310

309311
#: Dom modified event. This will fire when any child node is updated, added
310312
#: or removed. Observe this event to handle updating websockets.

0 commit comments

Comments
 (0)