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

Fix disabled after search #395

Merged
merged 2 commits into from
Aug 24, 2015

Conversation

bruderstein
Copy link
Collaborator

This is a fix for the (reopened) #378, where a disabled option can be selected with enter when the search results in only (or a single) disabled option. Tests added to cover this case.

I've refactored a little in order to extract a getFirstFocusableOption function, which simply returns the first none-disabled option from the given options. This is now called in 2 places. This really needs simplifying, such that we're only setting the focused option in one place, but that's a bigger issue and this fixes the immediate issue.

This will probably have an effect on #382, but should definitely go in together.

When searching, and the results contain exactly one result that is disabled,
it was previously "focused" (at least set as the `focusedOption` in state),
hence pressing enter caused it to be selected.

This fixes that, ensuring that:
1. A disabled option does not become the focusedOption
2. When there is no focusedOption, pressing enter does nothing

Closing the menu and leaving the selection empty would be another option,
but that would IMHO feel strange.

Fixes JedWatson#378
This ensures that error messages from unexpected are 
syntax highlighted on ansi terminals, due to an "issue" in 
unexpected, where if first detects the DOM, then if not,
 attempts to check for an ansi terminal. Moving the order 
of the requires works around this issue.
@JedWatson
Copy link
Owner

Nice work @bruderstein - I can't merge #382 yet because of conflicts, but this looks like it's safe to go in first.

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.

2 participants