Skip to content
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

fix: smooth scroll to search input with dynamic banner offset #1624

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

FreakPirate
Copy link

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

  • Adjusted Scroll Behavior: The scroll position now considers the height of the #dev-warning banner, ensuring that the search input is not obscured.
  • Replaced scrollIntoView: The code now uses window.scrollTo to smoothly scroll to the search input's position while accounting for the banner's height.
  • Improved User Experience: This change provides a seamless transition when the search input is focused, improving overall usability.

Testing

  • Tested the functionality across different browsers to ensure compatibility.
  • Verified that the scrolling behaves as expected with and without the warning banner present.

Issue Reference

This pull request fixes #1620.

- Adjusted scroll behavior to account for the height of the `#dev-warning` banner
- Replaced `scrollIntoView` with `window.scrollTo` to scroll smoothly to the search input, leaving space for the banner
Copy link
Member

@bmispelon bmispelon left a 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;
Copy link
Member

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:

Suggested change
const warning_banner_height = $('#dev-warning').outerHeight() || 0;
const warning_banner_height = $('.doc-floating-warning').outerHeight() || 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dev-warning strip on Django docs development version covers the search bar when used shortcut search key
2 participants