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

sl-switch and sl-checkbox allow scrolling out of bounds #1169

Closed
freeformflow opened this issue Feb 2, 2023 · 3 comments
Closed

sl-switch and sl-checkbox allow scrolling out of bounds #1169

freeformflow opened this issue Feb 2, 2023 · 3 comments
Assignees
Labels
bug Things that aren't working right in the library.

Comments

@freeformflow
Copy link

freeformflow commented Feb 2, 2023

Describe the bug

I'm encountering strange scrolling behavior caused by the sl-switch and sl-checkbox components under specific conditions. When they appear in the initial scroll view, the behavior is expected. However, when they appear beyond the initial scroll view, the entire viewport allows scrolling beyond the root html container.

In Chrome, when you toggle one of these elements, the scroll pops out of bounds, too. Even if I use CSS to constrain scrolling, the bug programmatically puts the scroll position beyond what you can reach with a scrollwheel. There are no errors listed in the console.

Demo

I've prepared a CodePen with a simplified representation. https://codepen.io/freeformflow/pen/rNroBMr?editors=1101

Updated repro with instructions: https://codepen.io/claviska/pen/JjBzyeJ

I constrained the html container to make it more clear. The blue section on the left in blue represents a nav that doesn't scroll. The section on the right has several panels with enough height that it must scroll. The way it's setup now, it will behave properly. If you uncomment the markup starting on line 29, you will see the bug behavior. When I run the demo in Chrome, toggling the lower switches pops the scroll outside the html container. That doesn't happen in Safari for me. I was also able to reproduce this behavior with sl-checkbox.

Browser / OS

  • OS: Mac
  • Browser: Chrome
    • Version 109.0.5414.87 (Official Build) (x86_64)
  • Browser: Safari
    • Version 14.1.1 (15611.2.7.1.6, 15611)
@freeformflow freeformflow added the bug Things that aren't working right in the library. label Feb 2, 2023
@claviska
Copy link
Member

claviska commented Feb 3, 2023

I was able to repro it in Chrome, Firefox, and Safari. It seems to happen when the <sl-switch> receives focus. I'll have to track this down next week. The same behavior also occurs with <sl-checkbox>.

If anyone wants to take a stab at this over the weekend, consider it fair game.

Here's an updated repro: https://codepen.io/claviska/pen/JjBzyeJ

@claviska claviska added help wanted Ready for a contributor to tackle. good first issue This bug or task is a good first issue for new contributors. labels Feb 3, 2023
@claviska claviska removed help wanted Ready for a contributor to tackle. good first issue This bug or task is a good first issue for new contributors. labels Feb 5, 2023
@claviska
Copy link
Member

claviska commented Feb 5, 2023

This was tricky to track down, but the root cause was the hidden <input> that's used by Switch and Checkbox under the hood. To hide it, the following CSS is used:

.switch__input {
  position: absolute;
  opacity: 0;
  padding: 0;
  margin: 0;
  pointer-events: none;
}

Unfortunately, there was supposed to be a container with position: relative around it to ensure it remains in the correct place for constraint validation positioning and scrolling.

Changing opacity to 1 in the dev console provides a better understanding as to why this happens. Notice the position of the checkboxes below. This is where the browser was scrolling to on focus, causing the bug.

CleanShot 2023-02-05 at 12 11 26@2x

Thanks for reporting this, and especially for the excellent repro! The fix landed in 7549e50 and will be available in the next release.

@freeformflow
Copy link
Author

Thank you for looking at that so quickly and making the fix. ✨🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Things that aren't working right in the library.
Projects
None yet
Development

No branches or pull requests

2 participants