Skip to content

Commit

Permalink
Merge pull request #307 from projectEndings/iss282-scrolling
Browse files Browse the repository at this point in the history
Abstracted the scrolling behaviour to an overridable method.
  • Loading branch information
joeytakeda committed Jun 4, 2024
2 parents c547fc0 + 4cedd59 commit 3f03a69
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion js/StaticSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ class StaticSearch{
//search has completed.
this.searchFinishedHook = function(num){};

//We add another function which can be overridden by end-users if
//for example they need the results div to be scrolled while taking
//account of a fixed page header or something similar.
this.scrollToResults = function(){this.resultsDiv.scrollIntoView({behavior: 'smooth', block: 'start'});};

//We add a method which can be overridden by end users to do any
//special handling for input strings (such as removing some diacritics
//but not others).
Expand Down Expand Up @@ -680,7 +685,7 @@ class StaticSearch{
else{
this.isSearching = false;
}
window.scroll({ top: this.resultsDiv.offsetTop, behavior: "smooth" });
this.scrollToResults();
return result;
}

Expand Down
16 changes: 16 additions & 0 deletions test/testCss/testCss.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
* test suite, and is never needed in a working search
* application context. */

/* Uncomment this if you wish to work on scrolling a
* result set into view while working around the problem
* of a fixed header which may obscure it. This provides
* an extreme example of the problem for dev purposes. */
/*
body:has(div#staticSearch) h1{
position: fixed;
top: 0;
margin: 0 0 0.25em 0;;
padding: 1em;
background-color: white;
border: solid 1pt gray;
width: 100%;
height: 30vh;
} */

#testResults{
margin: 2em;
border-top: solid 1pt black;
Expand Down

0 comments on commit 3f03a69

Please sign in to comment.