Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Add Autocomplete component #2808

Merged
merged 15 commits into from
Aug 21, 2019
Merged

Add Autocomplete component #2808

merged 15 commits into from
Aug 21, 2019

Conversation

joshuatf
Copy link
Contributor

Fixes #2527

Adds an autocomplete component with filterable options.

There are a few areas this does not cover and will be handled in a follow-up since this PR is already rather large:

  • Swapping out the old Autocomplete component inside the Search component.
  • Swapping out existing dropdowns for items that will benefit from this component (e.g., the country selector).
  • Implementing "matching" to bold/highlight matching portions of search queries.

Questions

  • Design-wise this needs a look over. Should we use transitions for label movements? Is the menu highlighting contrasted enough? The label/placeholder hiding is a bit different from existing newspack components (I believe they were incorrect and this component more closely mirrors those seen in Material).
  • Should this component offer an option to hide the search field, allowing it to become a styled select component? This may consolidate efforts between various components. If "yes," should this be renamed to Select or something similar?

Accessibility

  • I've tested using only a keyboard (no mouse)
  • I've tested using a screen reader

Screenshots

Screen Shot 2019-08-19 at 2 12 40 PM

Detailed test instructions:

  1. Go to the Autocomplete component in the Devdocs.
  2. Test all 3 examples and make sure they work as expected and are styled as expected.
  3. Test with a keyboard and screen reader. Make sure the component is a11y friendly.

Here are some references to check against in terms of accessibility standards (note this uses ARIA 1.0 as it seems this still has more support than 1.1 and there aren't plans to deprecate):

@joshuatf joshuatf added [Status] Needs Review focus: accessibility The issue/PR is related to accessibility. focus: components Issues for woocommerce components labels Aug 19, 2019
@joshuatf joshuatf requested review from jameskoster and a team August 19, 2019 06:24
@joshuatf joshuatf self-assigned this Aug 19, 2019
Copy link
Contributor

@rrennick rrennick left a comment

Choose a reason for hiding this comment

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

@joshuatf This works great. The only thing I found is that it needs docs/packages/components/autocomplete.md for the single component doc page to work.

Copy link
Collaborator

@justinshreve justinshreve left a comment

Choose a reason for hiding this comment

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

This is testing well for me. All CLI tests are passing as well. Besides my minor comment, we should add the documentation Ron noted below too.

The label/placeholder hiding is a bit different from existing newspack components (I believe they were incorrect and this component more closely mirrors those seen in Material).

If I recall correctly, I had to adjust the behavior in the calypso-ui port of TextControl as well. I think this is another reason to standardize/move components somewhere we can have more control over.

This display of this with inline tags looks a bit off to me:

Screen Shot 2019-08-19 at 1 40 33 PM

I think the label should be above the tags and text, like it would be in a text input.

Should this component offer an option to hide the search field, allowing it to become a styled select component? This may consolidate efforts between various components. If "yes," should this be renamed to Select or something similar?

That would be cool, and would help reduce the different components we have floating around (where a prop might suffice). We'll probably want to log an issue for the consolidation effort.

packages/components/src/autocomplete/control.js Outdated Show resolved Hide resolved
@joshuatf
Copy link
Contributor Author

Thanks for the review @rrennick and @justinshreve 😄

The only thing I found is that it needs docs/packages/components/autocomplete.md for the single component doc page to work.

Added these and other missing doc files.

I think the label should be above the tags and text, like it would be in a text input.

I think you're right. One small side effect from doing this means tags need to be reduced in height slightly:

Screen Shot 2019-08-20 at 9 56 46 AM

Also applied other feedback and gave this PR a rebase.

@rrennick
Copy link
Contributor

@joshuatf Looks great for me.

Copy link
Collaborator

@justinshreve justinshreve left a comment

Choose a reason for hiding this comment

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

Changes look good and are testing well 👍.

@joshuatf joshuatf merged commit fe854f1 into master Aug 21, 2019
@joshuatf joshuatf deleted the add/autocomplete branch August 21, 2019 06:41
Copy link
Collaborator

@psealock psealock left a comment

Choose a reason for hiding this comment

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

Amazing job with this @joshuatf! Sorry for the late review. I think this is a great start and gets us what we need. I found a few things off with keyboard interactions and noted two that I think are important because keyboard only users can get stuck.

Another really nice addition would be a focus state on the inputs.

Screen Shot 2019-08-22 at 2 25 41 PM

const filtered = [];

// Create a regular expression to filter the options.
const expression = getSearchExpression( escapeRegExp( query.trim() ) );
Copy link
Collaborator

Choose a reason for hiding this comment

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

On inline tags with the options always visible, pressing the escape key results in an error index.js:126 Uncaught TypeError: Cannot read property 'trim' of null.

Tab should also allow me to move on, but using only the keyboard you can get stuck. See the other comment.

event.stopPropagation();
break;

case TAB:
Copy link
Collaborator

Choose a reason for hiding this comment

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

The tab functionality in https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.1pattern/listbox-combo.html brings focus to the next focusable element even when the options are visible.

Here, tab brings me to the next focusable element only when the options are hidden. In the case of the first example in dev docs, if you navigate to it using tab, you can't tab out of it unless something is selected.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
focus: accessibility The issue/PR is related to accessibility. focus: components Issues for woocommerce components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Autocomplete Component
4 participants