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 autocomplete not having filter blank after selecting an item, and fix #540

Merged
merged 15 commits into from
Jul 19, 2018

Conversation

EWhite613
Copy link
Contributor

@EWhite613 EWhite613 commented Jul 18, 2018

Overview

Does this PR close an existing issue?

No PR should be opened without opening an issue first. Any change needs to be discussed before proceeding.

Summary

Provide a general summary of the issue addressed in the title above

Issue Number(s)

Which issue(s) does this PR address?

Put Closes #XXXX below to auto-close the issue that this PR addresses:

  • Closes #

Screenshots or recordings

Please provide screenshots or recordings if this PR is modifying the visual UI or UX.

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • I have evaluated if the README.md documentation needs to be updated
  • I have evaluated if the /tests/dummy/ app needs to be modified
  • I have evaluated if DocBlock headers needed to be added or updated
  • I have verified that lint and tests pass locally with my changes
  • If a fork of a dependent package had to be made to address the issue this PR closes:
    • I noted in the fork's README.md the reason the fork was created
    • I have opened an upstream issue detailing what was deficient about the dependency
    • I have opened an upstream PR addressing this deficiency
    • I have opened an issue in this repository to track this PR and schedule the removal of the usage of the fork

Semver

This project uses semver, please check the scope of this PR:

  • #none#
  • #patch#
  • #minor#
  • #major#

Examples:

  • NONE
    • README.md changes
    • test additions
    • changes to files that are not used by a consuming application (.travis.yml, .gitignore, etc)
  • PATCH
    • backwards-compatible bug fix
      • nothing about how to use the code has changed
      • nothing about the outcome of the code has changed (though it likely corrected it)
    • changes to demo app (/tests/dummy/)
  • MINOR
    • adding functionality in a backwards-compatible manner
      • nothing about how used to use the code has changed but using it in a new way will do new things
      • nothing about the outcome of the code has changed without having to first use it in a new way
      • addition of new CSS selectors
      • addition of new ember-hook selectors
  • MAJOR
    • incompatible API change
      • using the code how used to will cease working
      • using the code how used to will have a different outcome
      • any changes to CSS selector names
      • any removal of CSS selectors
      • any changes to ember-hook selectors
      • possibly changes to test helpers (depends on the changes made)
    • any changes to the dependencies entry in the package.json file

CHANGELOG

  • Fix autocomplete not being able to backspace to blank filter when have already selected

@EWhite613 EWhite613 requested a review from sophypal July 18, 2018 19:45
@EWhite613 EWhite613 requested a review from a team as a code owner July 18, 2018 19:45
@EWhite613 EWhite613 requested a review from quincyle July 18, 2018 19:45
}
},

// == Observers ====================================================

observeSelectedItemLavelChange: observer('value', 'options.[]', '_isTyping', 'filter', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Lavel?

const selectedItem = this._findSelectedItemGivenValue(value, options)
if (!isEmpty(selectedItem)) {
const label = get(selectedItem, 'label')
if (!isEmpty(label) && isEmpty(filter) && !isTyping) this.set('filter', label)
Copy link
Contributor

Choose a reason for hiding this comment

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

So I'm having a tough time understanding what the fix is. Do you mind posting screenshots/vids of the before and after. From what I can understand from these changes, it looks like the filter was empty previously and you're setting it the the selected item label when user is not typing? Is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well the original problem when you have a selectedItem and backspace to an empty filter it would.
2018-07-19 11_13_08

So if I can keep track of typing I know that I shouldn't set the filter when the user is just backspacing all the way
2018-07-19 11_01_52

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. Originally I was thinking that if a user started typing, it meant user intention was to set the value (even with backspace to clear) so it shouldn't need to set the filter back to the original. But autocomplete isn't like Google's auto suggest. A value is only made with a selection and filtering the list shouldn't clear the value.

This was easier to handle in select because there was clear separation between the filtering input and the value's input element. In select typing anything would update the filter to whatever the user typed, regardless if it was empty. If the user didn't like the choices, he could close the dropdown and get back his original value.

Would it be better to keep track of the dropdown states instead of the typing? If the dropdown is open, don't override the filter ever; just keep it at whatever the user typed. Hmm. that would mean you'd also have to fix the automatic closing of the dropdown when they backspace to clear. Man, this component is getting really complex.

Up to you I guess. If I had a hard time understanding this scenario, others will and it'll be hard to maintain. Perhaps throw in some comments explaining this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem, in this case, is I don't have knowledge on whether drop-down is open or not. That's in frost-autocomplete, and since we need to use onInput for querying/etc we can't really have frost-autocomplete control filter for us (because frost-autocomplete assumes if you use onInput you will control the filter, and shouldn't set it.

I think I made it much more readable now by removing the observer logic, I'll add some comments on _isTyping to make it easier to read

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like drop-down state is also closed when you have an empty filter. So I'd run into the same issue

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, removing the observer business definitely makes this more readable.


this.setProperties({
filter: filterValue,
_isTyping: focused
Copy link
Contributor

Choose a reason for hiding this comment

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

Interested to know why it's necessary to keep typing state. Is there no alternative?

Copy link
Contributor

Choose a reason for hiding this comment

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

I probably just need to get a better understanding of the bug you're fixing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya I'll add some screenshots/gifs tomorrow to better explain the problem

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well the original problem when you have a selectedItem and backspace to an empty filter it would.
2018-07-19 11_13_08

So if I can keep track of typing I know that I shouldn't set the filter when the user is just backspacing all the way
2018-07-19 11_01_52

@EWhite613 EWhite613 requested a review from a team as a code owner July 18, 2018 21:19
sophypal
sophypal previously approved these changes Jul 19, 2018
@EWhite613 EWhite613 merged commit 3460b52 into ciena-frost:master Jul 19, 2018
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