-
Notifications
You must be signed in to change notification settings - Fork 1k
Add controller for search focus for slash keypress #10395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
While having the search key autofocus is forbidden, having a keypress focus the search field is a desirable feature. Add a new Stumulus Controller that listens to the `/` keypress and focuses the input on the search field. Note: Currently applies only to the home page. Refs: pypi#6099 Signed-off-by: Mike Fiedler <[email protected]>
Thanks! I think if we add a check that the cursor is not currently in an input field, we could add this to the base template, so this is usable everywhere the search box is currently present. |
Happy to look at that change as well - but then I'm not sure how the base template property would be inherited to the homepage's search box? |
It wouldn't, we'd need to add it to both the form on the homepage (which you've already done here) and to this form: https://github.com/pypa/warehouse/blob/597938cff04261fd55f59dd538982b4bfcad4621/warehouse/templates/base.html#L225-L233 |
Instead of registering a listener, use an action to inform the controller to take an action. Signed-off-by: Mike Fiedler <[email protected]>
In order to prevent the feature from taking over other input fields, only activate when NOT in an input field, so the `/` key can be used in any input field and not interfere with inputs. Signed-off-by: Mike Fiedler <[email protected]>
@di I think I'm ready for another review! I'm happier with this implementation - it's more tightly scoped, albeit increasing the html line length. |
Thanks, this is great! |
* Add controller for search focus for slash keypress While having the search key autofocus is forbidden, having a keypress focus the search field is a desirable feature. Add a new Stumulus Controller that listens to the `/` keypress and focuses the input on the search field. Note: Currently applies only to the home page. Refs: pypi#6099 Signed-off-by: Mike Fiedler <[email protected]> * refactor: use stimulus action instead of a listener Instead of registering a listener, use an action to inform the controller to take an action. Signed-off-by: Mike Fiedler <[email protected]> * feat: add search focus to base template In order to prevent the feature from taking over other input fields, only activate when NOT in an input field, so the `/` key can be used in any input field and not interfere with inputs. Signed-off-by: Mike Fiedler <[email protected]>
While having the search key autofocus is forbidden, having a keypress
focus the search field is a desirable feature.
Add a new Stimulus Controller that listens to the
/
keypress andfocuses the input on the search field.
Note: Currently applies only to the home page.
Fixes #6099
Signed-off-by: Mike Fiedler [email protected]