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: show all items Behavior #2484

Open
wants to merge 59 commits into
base: main
Choose a base branch
from

Conversation

rjavier-trimbler
Copy link
Contributor

@rjavier-trimbler rjavier-trimbler commented Apr 26, 2024

Description

Behavior here:
Default:
1- it shows all options when focus
2- if you click an option it will highlight it and hide the combo box
3- if you click on the autocomplete again it will show all the options with the selected option
4- if you're typing, it will filter the options
5- if there's no matches then it will show the "no found message" and when you focusOut it will place the previous option selected
6- if you clear the autocomplete then it will remove the highlighted option selected

disableCloseOnSelect
the same behavior as Default but the step 2 it wont hide the combo box

showOptionsOnFocus
the same behavior as Default but the step 3 it only show all the options if there's no option selected

A good reference of what we're following on this PR:
https://mui.com/material-ui/react-autocomplete/#combo-box

References #2282

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Copy link

netlify bot commented Apr 26, 2024

Deploy Preview for moduswebcomponents ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit bed1d8a
🔍 Latest deploy log https://app.netlify.com/sites/moduswebcomponents/deploys/66463774120327000880cda9
😎 Deploy Preview https://deploy-preview-2484--moduswebcomponents.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 28 (🟢 up 3 from production)
Accessibility: 98 (no change from production)
Best Practices: 92 (no change from production)
SEO: 92 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@rjavier-trimbler rjavier-trimbler marked this pull request as ready for review May 1, 2024 16:13
@@ -195,7 +209,14 @@ export class ModusAutocomplete {
};

handleInputBlur = () => {
this.hasFocus = !this.disableCloseOnSelect;
if (!this.hasOptionMatched(this.value)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nesting if statements makes the code harder to read. Can you switch this to something like

if (this.hasOptionsMatched(this.value) || 
    this.selectedOption === '' || 
    this.value === '' || 
    this.hasFocus) {
  return;
}

this.value = this.selectedOption;
this.disableFiltering = true;

This makes it easier to tell what conditions cause it to not continue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

@@ -321,8 +343,11 @@ export class ModusAutocomplete {
search = search || '';
const isSearchEmpty = search.length === 0;

if ((isSearchEmpty && !this.showOptionsOnFocus) || (this.disableFiltering && this.disableCloseOnSelect)) {
if (isSearchEmpty) this.selectedOption = '';
Copy link
Contributor

Choose a reason for hiding this comment

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

one liners generally make code harder to read as it puts the action at a variable distance from the left depending on the condition. Update to:

if (isSearchEmpty) {
  this.selectionOption = '';
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

Copy link
Contributor

@cjwinsor cjwinsor left a comment

Choose a reason for hiding this comment

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

I haven't functionally validated this works. Has this been QA'd by your team?

@J-Ruiz1
Copy link

J-Ruiz1 commented May 16, 2024

@cjwinsor this has already been tested for the following scenarios in this user story:

Scenario 1: Validate that the Process Filter shows all available options when focused

Scenario 2: Validate that the Process Filter is able to filter based on search criteria via adding characters

Scenario 3: Validate that the Process Filter is able to filter based on search criteria via removing characters. An empty again Process filter must show all available options

Scenario 4: Validate that the Process Filter clears all characters and show the placeholder text "search processes" when characters are entered but the filter loses focus without a selection

Scenario 5: Validate that the Process Filter shows all available options when refocusing on the filter after an option was previously selected. The already selected item item shows with a checkmark on the right and is the second one from the bottom of the list (when able)

Scenario 6: Validate that when there are no matches when searching with no previous selection the dropdown will show a “not found” message.

Scenario 7: Validate that when there are no matches when searching with a previous selection the dropdown will show a “not found” message. Focusing out will show the previously selected option

Scenario 8: Validate that clearing the autocomplete removes the highlighted selection.

Copy link
Contributor

@cjwinsor cjwinsor left a comment

Choose a reason for hiding this comment

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

Things I noticed:

A flicker was introduced when picking an item (in my case, I didn't set any props, only set options) that wasn't there before. The text goes blank, then shows new value.

It now behaves as if show-options-on-focus is always enabled. It should not show the items on focus until that prop is set to true. There seems to be a previous bug where once there is a selection it opens the autocomplete on focus even when show-options-on-focus is not set to true, that isn't correct either.

If I have a value selected, and while focused on the textbox, click the down arrow, it erases the text and the selection. The down arrow should not remove the value/selection.

const optionList = this.el.shadowRoot.querySelector(`.options-container`) as HTMLUListElement;

const selectedOption = optionList.querySelector('li.selected') as HTMLElement;
if (selectedOption) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you have used selectedOption.scrollIntoView() to use the native browser handling?

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.

None yet

4 participants