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

Bug: scroll position changes when the button is dropdown #33993

Closed
delef opened this issue May 15, 2021 · 7 comments · Fixed by #35736
Closed

Bug: scroll position changes when the button is dropdown #33993

delef opened this issue May 15, 2021 · 7 comments · Fixed by #35736

Comments

@delef
Copy link

delef commented May 15, 2021

009455260bd0a7ab75fc0c9d2f295f7b

  • Operating system and version: macOS, 11.3
  • Browser and version: Safari, 14.1
@anderlaw
Copy link

bro, you need to provide steps to reproduce this issue

@alpadev
Copy link
Contributor

alpadev commented May 16, 2021

Someone of @twbs/css-review owes me a coffee!😏

Figured it might be something with our JS. It happens because of the button receiving focus which is done programmatically in our script. (Safari doesn't focus a button automatically when you click it.. go figure)

The click that closes it returns focus to the body again, because we focus it only when we call show(). So toggling the dropdown like this, will make the focus change back and forth between body and the dropdown button, as such the behaviour is repeating.

This only happens because the navbar is made sticky - with fixed it doesn't do that.

As a side note, I couldn't find any bug report about our page scrolling when you type something into the search. (Which happens for Chromium based, Firefox and Safari. Why I mention it? Because this is caused by the same thing..)

The reason for all this is https://github.com/twbs/bootstrap/blob/main/site/assets/scss/_content.scss#L6-L10

@ffoodd
Copy link
Member

ffoodd commented May 17, 2021

Does it only happen in Safari? I can't reproduce on either Firefox or Chromium on Ubuntu.

This looks like an odd browser bug, and since we don't use scroll-padding-top in Bootstrap itself I'd say that's not a big deal. Could try to find a workaround for Safari, but I probably won't take time to search for it :/

@ffoodd
Copy link
Member

ffoodd commented May 17, 2021

Ow and @alpadev up for the coffee ;)

@alpadev
Copy link
Contributor

alpadev commented May 17, 2021

@ffoodd yeah the dropdown toggle scroll only happens in Safari.

Scrolling while typing into the search tho, happens for me on Chromium based and Firefox (nightly) on Windows, Safari on Mac.

scroll-search

The reason for this seems to be that scroll-padding will shrink what the spec calls optimal viewing region. If you enter text into inputs (or they receive focus) the default behaviour is to scroll inputs into view. This seems to respect this scroll-padding, so if the input is located in that scroll-padding area, the browser is trying to move it underneath by scrolling the page. At least that's how I understand it.

Edit: Looks like the scroll on input is going to be addressed for Chromium - https://bugs.chromium.org/p/chromium/issues/detail?id=1178622

@mdo
Copy link
Member

mdo commented Feb 23, 2022

Thinking the thing to do is to drop scroll-padding and restore the heading:target selectors with margin-top that we used to have. Thoughts?

@ffoodd
Copy link
Member

ffoodd commented Feb 23, 2022

Agreed, that's sad but I can't think of another workaround for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants