-
Notifications
You must be signed in to change notification settings - Fork 80
Keyboar selection in list using arrow keys #152
Keyboar selection in list using arrow keys #152
Conversation
Thanks @turboMaCk, I'm definitely interested in getting this merged 🙂 This feature was also requested a while ago in a comment somewhere else. I'll be reviewing the code a bit later today or tomorrow. |
I've tried it out, my immediate thoughts: I'm concerned that you are basically re-implementing the selection feature, you are writing lots of code to do this, you are coloring the selection, keeping track of highlighted item, etc... First of all, all this is already implemented by the browser itself (what you see when pressing I have two ideas, not sure if any of them is possible, but could potentially simplify this PR a lot.
Both ideas will allow you to reuse most of what is already implemented by browsers, and arrows will not conflict with What do you think about these? |
Had a chance to investigate a bit, here are the findings:
|
Hello, @maximbaz 👋 Thanks for super fast response. I was away until now so sorry for not keeping up with you in this. Frankly I even didn't notice that I can use native focus with this extension since I dind't know items are buttons but it makes quite some sense. There are some advantages for using custom highlighting over native focus. For instance I like to be able to type and using sellection at the same time but probably it's not as usefull in this case sice search is performed on form submit not input (which makes sense from security perspective). The fact that this doesn't play well with native focus is game changer indeed though and I agree it we need to fix that. In this implementation key handler is on input so on I think it's pretty clear that you would prefer arrows to behave as much like native focus as possible so I'll reimplement it that way. One thing I'm not so much sure about is how will usage of I'll keep you up to date. Let me know if you have so additional points. |
Yeah I'd prefer to use the native focus as much as possible. Let me know if you get into issues and I'll try to help as much as I can, but I tested the things above (like By the way, I was toying recently with the idea to perform search on keydown instead of form submit, and even if we ignore security perspective for a minute, the current UI is simply not fit for this, everything is rather ugly, the box is jumping and changing width and height every time, and flashing between doing the searches... in the end, it's no good, I think there are too many reasons for now to stay with the "form submit" event 🙂 |
chrome/script.browserify.js
Outdated
@@ -54,6 +54,7 @@ function view() { | |||
[ | |||
m("input", { | |||
type: "text", | |||
id: "search-field", |
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.
I'm using id for selecting and detecting focus on input
. It seemed to be better than reading other attributes (like tagName) to me.
chrome/script.browserify.js
Outdated
@@ -69,7 +70,7 @@ function view() { | |||
]), | |||
|
|||
// results | |||
m("div.results", results) | |||
m("div.results", { onkeydown: keyHandler }, results) |
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.
As you can see handler is assigned to a container of results and container of input. I did it because I didn't want to change structure without asking you first. Alternatively, we can add a new extra container to render or use native API to register the handler.
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.
I don't mind wrapping both containers in a some kind of parent container, and assigning the onkeydown to it. But if for whatever reason it gets complicated, the current solution is also fine.
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 comment
The 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
I'll wait for your review before porting/integrating this to FF version. |
I like it much better now @turboMaCk! And by the way, it works very well on both my Chromium and Firefox 😉 Just to make sure, you know that we have the same code for both browsers, right? After you run Regarding to your suggestion to wrap everything in a parent container, seems like a valid idea to me. Try it out, and let me know when you are done implementing and testing, so that I can do one final test and merge everything 🙂 |
Gotcha. There is one tiny issue in FireFox though. Native focus circles between
2nd issue should be possible to fix by reversing logic in this check to not The first issue would require overloading |
// results | ||
m("div.results", results) | ||
]; | ||
return m('div.container', { onkeydown: keyHandler }, [ |
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.
|
It seems that extra thing firefox focus is not |
Then let's not introduce any such hacks for now. I'll test it later today, and merge if everything is okay. Thanks for this PR! |
Merged in c3a6279. What I did extra is I removed a parent ".container", because it looked like that and I don't see a need for the outermost container: Thanks once again! My testing on Firefox revealed the following troubling issue: Firefox does not respect the Recorded as #155. |
@maximbaz I've spotted that issue as well myself just didn't want to mix it with this one. Great you've made an issue - I wanted to create one myself once this is closed. I'll subscribe to that issue and in case I'll have some time before anybody else will pick it up I'll do so myself. Thanks for all your help with this PR - very appreciated. |
This is still work in progress (missing FF version).
I've really missed arrow keys selection so I've coded it myself. I'm opening this PR early in case you're interested to review and discuss it. If you're not interested in this feature, feel free to close this PR - I can always use my own version of extension anyway. In case you're interested I'm going to clean code a bit implement the same feature for firefox as well as include changes from code review.