Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

fix(uiSelectCtrl): scroll to dropdown position on dropdown open #2034

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

Conversation

kidroca
Copy link

@kidroca kidroca commented Jul 21, 2017

Related to issue #976 and pull request #1742

As suggested in the above references - a couple of helper function were extracted
Updated the animation handling to use $q promise and resolve when the animation is unsubscribed
Then the caller triggers the actual focusing/scrolling logic so it stays out of the animation handler context
If it's not desired to use promise there the last commit can just be reverted/removed

Added tests about the scrolling functionality, the one that handles the animation callback is a bit tricky and can be updated, I haven't used $animate and written tests for it before

Had to include the select.css to karma.config in order to have proper sizes for the
elements that are tested otherwise container.scrollTop is always 0
This did not alter execution time or results for other tests

@aaronroberson
Copy link
Contributor

Can you update your branch to resolve conflicts?

@kidroca
Copy link
Author

kidroca commented Dec 6, 2017

I'll give it a go tomorrow

@aaronroberson
Copy link
Contributor

Right on, thanks!

…ogic to private function

Extracted:
 - method: _displayDropdown(initSearchValue, avoidReset) -> handle opening
 - method: _canAnimate(element)
 - method: _animateDropdown(searchInput, initSearchValue, container)
When ui-select is configured with `resetSearchInput: false`
`ctrl.activeIndex` is not calculated when `ctrl.activate()` is invoked

Opening an ui-select control with preselected model doesn't trigger
active index update/reset and so the container is scroll the the
element with 0 `ctrl.activeIndex` initial value (check `_ensureHighlightVisible()`)
Extracted repeating logic that focuses the search input after
the dropdown is clicked
Performed with $timeout so any digest or animation logic is waited for
…unction with $animate

The function `_ensureHighlightVisible()` that scrolls to the
active (highlighted) element is never invoked at the end of the
animation, when animation is used

The logic that handles non animation opening is a bit different in that
it scrolls to the highlighted element

Updated the animation handler to perform similarly
This sets proper element size during testing
And doesn't break the rest of the test

Tests for scroll position depend on these styles
…urn promise

The promise is resolved when the animation is switched off (unsubscribed)
This extracts the additional responsibility to call focus/scroll the
active element at the end of the animation
@kidroca kidroca force-pushed the fix-scroll-to-selected-position branch from 4191236 to e6ba734 Compare December 7, 2017 15:30
@kidroca
Copy link
Author

kidroca commented Dec 7, 2017

Ready

This PR changes uiSelectCtrl's ctrl.activate method (mostly), by extracting logic to subroutines, which could result in conflicts with some of the other pull requests that change the same method. Conflicts should be easy to fix though, because I only extracted methods and didn't change logic, besides the one needed for the fix

@aaronroberson
Copy link
Contributor

Whoa! I no longer have permissions to merge. @Jefiozie can you review/merge this PR?

@aaronroberson
Copy link
Contributor

aaronroberson commented Dec 7, 2017

To release a new version, please follow these steps:

  1. Bump the version
    Run gulp recommendedBump to increment the version in package.json and elsewhere.

  2. Update the changelog
    Run gulp changelog to update the changelog based on the conventional commit messages. You may want to visually inspect the changelog after to ensure that it was generated as expected.

  3. Add and commit your changes
    The gulp commands are not working as-is for these operations. Manually run git add . && git commit -am "chore(release): bump package version and update changelog".

  4. Tag the commit with the package version
    Either run gulp tag or manually view the new version in package.json and run git tag vX.X.X where X.X.X is the version number.

  5. Push the commits and tag to remote
    Either run gulp push or manually run git push && git push origin master --tags if the gulp command doesn't work.

  6. Publish to npm
    I don't recall if Travis CI is working in regard to auto-publishing new versions. If upon merge and push, Travis doesn't publish a new version to npm, you can publish it manually. To do so, run npm publish after logging into npm via npm login and entering your npm credentials.

All of this is supposed to be encapsulated in a single gulp command gulp bump. With a couple minor updates, this can be accomplished.

@kickergold
Copy link

Is this still merged? Currently this doesn't work anymore, and it doesn't scroll to the selected option.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants