-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Programmatically focus select component #856
Comments
I've also looked at this, I work with Ryan. The problem is that the placeholder element sits above the input element. Sending keys to the placeholder element crashes PhantomJS 2.0 and 2.1, so that won't work. Setting the value of the input element does not do anything. Using I consider this a bug with react-select and not our testing as react-select is doing strange things to do the DOM that break how input elements are supposed to work. |
Oh, and we're using 1.0.0-beta5 |
Anybody figure this out? |
Unfortunately, we ended up rolling our own autocomplete instead. |
I think I figured it out. I think it's something like: $('.Select-input input').trigger('mousedown');
$('div.Select-option').first().trigger('mousedown'); |
From what I saw when firing mousedown on the select the input.focus() is called, but the render is not (until I actually click on the screen). |
@radar Can confirm this is awkward using Selenium too -
The overlaying of elements is confusing the web driver it seems. For what it's worth, this works completely fine with Capybara and the |
@ilantc have you found a solution to fix that issue? |
@timsheng |
@ilantc, can you write here that piece of code that worked? |
@liorbentov If you're using the const input = yourElement.querySelector('input');
TestUtils.Simulate.focus(input);
const selectArrow = yourElement.querySelector('.Select-arrow');
TestUtils.Simulate.mouseDown(selectArrow, { button: 0 }); It is possible to use enzyme etc, the important thing is that you need to focus on the input, then mouse down on the Select-arrow with button 0 set. |
@AlanFoster thanks! |
@liorbentov Unfortunately I was only able to trigger the component to open with selenium/capybara with JavaScript directly, due to the component's DOM structure and how it's styled on the page. |
@JedWatson any update on this? is there any way that we can actually trigger programmatically the selection dropdown? I'm currently using NightmareJS and cannot find any working solution. |
Looking for a similar thing. trying to write integration tests using zombiejs but unable to find the best way to programmatically trigger the dropdown. |
@nathanielescribano I finally found out a way to make tests work. I'm testing with NightmareJS, so there is a package https://github.com/Mr0grog/nightmare-real-mouse for triggering real mouse events on the browser. This solution worked fine for me. You may probably need a relative solution with ZombieJS, since it is also testing on headless browser. |
see also #603 Document how to test with selenium |
This worked for me using Selenium:
The xpath there is to the input element |
Does anyone know how to simulate selection on this component using just Javascript? The code samples above did not work for me. $('.Select-input input').trigger('mousedown');
$('div.Select-option').first().trigger('mousedown'); I need a solution I can use in my integration tests. I'm using React 15.6.2 and react-select 1.2.1. |
@volkanunsal after a few failed tentatives, I ended up doing 'brute force' by tabbing, going down with the arrow key and then sending an enter.
|
I was able to get the menu opened with following code: Note that this is casperJS syntax. However I feel you can extend this to any other framework. |
Was anyone able to find a fix for selenium? |
I'm also not able to solve it - it seems jQuery is not an option: facebook/react#3249 |
I am also not been able to trigger it with jasmine. |
It seems to changes in library itself, so we need to trigger event This link may be helpful to testing in chrome (presumably puppeteer for integration tests): https://stackoverflow.com/a/42447620 |
A |
Hi all, Thank you everyone who had a part in addressing this question. In an effort to sustain the However, if you feel this issue is still relevant and you'd like us to review it, or have any suggestions regarding this going forward - please leave a comment and we'll do our best to get back to you! |
Tried all the options above, nothing worked in plain js for me. selectContainer
.querySelector(".YOUR_CUSTOM_CLASS__dropdown-indicator")
.dispatchEvent(
new MouseEvent("mousedown", {
button: 0,
bubbles: true, // this is key, otherwise it wont work
})
); // open the menu by "clicking" dropdown indicator Where |
if we want to do it via react test library I would always recommend to check the actual tests from this library, they are the key to understand what needs to be triggered.
If we are talking about vanilla js, we can do it like this:
|
I'm looking to write an integration test for a form that uses a react-select component. This is the Ruby code that I have for it now:
I would believe this would:
However, I'm getting this error in my tests:
I would consider documentation for how to integration test a react-select (even if it is with some jQuery functions) would be something that this library should provide. I am considering this a "bug" with the documentation for this component, which is why I'm filing this issue.
Please add some examples of programatically triggering / filling in this element with jQuery.
The text was updated successfully, but these errors were encountered: