Skip to content

fix: horizontally align combo-box overlay - #2153

Merged
web-padawan merged 2 commits into
masterfrom
fix/horizontal-alignment
Jul 8, 2021
Merged

web-padawan merged 2 commits into
masterfrom
fix/horizontal-alignment

Conversation

@yuriy-fix

Copy link
Copy Markdown
Contributor

Fixes #411

@yuriy-fix
yuriy-fix marked this pull request as ready for review June 24, 2021 11:36

_shouldAlignLeft(targetRect) {
const spaceRight =
(window.innerWidth - targetRect.right - Math.min(document.body.scrollLeft, 0)) / window.innerWidth;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of curious why this tries to subtract negative scroll positions?
First, how do you get a negative scroll position? I can only image rubber banding on iOS / Mac, but I can't image how that would be relevant here. Tried with Chrome, FF, Safari, they all report 0 even when doing rubber banding. Also there is no horizontal rubber banding I think?

Second, bounding client rect already accounts for scrolling by reporting the positions relative to the viewport, so whatever the scroll value is, it has already been subtracted from the rect.

@vursen vursen Jun 25, 2021 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sissbruecker Seems there is the case when scrollLeft takes a negative value:

If the element's direction is rtl (right-to-left), then scrollLeft is 0 when the scrollbar is at its rightmost position (at the start of the scrolled content), and then increasingly negative as you scroll towards the end of the content.

https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollLeft

@vursen vursen Jun 25, 2021 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...if this is the case, it might be worth creating another test case to cover direction=rtl.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK thanks, that would explain how it can assume a negative value.

However I'm still sceptical of the logic, as bounding client rect should already compensate for the scroll position: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#value

I might just have to test this, I'm having a hard time visualising this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that it's not required to cover the rtl case. Removed.

@sonarqubecloud

sonarqubecloud Bot commented Jul 6, 2021

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@web-padawan web-padawan changed the title fix: horizontally align overlay fix: horizontally align combo-box overlay Jul 8, 2021
@web-padawan
web-padawan merged commit 06f4741 into master Jul 8, 2021
@web-padawan
web-padawan deleted the fix/horizontal-alignment branch July 8, 2021 12:22
web-padawan pushed a commit that referenced this pull request Jul 11, 2021
Co-authored-by: Yuriy Yevstihnyeyev <yuriy@vaadin.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ComboBox with a wide overlay overflows the screen

5 participants