Skip to content

feat: Validate if an element to scroll is actually scrollable #118

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

Merged
merged 5 commits into from
Mar 3, 2025

Conversation

just-boris
Copy link
Member

Issue #, if available:

Description of changes:

Make sure that we attempt to scroll an element which is actually scrollable

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link

codecov bot commented Oct 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.66%. Comparing base (044286b) to head (6e0b26c).
Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #118   +/-   ##
=======================================
  Coverage   91.66%   91.66%           
=======================================
  Files          18       18           
  Lines         396      396           
  Branches       63       63           
=======================================
  Hits          363      363           
  Misses         29       29           
  Partials        4        4           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Al-Dani Al-Dani marked this pull request as ready for review February 17, 2025 13:39
@Al-Dani Al-Dani requested a review from a team as a code owner February 17, 2025 13:39
@Al-Dani Al-Dani requested review from taheramr and removed request for a team February 17, 2025 13:39
@Al-Dani Al-Dani self-assigned this Feb 18, 2025
taheramr
taheramr previously approved these changes Feb 25, 2025
Copy link
Member

@taheramr taheramr left a comment

Choose a reason for hiding this comment

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

Left a couple of comments that are non-blocking

throw new Error('Element ' + selector + ' has not been found at the page');
const overflowStyles = getComputedStyle(element)[overflowDirection].split(' ');
if (!overflowStyles.includes('auto') && !overflowStyles.includes('scroll') && element !== document.documentElement) {
throw new Error('Element ' + selector + ' is not scrollable');
Copy link
Member

Choose a reason for hiding this comment

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

can we align using the formatting of errors strings? I see some exaples using the `` and some using '' + ''

could it be:

throw new Error(`Element ${selector}  is not scrollable`);

}
element.scrollTop = top;
element.scrollLeft = left;
}

export function getElementScrollPosition(selector: string): ScrollPosition {
var element = document.querySelector(selector);
Copy link
Member

Choose a reason for hiding this comment

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

Away from the changes but can this be const instead?

@Al-Dani Al-Dani added this pull request to the merge queue Mar 3, 2025
Merged via the queue into main with commit 8e6c290 Mar 3, 2025
36 checks passed
@Al-Dani Al-Dani deleted the scroll-validation branch March 3, 2025 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants