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

feat(autocomplete simple): react component for autocomplete - simple variation #191

Merged
merged 20 commits into from
Oct 29, 2019

Conversation

juanigalan91
Copy link
Contributor

@juanigalan91 juanigalan91 commented Oct 14, 2019

Created the first version of the autocomplete component. it supports:

  • Filter options based on a given input
  • Control over the value, options, and when the suggestions are displayed or not
  • Navigate between options using the keyboard
  • Selecting one option either by clicking or pressing Enter

Simple usage
QHePgrkFJV

Keyboard navigation
BrMiLlz37o

No results
BRTzGGX353

Note: this variation may need css changes since the no results label is a little bit more gray on the mockups.

Leave and come back
96ohhIcDx4

Side effects:

  • ListItem: in order to allow the keyboard navigation, it was necessary to add some sort of mechanism to ListItem in order to, from the outside, control which ListItem is highlighted. To do that, we can create a new prop called isHighlighted and control the boolean from the outside
  • TextField: added textFieldRef in order to forward the ref, since Dropdown needs that reference to display the popover. Also, TextField did not allow to override onFocus and onBlur, so now, when the onFocus and onBlur are executed inside the component, they will check whether there are functions passed in as props and they will be executed first. inputRef was also added since it is necessary to have a reference to the actual input, and not the wrapper as textFieldRef did.

@juanigalan91 juanigalan91 changed the title feat(autocomplete simple): react component for autocomplete feat(autocomplete simple): react component for autocomplete - simple variation Oct 14, 2019
src/components/autocomplete/react/Autocomplete.tsx Outdated Show resolved Hide resolved
src/components/autocomplete/react/Autocomplete.tsx Outdated Show resolved Hide resolved
src/components/autocomplete/react/Autocomplete.tsx Outdated Show resolved Hide resolved
src/components/autocomplete/react/Autocomplete.tsx Outdated Show resolved Hide resolved
src/components/autocomplete/react/Autocomplete.test.tsx Outdated Show resolved Hide resolved
src/components/list/react/ListItem.tsx Outdated Show resolved Hide resolved
src/components/text-field/react/TextField.tsx Outdated Show resolved Hide resolved
src/components/autocomplete/react/Autocomplete.tsx Outdated Show resolved Hide resolved
demo/react/doc/product/components/autocomplete.mdx Outdated Show resolved Hide resolved
demo/react/doc/product/components/autocomplete.mdx Outdated Show resolved Hide resolved
Copy link
Member

@gcornut gcornut left a comment

Choose a reason for hiding this comment

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

Good job on this component 👍

@matmkian
Copy link
Collaborator

I don't understand why we don't focus the list and focus elements on keyboard navigation -> check what have been done in angularjs on dropdown.

@juanigalan91
Copy link
Contributor Author

We can discuss it in our meeting today!

@juanigalan91
Copy link
Contributor Author

Just for visibility purposes, we discussed and the reason why we need the isHighlighted prop is that if we move the focus to the list, we loose it on the text field, so the user cannot continue typing. By taking this approach, we can "highlight" a result while maintaining focus on the text field

@FlorentDinet
Copy link
Contributor

Nice work !
My only doubt come from the "no result" which is indeed to close to an actual "suggestion item"
Capture d’écran 2019-10-28 à 14 57 38
I'll suggest to display nothing, when there is no suggestion

@juanigalan91
Copy link
Contributor Author

Awesome, I can definitely do that!

@FlorentDinet
Copy link
Contributor

Nice
I did catch something when hitting backspace key :
Oct-28-2019 16-27-47

losing focus on backspace

@juanigalan91
Copy link
Contributor Author

@FlorentDinet fixed ! thanks for the catch !

@FlorentDinet
Copy link
Contributor

ok, last thing I saw is that we're kind of "stuck" in the field with keyboard navigation:

  • can't hit "tab" to focus next input
  • can't hit "shift+tab" to focus previous input

I'd understand if tab was used to navigate between suggestions but that's not the case

Anyway it's not blocking, just icing on the cake

@juanigalan91
Copy link
Contributor Author

@FlorentDinet got it, on my end I see that as a blocker, it is definitely not a good UX. It was a quick fix, so there it is! would you mind trying again ?

@FlorentDinet
Copy link
Contributor

👌

@gcornut gcornut merged commit 492fb72 into master Oct 29, 2019
@gcornut gcornut deleted the feat/autocomplete-simple branch October 29, 2019 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants