question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tabs switching cause scrolling up

See original GitHub issue

Summary

app scrolls up when I have tabs after some widgets and switch them

Steps to reproduce

Code snippet:

import streamlit as st

for i in range(20):
    st.markdown("dummy text")


tab1, tab2 = st.tabs(["tab1", "tab2"])

with tab1:
    st.video(video_path)

with tab2:
    st.video(video_path)

steps :

  1. scroll down to the videos
  2. switching tabs

Expected behavior:

tabs should be switched and focus stay on video

Actual behavior:

it scrolling up and I have to scroll down again

Debug info

  • Streamlit version: 1.11.0
  • Python version: 3.8.11

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
LukasMasuchcommented, Aug 1, 2022

@RRaphaell Thanks for reporting this issue! I was able to reproduce it and have deployed a demo app here. The underlying issue is that when changing tabs, the height of the actual tab content is not correct for a split second. This influences the full height of the app -> which in turn influences the maximum possible scroll position -> and this causes the unexpected up scroll. This does not happen if there is enough content underneath the tab (try out in the demo app), since in that case the scroll position will not be larger than the maximum possible.

To find a solution here requires a bit more investigation. I tried out the renderAll property of the baseWeb component, but this only fixes it for a second tab change.

1reaction
LukasMasuchcommented, Aug 8, 2022

@sfc-gh-tszerszen Thanks for investigating this! I think there are also a few other elements without a fixed height. For example, our built-in chart commands:

import streamlit as st
import pandas as pd
import numpy as np

chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])

for i in range(20):
    st.markdown("dummy text")


tab1, tab2 = st.tabs(["tab1", "tab2"])

with tab1:
    st.line_chart(chart_data)

with tab2:
    st.line_chart(chart_data)

So, we might need to figure out which elements are affected and apply the same fix.

I’d like to set fixed height on first componentDidMount, what do you think about such proposition?

Would be great if we can fix it this way, but this needs some testing if there are any negative side effects. E.g. in some situations, components are reused for different content, so just fixing the height on componentDidMount might lead to wrong height in some situations.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Clicking JS Tabs Causes Browser to Scroll Up - Stack Overflow
It only happens if you scroll down so the video is above the bottom of your browser. It seems to be a problem...
Read more >
Uncontrollable Scrolling - Microsoft Community
Anywhere in the settings app, if the page can be scrolled down it will scroll down to the bottom even after resizing the...
Read more >
Allow switching tabs by scrolling in the tab bar when it doesn't ...
Firefox uses the mouse wheel in the tabbar to scroll the tabs when they are overflowing. We won't be able to change tabs...
Read more >
How to prevent switching tabs using horizontal mouse scroll in ...
According to this thread the Chromium development team fixed the issue in late August 2019 and it was included in Release 77 of...
Read more >
Fix Infinite/Automatic Scrolling On Windows 10/11 PC - YouTube
How to Fix Automatic/Infinite Scrolling On Windows 11/10 PC,Windows 10/11 ... Windows 10/11 mouse scrolling automatically up or down,Mouse ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found