Select the first list item after changing the list filter

This commit is contained in:
Nathan Sobo
2012-10-03 21:04:44 -10:00
parent a4c25f1cb7
commit 1e9b40a6ea
2 changed files with 4 additions and 1 deletions

View File

@@ -30,11 +30,12 @@ fdescribe "SelectList", ->
expect(list.find('li:eq(0)')).toHaveClass 'A'
describe "when the text of the mini editor changes", ->
it "filters the elements in the list based on the scoreElement function", ->
it "filters the elements in the list based on the scoreElement function and selects the first item", ->
miniEditor.insertText('la')
expect(list.find('li').length).toBe 2
expect(list.find('li:contains(Alpha)')).toExist()
expect(list.find('li:contains(Delta)')).toExist()
expect(list.find('li:first')).toHaveClass 'selected'
describe "when move-up / move-down are triggered on the miniEditor", ->
it "selects the previous / next item in the list, or wraps around to the other side", ->

View File

@@ -52,6 +52,8 @@ class SelectList extends View
item.data('select-list-element', element)
@list.append(item)
@selectItem(@list.find('li:first'))
selectPreviousItem: ->
item = @getSelectedItem().prev()
item = @list.find('li:last') unless item.length