Skip to content

Commit

Permalink
document.activeElement の親要素に box が含まれていた場合のみ、上下キーを処理するようにした (fix #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed Oct 24, 2017
1 parent 7f9fc3f commit 19a7ea7
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/js/crsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,6 @@ export default class CRSearch {

let box = $(sel)
box.attr('data-crsearch-id', id)
Mousetrap.bind('up', e => {
e.preventDefault()
this.selectChange(true, box)
})
Mousetrap.bind('down', e => {
e.preventDefault()
this.selectChange(false, box)
})

this.last_input[id] = ''

Expand All @@ -304,6 +296,23 @@ export default class CRSearch {
input.attr('placeholder', CRSearch.INPUT_PLACEHOLDER)
input.appendTo(control)

Mousetrap.bind('up', e => {
console.log(document.activeElement)
console.log(input)
console.log(input[0])
console.log($(document.activeElement).closest('*[data-crsearch-id="' + id + '"]').length != 0)
if ($(document.activeElement).closest('*[data-crsearch-id="' + id + '"]').length != 0) {
e.preventDefault()
this.selectChange(true, box)
}
})
Mousetrap.bind('down', e => {
if ($(document.activeElement).closest('*[data-crsearch-id="' + id + '"]').length != 0) {
e.preventDefault()
this.selectChange(false, box)
}
})

input.on('click', function(e) {
this.show_result_wrapper_for(e.target)
return this.select_default_input()
Expand Down

0 comments on commit 19a7ea7

Please sign in to comment.