Commit b244317a authored by Phil Hughes's avatar Phil Hughes

Scrolls the dropdown content down

parent 0e290a84
...@@ -96,7 +96,7 @@ class GitLabDropdown ...@@ -96,7 +96,7 @@ class GitLabDropdown
LOADING_CLASS = "is-loading" LOADING_CLASS = "is-loading"
PAGE_TWO_CLASS = "is-page-two" PAGE_TWO_CLASS = "is-page-two"
ACTIVE_CLASS = "is-active" ACTIVE_CLASS = "is-active"
CURRENT_INDEX = 0 CURRENT_INDEX = -1
FILTER_INPUT = '.dropdown-input .dropdown-input-field' FILTER_INPUT = '.dropdown-input .dropdown-input-field'
...@@ -410,7 +410,7 @@ class GitLabDropdown ...@@ -410,7 +410,7 @@ class GitLabDropdown
if currentKeyCode is 40 if currentKeyCode is 40
# Move down # Move down
CURRENT_INDEX += 1 if CURRENT_INDEX < $listItems.length CURRENT_INDEX += 1 if CURRENT_INDEX < ($listItems.length - 1)
else if currentKeyCode is 38 else if currentKeyCode is 38
# Move up # Move up
CURRENT_INDEX -= 1 if CURRENT_INDEX > 0 CURRENT_INDEX -= 1 if CURRENT_INDEX > 0
...@@ -434,6 +434,18 @@ class GitLabDropdown ...@@ -434,6 +434,18 @@ class GitLabDropdown
$listItem = $(selector, @dropdown) $listItem = $(selector, @dropdown)
$listItem.addClass "is-focused" $listItem.addClass "is-focused"
# Dropdown content scroll area
$dropdownContent = $listItem.closest('.dropdown-content')
dropdownContentBottom = $dropdownContent.prop('offsetTop') + $dropdownContent.prop('offsetHeight')
# Get the offset bottom of the list item
listItemBottom = $listItem.prop('offsetTop') + $listItem.prop('offsetHeight')
console.log listItemBottom, dropdownContentBottom
if listItemBottom > dropdownContentBottom
# Scroll the dropdown content down
$dropdownContent.scrollTop(listItemBottom - dropdownContentBottom)
$.fn.glDropdown = (opts) -> $.fn.glDropdown = (opts) ->
return @.each -> return @.each ->
if (!$.data @, 'glDropdown') if (!$.data @, 'glDropdown')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment