Skip to content

Commit

Permalink
feat(raw_attrs): widgets support raw_attrs at construction
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Jan 17, 2024
1 parent cea5175 commit 131618a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion trame_client/widgets/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,18 @@ class AbstractElement:
:param mouseleave: See |mdn_event_link| for more info
:param contextmenu: See |mdn_event_link| for more info
Raw attributes
:param raw_attrs: List of string that will be added as-is in the generated template
>>> print(html.Template(raw_attrs=["v-slot:item.1", 'class="bg-red"', '@click.stop="a=2"']))
... <Template v-slot:item.1 class="bg-red" @click.stop="a=2" />
"""

_next_id = 1
_debug = "--debug" in sys.argv or "-d" in sys.argv

def __init__(self, _elem_name, children=None, **kwargs):
def __init__(self, _elem_name, children=None, raw_attrs=None, **kwargs):
AbstractElement._next_id += 1
self._id = AbstractElement._next_id
self._server = kwargs.get("trame_server")
Expand All @@ -284,6 +290,11 @@ def __init__(self, _elem_name, children=None, **kwargs):
self._py_attr = kwargs
self._children = []

# Handle raw attributes if provided
if raw_attrs:
for idx, raw_value in enumerate(raw_attrs):
self._attributes[f"_raw_{idx}"] = raw_value

if children:
if isinstance(children, (list, tuple)):
self._children.extend(children)
Expand Down

0 comments on commit 131618a

Please sign in to comment.