Skip to content

Conversation

@imaustink
Copy link
Contributor

@imaustink imaustink commented Jun 16, 2017

search-result-stuck

@imaustink imaustink requested a review from chasenlehara June 16, 2017 22:10
@chasenlehara
Copy link
Member

Going down is looking good!

I think we should make it behave the same way going up: when the user hits the up arrow when the last item is selected, what’s visible in the scroll area should stay the same while the selection moves up. See the gif below for the unwanted behavior:
going up

@chasenlehara chasenlehara changed the title Active search result sticks to bottom of page. Closes #276 Active search result sticks to bottom of page Jun 21, 2017
@imaustink
Copy link
Contributor Author

@chasenlehara this PR has been updated to address your last comment.
(gray is too hard to see so I made it red for the gif)
search-result-stuck

@imaustink imaustink changed the title Active search result sticks to bottom of page Active search result sticks to bottom and top of page Jun 22, 2017
static/search.js Outdated
if(isMovingDown){
var resultsContainerHeight = this.$resultsContainer.height();

var isBellow = activeResultPosTop > resultsContainerHeight;
Copy link

Choose a reason for hiding this comment

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

isBelow?

@imaustink imaustink requested review from andrejewski, bgando and chasenlehara and removed request for chasenlehara June 22, 2017 22:59
Copy link

@bgando bgando left a comment

Choose a reason for hiding this comment

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

Overall looks good. Check out my comments for a couple small things. A medium-sized thing to consider is that this method has 2 jobs: toggling the class and adjusting the scroll. There isn't a ton of code so maybe it doesn't matter that much, but personally I'd break them apart.

static/search.js Outdated
// sets property and adds class to active result
activateResult: function($result){
// Get position top of last active element
var lastResultPosTop = parseInt(this.$activeResult && this.$activeResult.position().top || 0);
Copy link

Choose a reason for hiding this comment

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

props on IDing this bug ahead of time!

Copy link
Member

Choose a reason for hiding this comment

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

Make sure to always pass 10 as the second argument to parseInt (you can search for reasons why).

static/search.js Outdated
var isAbove = activeResultPosTop < 0;

if(isMovingDown){
if(isBellow){
Copy link

Choose a reason for hiding this comment

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

isMovingDown && isBelow could be on one line

static/search.js Outdated
this.resetScrollToBottom(activeResultPosTop, resultsContainerHeight);
}
}else{
if(isAbove){
Copy link

Choose a reason for hiding this comment

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

could use an else if(isAbove)

static/search.js Outdated

if(isMovingDown){
if(isBellow){
this.resetScrollToBottom(activeResultPosTop, resultsContainerHeight);
Copy link

Choose a reason for hiding this comment

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

Much more readable! Awesome 💃

var resultsContainerHeight = this.$resultsContainer.height();

this.$resultsContainer.scrollTop(this.$activeResult.position().top - activeResultOffset);
var isMovingDown = lastResultPosTop < this.$activeResult.position().top;
Copy link

Choose a reason for hiding this comment

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

Add a comment here to clarify that you are talking about the arrow key direction

static/search.js Outdated

this.$resultsContainer.scrollTop(this.$activeResult.position().top - activeResultOffset);
var isMovingDown = lastResultPosTop < this.$activeResult.position().top;
var isBellow = activeResultPosTop > resultsContainerHeight;
Copy link

Choose a reason for hiding this comment

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

isBelow

@imaustink
Copy link
Contributor Author

@bgando I agree with your reasoning behind splitting up activateResult, the only problem is that part of the math for scrolling involves the position top of the previous active element.

@imaustink
Copy link
Contributor Author

@chasenlehara do you want it to stop when it reached the bottom or top? Currently, it restarts from the other end.

@chasenlehara
Copy link
Member

I personally don’t like that it goes back to the top when you reach the bottom, but I’m willing to see how people react to it in practice.

Copy link
Member

@chasenlehara chasenlehara left a comment

Choose a reason for hiding this comment

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

Looks great! I added a comment for one minor thing.

static/search.js Outdated
// sets property and adds class to active result
activateResult: function($result){
// Get position top of last active element
var lastResultPosTop = parseInt(this.$activeResult && this.$activeResult.position().top || 0);
Copy link
Member

Choose a reason for hiding this comment

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

Make sure to always pass 10 as the second argument to parseInt (you can search for reasons why).

@imaustink imaustink merged commit 1fc7a6e into master Jun 26, 2017
@imaustink imaustink deleted the 276-active-result-sticks-to-bottom branch June 26, 2017 21:16
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.

4 participants