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

'Auto' id namespacing for shiny's Module() #24

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions htmltools/_core.py
Expand Up @@ -321,6 +321,10 @@ class TagAttrs(Dict[str, str]):
More attributes.
"""

@staticmethod
def _namespace_id(x: str) -> str:
return x

def __init__(self, *args: Mapping[str, TagAttrArg], **kwargs: TagAttrArg) -> None:
super().__init__()
self.update(*args, **kwargs)
Expand All @@ -339,6 +343,13 @@ def update( # type: ignore
if kwargs:
args = args + (kwargs,)

try:
from shiny._namespaces import namespaced_id

setattr(self, "_namespace_id", namespaced_id)
except ImportError:
pass

attrz: Dict[str, Union[str, HTML]] = {}
for arg in args:
for k, v in arg.items():
Expand All @@ -351,6 +362,9 @@ def update( # type: ignore
if nm in attrz:
val = attrz[nm] + HTML(" ") + val

if nm == "id":
val = self._namespace_id(val)

attrz[nm] = val

super().update(attrz)
Expand Down