Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

Auto-scroll the search result list to keep the selection in view #35

Merged
merged 1 commit into from
Jun 11, 2018

Conversation

nusjzx
Copy link

@nusjzx nusjzx commented Jun 6, 2018

What is the purpose of this pull request? (put "X" next to an item, remove the rest)

• [ ] Documentation update
• [ ] Bug fix
• [ ] New feature
• [X] Enhancement to an existing feature
• [ ] Other, please explain:

Resolves MarkBind/markbind#258

What is the rationale for this request?
Currently, when the user navigates down the result list using the down arrow, the selection goes out of the view port of the list. The dropdown should auto-scroll to the entry

What changes did you make? (Give an overview)
update up and down event handler to scroll to current item

Testing instructions:

  1. deployed website: https://nusjzx.github.io/website-base/

@yamgent
Copy link
Member

yamgent commented Jun 7, 2018

The downwards scroll looks very weird, especially if the next selection doesn't seem like it will go off the screen. Perhaps try calculating the position of the next selection before scrolling?

Copy link
Member

@yamgent yamgent left a comment

Choose a reason for hiding this comment

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

Excellent work, this works like a charm now. 👍 Some minor nits:

this.scrollWindow();
}
},
scrollWindow() {
Copy link
Member

Choose a reason for hiding this comment

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

scrollListView() might be a bit more accurate. (I think the term "window" might be more suitable for the entire browser's window, rather than the component's window).

},
scrollWindow() {
const { dropdown } = this.$els;
const curEntry = dropdown.children[this.current];
Copy link
Member

Choose a reason for hiding this comment

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

Try to spell out the abbreviation. Should be currentEntry.

const curEntry = dropdown.children[this.current];
const upperBound = dropdown.scrollTop;
const lowerBound = upperBound + dropdown.clientHeight;
const curBottom = curEntry.offsetTop + curEntry.offsetHeight;
Copy link
Member

Choose a reason for hiding this comment

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

I think you should just name it literally to what it should have been provided by them: currentEntryOffsetBottom. Makes it more consistent.

},
scrollListView() {
const { dropdown } = this.$els;
const curEntry = dropdown.children[this.current];
Copy link
Member

Choose a reason for hiding this comment

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

Try to spell out the abbreviation. Should be currentEntry.

Reminder to fix this one. :P

if (curEntry.offsetTop < upperBound) {
dropdown.scrollTop = curEntry.offsetTop;
} else if (currentEntryOffsetBottom > lowerBound) {
dropdown.scrollTop = (upperBound + currentEntryOffsetBottom) - lowerBound;
Copy link
Member

Choose a reason for hiding this comment

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

This can be simplified to just dropdown.scrollTop = currentEntryOffsetBottom - dropdown.clientHeight;

@acjh
Copy link

acjh commented Jun 7, 2018

@nusjzx Can you update the deployed website?

@nusjzx
Copy link
Author

nusjzx commented Jun 8, 2018

done @

@nusjzx nusjzx closed this Jun 8, 2018
@nusjzx nusjzx reopened this Jun 8, 2018
@acjh
Copy link

acjh commented Jun 9, 2018

@nusjzx It seems that the deployed website was updated to another PR.
But I've tested it locally and as @yamgent said, works like a charm now :)

Can you post an updated gif for completeness sake?

@acjh
Copy link

acjh commented Jun 9, 2018

Please squash the commits.

@nusjzx
Copy link
Author

nusjzx commented Jun 11, 2018

1

@nusjzx nusjzx force-pushed the 258-search-dropdown-autoscroll branch from fffcade to 48f8c18 Compare June 11, 2018 03:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants