This repository has been archived by the owner on May 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
Keyboar selection in list using arrow keys #152
Closed
turboMaCk
wants to merge
5
commits into
browserpass:master
from
turboMaCk:feature/keyboard_selecting
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
330c599
keyboar selection in chrome
turboMaCk 1e364fd
reimplement to use DOM native focus
turboMaCk 4471e27
use input id from variable in fallback
turboMaCk 7d6f4be
wrap into view container element
turboMaCk 795ee62
retrun container rather then container in array.
turboMaCk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,34 +43,35 @@ function view() { | |
} | ||
} | ||
|
||
return [ | ||
// search form | ||
m("div.search", [ | ||
m( | ||
"form", | ||
{ | ||
onsubmit: submitSearchForm | ||
}, | ||
[ | ||
m("input", { | ||
type: "text", | ||
name: "s", | ||
placeholder: "Search password..", | ||
autocomplete: "off", | ||
autofocus: "on" | ||
}), | ||
m("input", { | ||
type: "submit", | ||
value: "Search", | ||
style: "display: none;" | ||
}) | ||
] | ||
) | ||
]), | ||
|
||
// results | ||
m("div.results", results) | ||
]; | ||
return m('div.container', { onkeydown: keyHandler }, [ | ||
// search form | ||
m("div.search", [ | ||
m( | ||
"form", | ||
{ | ||
onsubmit: submitSearchForm | ||
}, | ||
[ | ||
m("input", { | ||
type: "text", | ||
id: "search-field", | ||
name: "s", | ||
placeholder: "Search password..", | ||
autocomplete: "off", | ||
autofocus: "on" | ||
}), | ||
m("input", { | ||
type: "submit", | ||
value: "Search", | ||
style: "display: none;" | ||
}) | ||
] | ||
) | ||
]), | ||
|
||
// results | ||
m("div.results", results) | ||
]); | ||
} | ||
|
||
function submitSearchForm(e) { | ||
|
@@ -149,3 +150,30 @@ function getLoginData() { | |
} | ||
); | ||
} | ||
|
||
// This function uses regular DOM | ||
// therefore there is no need for redraw calls | ||
function keyHandler(e) { | ||
switch (e.key) { | ||
case 'ArrowUp': | ||
switchFocus('button.login:last-child', 'previousElementSibling'); | ||
break; | ||
|
||
case 'ArrowDown': | ||
switchFocus('button.login:first-child', 'nextElementSibling'); | ||
break; | ||
} | ||
} | ||
|
||
function switchFocus(firstSelector, nextNodeAttr) { | ||
var inputId = 'search-field'; | ||
var newActive = document.activeElement.id === inputId ? | ||
document.querySelector(firstSelector) : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is using querySelector. Compatibility should be probably fine due to browser selection. https://www.w3schools.com/jsref/met_document_queryselector.asp |
||
document.activeElement[nextNodeAttr]; | ||
|
||
if (newActive) { | ||
newActive.focus(); | ||
} else { | ||
document.getElementById(inputId).focus(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stupid class name but is fine for the view as small as this.