-
Notifications
You must be signed in to change notification settings - Fork 638
Fix selected choice was not reliably highlighted when opening the dropdown #1339
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
Conversation
|
Unsure but the tests failing seem to be unrelated (Screenshots differing by a pixel) |
|
I think a boolean check on when the |
You are right that it could be improved upon but it's not a boolean check, it has just never been accounted for as explained below:
So my best bet right now is to set the highlightPosition based on the type in this._highlightPosition = passedElement instanceof WrappedSelect ? passedElement.element.selectedIndex : 0;I did update the PR c663c6f according to my explanation, the caveat being that this would not work for options that were sorted aftewards or through data-attributes or anything else but that could be a known limitation and the highlighted choice should be updated with own logic after a custom sort. Mind that the behavior will already account for no items selected due to |
|
This does look like it will fix the initial highlighted items, but might not handle the I will need to run some tests and doublecheck this, as the logic is on the more complex side. I'll probably setup some new e2e tests to cover this behavior |
|
Yuck, the legacy placeholder ( |
|
Hmm... how about passing the element from the store within the render method? Or is it the same case here? |
|
Not using the Choices/src/scripts/choices.ts Line 1056 in d6b4d50
With that, if there is no selected choice in the store, it would still pass a null value, leading to the same behavior as before: this._highlightChoice(this._store.items[0]?.choiceEl);It would also preselect the custom options and handle all the other cases. |
|
I've tinkered reproducing the linked issues, and I believe this fixes the most cases. Adding to |
|
Refactoring |
|
Yeah, latest change will also work and seems way better to me than the store solution, I do however think that 605ca42 will break it again, most likely due to this line Looks like you've already seen that 🙈 |
|
This is looking better now, and should address the caveats from the previous solution. I think this definitely needs some E2E tests to validate the behavior so it stays fixed. I should have some time for that tomorrow-ish, but if you want to take a stab at it that would be good for someone else to contribute to those playwright tests |
Got some time on my hand today so might look into these but can't promise🤞. |
…as this state is redundnant
… is set as this state is redundnant" This reverts commit 605ca42.
a935ec6 to
65aed56
Compare
|
The latest commit 305a925 should fix the broken search that was caught by the tests (if e.g. So we should only ever have a highlightedEl when we are
Also pushed the current main into the branch as there have already been merge conflicts due to the modified screenshots. Mind that I updated the
With that, everything should work as expected, tests for single-select and multi-select will be added as well. |
| /* known limitation due to highlighting the first choice only right now */ | ||
| // await expect(suite.choices.nth(3)).toHaveClass(/is-highlighted/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is commented out as the current implementation cannot highlight multiple elements right now.
We could remove the check for else if (!highlightedEl), rename it to highlightedElements and either run _highlightChoice multiple times or change it that it would allow an array.


Description
This one was on my list for a while but I had to check where to apply this one as easy as possible.
Basically this highlights the first selected choice in the dropdown on init / rendering of the items
This will fix all of these (as they are duplicates)
Types of changes
Checklist