Browse Source

introduce ui.link_target #136

Falko Schindler 2 years ago
parent
commit
7c71e13db5
2 changed files with 18 additions and 1 deletions
  1. 17 0
      nicegui/elements/link.py
  2. 1 1
      nicegui/ui.py

+ 17 - 0
nicegui/elements/link.py

@@ -3,6 +3,7 @@ from typing import Callable, Union
 import justpy as jp
 import justpy as jp
 
 
 from .. import globals
 from .. import globals
+from .element import Element
 from .group import Group
 from .group import Group
 
 
 
 
@@ -13,6 +14,9 @@ class Link(Group):
 
 
         Create a hyperlink.
         Create a hyperlink.
 
 
+        To jump to a specific location within a page you can place linkable anchors with `ui.link_target("name")`
+        and link to it with `ui.link(target="#name")`.
+
         :param text: display text
         :param text: display text
         :param target: page function or string that is a an absolute URL or relative path from base URL
         :param target: page function or string that is a an absolute URL or relative path from base URL
         """
         """
@@ -20,3 +24,16 @@ class Link(Group):
         view = jp.A(text=text, href=href, classes='underline text-blue', temp=False)
         view = jp.A(text=text, href=href, classes='underline text-blue', temp=False)
 
 
         super().__init__(view)
         super().__init__(view)
+
+
+class LinkTarget(Element):
+
+    def __init__(self, name: str) -> None:
+        """Link target
+
+        Create an anchor tag that can be used as inner-page target for links.
+
+        :param name: target name
+        """
+        view = jp.A(name=name, temp=False)
+        super().__init__(view)

+ 1 - 1
nicegui/ui.py

@@ -32,7 +32,7 @@ class Ui:
     from .elements.joystick import Joystick as joystick
     from .elements.joystick import Joystick as joystick
     from .elements.keyboard import Keyboard as keyboard
     from .elements.keyboard import Keyboard as keyboard
     from .elements.label import Label as label
     from .elements.label import Label as label
-    from .elements.link import Link as link
+    from .elements.link import Link as link, LinkTarget as link_target
     from .elements.log import Log as log
     from .elements.log import Log as log
     from .elements.markdown import Markdown as markdown
     from .elements.markdown import Markdown as markdown
     from .elements.menu import Menu as menu
     from .elements.menu import Menu as menu