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

Scrolling an element into view #765

Closed
u01jmg3 opened this issue Apr 21, 2020 · 1 comment · Fixed by #766
Closed

Scrolling an element into view #765

u01jmg3 opened this issue Apr 21, 2020 · 1 comment · Fixed by #766

Comments

@u01jmg3
Copy link
Contributor

u01jmg3 commented Apr 21, 2020

I realise the scrollTo($selector) method was added to the core of Dusk.

However, it might be useful to make use of the Element.scrollIntoView() JavaScript API which ensures the selected element is actually in view? Browser support is also good for this API as well as support for document.querySelector.

/**
 * Scroll element into view at the given selector.
 *
 * @param  string  $selector
 * @return $this
 */
public function scrollIntoView($selector)
{
    $selector = addslashes($this->resolver->format($selector));

    $this->driver->executeScript("document.querySelector(\"$selector\").scrollIntoView();");

    return $this;
}
@driesvints
Copy link
Member

Sure feel free to PR

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.

2 participants