How to Prevent Automatically Scrolling to Top After Clicking ui.link() #3129
-
QuestionI have a question about behavior in NiceGUI that I can't seem to resolve. In the simplified example code below, each time I click "More...", the first line of text updates to the current time, which works well. However, each time after clicking "More...", the page automatically scrolls to the top. Is there a way to prevent this vertical scrolling after a click? (I would like to keep using ui.link for this functionality in my real application, so I prefer not to change that part of the implementation.) Here's the example code: import time
from nicegui import ui
def update_status(event):
status.text = time.time()
status = ui.label()
status.text = 'initial'
for i in range(222):
ui.label('some label')
ui.link("More...").on('click', update_status)
for i in range(222):
ui.label('some label')
ui.run() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @happybeginning1, The browser is jumping to the top, because status = ui.label('initial')
for _ in range(100):
ui.label('some label')
ui.link('More...').on('click', lambda: status.set_text('clicked')).props(remove='href').classes('cursor-pointer') Note that you need to explicitly set the pointer to "cursor", because anchors without a target are usually not clickable in HTML. |
Beta Was this translation helpful? Give feedback.
I'm not quite sure why the frame scrolls to the top after closing the dialog...
But I suggest to remove the absolute positioning for
ui.tab_panels
and make sure the router frame fills the width: