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

[AutoComplete] Fix first item selection on keyboard focus #3867

Conversation

viniciusdacal
Copy link

This fix first item selection at autocomplete popover, described at #3629.
If you type 'a' in the input, and hit down arrow to select the first item, you don't see the selection, if you press again, the second item will be selected.
http://www.material-ui.com/#/components/auto-complete

Fixes #3629.

@mbrookes mbrookes changed the title [autocomplete]Fix first item selection when keyboard focus [AutoComplete] Fix first item selection on keyboard focus Apr 3, 2016
@mbrookes
Copy link
Member

mbrookes commented Apr 3, 2016

Thanks for recreating the PR.

@mbrookes mbrookes added the bug 🐛 Something doesn't work label Apr 3, 2016
@oliviertassinari
Copy link
Member

@viniciusdacal I haven't noticed any issue with the component. That looks good 👍.

@viniciusdacal viniciusdacal force-pushed the autocomplete-first-item-selected branch from 7a08927 to 206fbad Compare April 4, 2016 23:51
@@ -242,6 +248,7 @@ class Menu extends React.Component {
this.setState({
focusIndex: nextProps.disableAutoFocus ? -1 : selectedIndex >= 0 ? selectedIndex : 0,
keyWidth: nextProps.desktop ? 64 : 56,
isKeyboardFocused: nextProps.keyboardFocused || this.state.isKeyboardFocused,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if nextProps.keyboardFocused = false and this.state.isKeyboardFocused = true 😁?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question 😄
Do you think we could use only nextProps.keyboardFocused here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use something like:

isKeyboardFocused: nextProps.keyboardFocused !== null ? nextProps.keyboardFocused : this.state.isKeyboardFocused

@viniciusdacal viniciusdacal force-pushed the autocomplete-first-item-selected branch from 206fbad to 666874e Compare April 7, 2016 00:53
@viniciusdacal
Copy link
Author

@oliviertassinari pr updated.

@oliviertassinari
Copy link
Member

@viniciusdacal Thanks.
Looking at the initial state of isKeyboardFocused we can see that it's set by the props.initiallyKeyboardFocused. Should we use keyboardFocused first and fallback to initiallyKeyboardFocused if it's null?

@viniciusdacal
Copy link
Author

@oliviertassinari make sense for me use keyboardFocused first, the api would be more consistent. Do you want me to change it?

@oliviertassinari
Copy link
Member

@viniciusdacal Yes please 👯.

@viniciusdacal
Copy link
Author

Great.
I can work on this tonight (in 6 hours), I don't have the environment installed here.

@mbrookes mbrookes added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed PR: Needs Review labels Apr 7, 2016
@oliviertassinari
Copy link
Member

Don't worry, no need to rush things :).

On Thu, 7 Apr 2016 19:22 Vinicius Dacal Lopes, notifications@github.com
wrote:

Great.
I can work on this tonight (in 6 hours), I don't have the environment
installed here.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#3867 (comment)

@viniciusdacal viniciusdacal force-pushed the autocomplete-first-item-selected branch from 666874e to 90fb007 Compare April 8, 2016 01:31
@@ -224,7 +230,7 @@ class Menu extends React.Component {

this.state = {
focusIndex: props.disableAutoFocus ? -1 : selectedIndex >= 0 ? selectedIndex : 0,
isKeyboardFocused: props.initiallyKeyboardFocused,
isKeyboardFocused: props.keyboardFocused !== null ? props.keyboardFocused : props.initiallyKeyboardFocused,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oliviertassinari updated 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm missing something -- can that be shortened to props.keyboardFocused || props.initiallyKeyboardFocused

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we set prop keyboardFocused as false, isKeyboardFocused should be false, even if initiallyKeyboardFocused is true

@oliviertassinari
Copy link
Member

@viniciusdacal I have just realized that we can fix the issue with a single line diff commit:

-initiallyKeyboardFocused={false}
+initiallyKeyboardFocused={true}

No need for an extra keyboardFocused property. Can you check that and update the PR if it's working fine 😁?

@viniciusdacal
Copy link
Author

@oliviertassinari I will change to check, but I think this way it will be focused instantly when the menu open, and not only on keydown.

@mbrookes
Copy link
Member

@viniciusdacal - what did you find?

@viniciusdacal
Copy link
Author

@mbrookes I was very busy in the last weeks, but I'm gonna use this weekend to solve this.

@mbrookes mbrookes added on hold There is a blocker, we need to wait and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels May 7, 2016
@mbrookes
Copy link
Member

mbrookes commented May 7, 2016

On hold pending review of alternate fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work on hold There is a blocker, we need to wait
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants