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

Keep selected item visible in results list. #37

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

richardkmichael
Copy link
Contributor

@richardkmichael richardkmichael commented Apr 3, 2018

@charliekassel I talked with @alanbhamilton about PR #20 (which closes issue #19). I've taken the PR, and re-worked it. I left the commits unsquashed, if you want to review the evolution. Prior to merge, I'd rebase and squash them.

There are a few considerations:

  • Avoids usage of ref, only because the component doesn't use them anywhere else. Instead, $el.querySelector() is used once.

  • selectedElement could be a computed property, but it's might not be worth burdening Vue with re-computation. It is used on every up() and down() call, but only in those functions, and Vue may re-compute it in other circumstances, even when not necessary (any access to selectedIndex might cause re-computation, as it's the dependency).

  • Calculations use the .offset* properties. These do not consider applied transformations (e.g., scaling). However, I suspect these will be a rare and suggest waiting for a "bug" report before re-working it with .getClientBoundingRect() (which provides sizes after transformations have been applied; that is, rendered sizes). What are your thoughts? After discussion, I'll remove the code comment prior to merge.

  • There is an uncommon possibility handled by the code: if the <ul> list of options is shorter than a single choice (that is, the visible scroll area doesn't fit a single choice element). In such a situation, the user will see only a partial choice. This would be a very strange UI, but it could happen (presumably by accident) on mobile. I've avoid trying to sync in this case, becuse there is nothing to do -- just allow the selection to move. Although, it won't wrap, so it is somewhat broken. I wonder if it's worth handling this at all. I'd prefer to remove the special handing, and wait for a bug report.

alanbhamilton and others added 5 commits March 29, 2018 18:38
Use `element.scrollTop` to manipulate the scroll position of the results ul.
Change several variable names to make clearer the values which are
JavaScript data and those which are DOM elements.

Use the `n-child()` selector to find the selected element directly,
after the `selectedIndex` has been changed, instead of using the first
result of find-by-class.

`isVisibleInside()` used `offset` to "look ahead or behind", from the
unchanged selected element, to find the "will be selected after
movement" element and then determine if it will be contained in the
parent.  However, as a result of working with the selected element
directly, `offset` can be removed: `isVisibleInside()` has the element
required for consideration.
Move `selectedElement` to computed property and add more specific
"overflow" helper which uses it.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 27

  • 19 of 25 (76.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-4.2%) to 92.017%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/components/Autocomplete.vue 19 25 76.0%
Totals Coverage Status
Change from base Build 26: -4.2%
Covered Lines: 163
Relevant Lines: 172

💛 - Coveralls

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.

3 participants