-
Notifications
You must be signed in to change notification settings - Fork 80
WIP: Bug/ff input auto select #158
Changes from all commits
5bdd62d
014aeab
5bd17ac
710a8d0
ee94ee4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ var searching = false; | |
var logins = null; | ||
var domain, urlDuringSearch; | ||
|
||
m.mount(document.getElementById("mount"), { view: view }); | ||
m.mount(document.getElementById("mount"), { view: view, oncreate: oncreate }); | ||
|
||
chrome.browserAction.setIcon({ path: "icon-lock.svg" }); | ||
chrome.tabs.onActivated.addListener(init); | ||
|
@@ -166,15 +166,29 @@ function keyHandler(e) { | |
} | ||
|
||
function switchFocus(firstSelector, nextNodeAttr) { | ||
var inputId = "search-field"; | ||
var newActive = | ||
document.activeElement.id === inputId | ||
var searchField = document.getElementById('search-field'); | ||
var newActive = document.activeElement === searchField | ||
? document.querySelector(firstSelector) | ||
: document.activeElement[nextNodeAttr]; | ||
|
||
if (newActive) { | ||
newActive.focus(); | ||
} else { | ||
document.getElementById(inputId).focus(); | ||
searchField.focus(); | ||
} | ||
} | ||
|
||
// The oncreate(vnode) hook is called after a DOM element is created and attached to the document. | ||
// see https://mithril.js.org/lifecycle-methods.html#oncreate for mor informations | ||
function oncreate() { | ||
var searchField = document.getElementById('search-field'); | ||
|
||
// FireFox probably prevents `focus()` calls for some time | ||
// after extension is rendered. | ||
searchField.focus(); | ||
window.setTimeout(function() { | ||
if (searchField) { | ||
searchField.focus(); | ||
} | ||
}, 100); | ||
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. there is that ugly hack with timeout:( EDIT: I've tried to set it to 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. Try to wrap it in 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. I'd also move the call to 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. I've just found some time to try it and it doesn't work which makes sense to me. if I also tried this sort of "recursive" approach: function oncreate() {
var searchField = document.getElementById('search-field');
searchField.focus();
if (document.activeElement !== searchField) {
window.requestAnimationFrame(oncreate);
}
} which doesn't work either. One thing I'm still not sure about is what makes timeout Next thing I did was to remove whole To me, it seems that same thing that prevents us to simply use Another solution that came to my mind was to rewrite that function so it will perform check every 10ms and if it's not successful it will set itself to run in next 10ms until it is. Anyway, I did quick and it seems that 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. Hey, thanks for doing the experiments! Then let's keep it simple and not over-engineer stuff, it's a bit hacky - yes, but it works and it's quite simple to understand, especially given that you left an explanatory comment. I'll merge now. Thanks 👍 |
||
} |
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.
This is just a tiny change I forgot to push to the previous PR it seems. I can remove it from this one if you want.
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.
No need, keep it here 👍