-
-
Notifications
You must be signed in to change notification settings - Fork 996
fix: smooth scroll to search input with dynamic banner offset #1624
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
base: main
Are you sure you want to change the base?
fix: smooth scroll to search input with dynamic banner offset #1624
Conversation
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.
Hi and thanks so much for this. I've tested it locally and it seems to work very well.
One thing I noted is that the overlapping problem also shows up on outdated pages (like https://docs.djangoproject.com/en/1.8/) so it'd be nice to have it fixed there too. I've made a suggestion for how to do that but if you have a better idea I'm all ears.
Let me know what you think!
@@ -17,8 +17,14 @@ define([ | |||
|
|||
$(window).keydown(function(e) { | |||
if ((e.metaKey || e.ctrlKey) && e.key === 'k' && $('input:focus, textarea:focus').length === 0) { | |||
const warning_banner_height = $('#dev-warning').outerHeight() || 0; |
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.
There's also a banner when the version is outdated, but it uses a different id (#outdated-warning
). I would suggest using the class instead:
const warning_banner_height = $('#dev-warning').outerHeight() || 0; | |
const warning_banner_height = $('.doc-floating-warning').outerHeight() || 0; |
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.
Thanks @bmispelon for the suggestion. Apologies for responding so late, I must have missed this comment.
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.
Since search-key.js was refactored into djangoproject.js
, I have make the suggested changes in the designated place. Please re-review. 🙌
@FreakPirate Could you address the comments on this PR if you're still interested in working on it? Otherwise it will be closed in a week. Thanks! |
Hi @adamzap . I must have missed the comment. Let me address it right away. Thanks for being considerate 🙌 |
- Adjusted scroll behavior to account for the height of the `.doc-floating-warning` banner (suggested by django#1624 (comment)) - Replaced `scrollIntoView` with `window.scrollTo` to scroll smoothly to the search input, leaving space for the banner
6aa6003
to
88d2180
Compare
for more information, see https://pre-commit.ci
@FreakPirate Thanks for this! Let me see if we are able to get #2075 in before we move forward here. |
@FreakPirate Thanks for your patience here. @bmispelon I think it's unfortunate that this code has to account for the floating warning element specifically. If we added another element with a fixed position at the top of the page, we'd have to account for it in this JavaScript code. I suppose another option would be to just scroll to the top of the page. Does that seem cleaner to you, or does it worsen the user experience here? |
Overview
This pull request addresses the scrolling behavior when focusing on the search input field via the shortcut (Ctrl + K / Cmd + K). The previous implementation did not account for the height of the warning banner, resulting in a less-than-ideal user experience.
Changes Made
#dev-warning
banner, ensuring that the search input is not obscured.scrollIntoView
: The code now useswindow.scrollTo
to smoothly scroll to the search input's position while accounting for the banner's height.Testing
Issue Reference
This pull request fixes #1620.