diff --git a/shiny/types.py b/shiny/types.py index 4680faf68..562ec5d4b 100644 --- a/shiny/types.py +++ b/shiny/types.py @@ -209,7 +209,7 @@ def resolve( """ ... - def get_value(self) -> Optional[str]: + def get_value(self) -> str | None: """ Get the value of this navigation item (if any). diff --git a/shiny/ui/_navs.py b/shiny/ui/_navs.py index 2480c03fb..a87d8bb9d 100644 --- a/shiny/ui/_navs.py +++ b/shiny/ui/_navs.py @@ -91,11 +91,14 @@ def resolve( return nav, content - def get_value(self) -> str | HTML | None: + def get_value(self) -> str | None: if self.content is None: return None a_tag = cast(Tag, self.nav.children[0]) - return a_tag.attrs.get("data-value", None) + data_value_attr = a_tag.attrs.get("data-value", None) + if isinstance(data_value_attr, HTML): + data_value_attr = str(data_value_attr) + return data_value_attr def tagify(self) -> None: raise NotImplementedError( @@ -279,7 +282,7 @@ def resolve( content.children, ) - def get_value(self) -> Optional[str]: + def get_value(self) -> str | None: for x in self.nav_controls: val = x.get_value() if val: