Skip to content

Commit ecbcfc0

Browse files
committed
Fix responsive search not at top of page
fixed #7117
1 parent b45e69d commit ecbcfc0

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

news/changelog-1.4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116

117117
- ([#7105](https://github.com/quarto-dev/quarto-cli/issues/7105)): Improve search results by raising default limit and fixing and removing warning that would appear for Algolia when limit was more than 20.
118118
- ([#7150](https://github.com/quarto-dev/quarto-cli/issues/7150)): Search keyboard shortcut will not intercept keys directed at inputs.
119+
- ([#7117](https://github.com/quarto-dev/quarto-cli/issues/7117)): Ensure that search works properly in mobile layouts when not scrolled to top of page (don't close search when scroll occurs because of keyboard being shown).
119120

120121
## Books
121122

src/resources/projects/website/search/quarto-search.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,30 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
409409
}
410410
}
411411

412+
function throttle(func, wait) {
413+
let waiting = false;
414+
return function () {
415+
if (!waiting) {
416+
func.apply(this, arguments);
417+
waiting = true;
418+
setTimeout(function () {
419+
waiting = false;
420+
}, wait);
421+
}
422+
};
423+
}
424+
412425
// If the main document scrolls dismiss the search results
413426
// (otherwise, since they're floating in the document they can scroll with the document)
414-
window.document.body.onscroll = () => {
415-
setIsOpen(false);
416-
};
427+
window.document.body.onscroll = throttle(() => {
428+
// Only do this if we're not detached
429+
// Bug #7117
430+
// This will happen when the keyboard is shown on ios (resulting in a scroll)
431+
// which then closed the search UI
432+
if (!window.matchMedia(detachedMediaQuery).matches) {
433+
setIsOpen(false);
434+
}
435+
}, 50);
417436

418437
if (showSearchResults) {
419438
setIsOpen(true);

0 commit comments

Comments
 (0)