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

[6.x] Support executing closures outside of the current selector scope #784

Merged
merged 1 commit into from
Jun 11, 2020
Merged

[6.x] Support executing closures outside of the current selector scope #784

merged 1 commit into from
Jun 11, 2020

Conversation

Infamoustrey
Copy link

There are scenarios, particularly when writing logic to encapsulate components that don't necessarily have a linear structure in the dom, that you might want to run certain logic outside of your current selector scope. This function simply executes a closure outside of the current scope.

Consider the following html generated from a js component from a popular react framework:

<div class="mui-select">
   <label>My Label</label>
   <div>...input display</div>
</div>

... other portions of the page

<div class="mui-menu">
  <ul>
     <li class="select-option">1</li>
     <li class="select-option">2</li>
     <li class="select-option">3</li>
  </ul>
</div>

To interact with this component before you had to do something like this:

public function selectFromDropdown(Browser $browser, string $value)
{ 
    $prefix = $browser->resolver->prefix;
    $browser->resolver->prefix = "";
    $browser->within('.mui-menu', function ($browser) use ($value) {
           // do unscoped stuff
     });
    $browser->resolver->prefix = $prefix;
}

Now the code will look something like this:

public function selectFromDropdown(Browser $browser, string $value)
{ 
    $browser->elsewhere('.mui-menu', function ($browser) use ($value) {
        // do unscoped stuff 
    }); 
}

Closes #783

@driesvints driesvints changed the title Support executing closures outside of the current selector scope [6.x] Support executing closures outside of the current selector scope Jun 11, 2020
@taylorotwell taylorotwell merged commit b114f3c into laravel:6.x Jun 11, 2020
@taylorotwell
Copy link
Member

Can you make a PR to laravel/docs to document this?

@Infamoustrey
Copy link
Author

Will do!

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.

A way to break selector scope
3 participants