selectOptions
doesn't work when 'listbox' lives outside of select element
#522
Labels
accuracy
Improves the accuracy of how behavior is simulated
needs investigation
Someone has to do research on this
Environment
@testing-library/user-event
version: 12.2.2Problem description
selectOptions
anddeselectOptions
does not work if the dropdown menu is a child of some other element, saydocument.body
for example. It's because the current logic looks for options inside the given select element, and in the given scenario, it can't find any and it throws theValue [X] not found in options
error.Suggested solution
Instead of looking for options "inside" the select element straight up, we could first check if the given select element is "pseudo-select" by checking the
aria-haspopup
attribute and if it has a linkedlistbox
through a sharedlabelledby
pointer.downshift
for one, has been tested to work with the proposed setup below.If both the assertions are positive, then we could handle the selection and deselection like so:
Notice the call signature of
selectOptions
anddeselectOptions
; it's 100% compliant and backwards compatible with current signatureThe text was updated successfully, but these errors were encountered: