File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change 11/**
22 * Smooth scrolling onClick event handler
33 * @param {string } selector argument will be passed to `querySelector`, usually an HTML id
4+ * @returns {boolean } false if `document.querySelector` doesn't find a match, otherwise true
45 */
5- declare const scrollTo : ( selector : string ) => void ;
6+ declare const scrollTo : ( selector : string ) => boolean ;
67export default scrollTo ;
Original file line number Diff line number Diff line change 11/**
22 * Smooth scrolling onClick event handler
33 * @param {string } selector argument will be passed to `querySelector`, usually an HTML id
4+ * @returns {boolean } false if `document.querySelector` doesn't find a match, otherwise true
45 */
56const scrollTo = ( selector ) => {
6- document . querySelector ( selector ) . scrollIntoView ( {
7- behavior : 'smooth' ,
8- block : 'start' ,
9- } ) ;
7+ const element = document . querySelector ( selector ) ;
8+
9+ if ( element ) {
10+ element . scrollIntoView ( {
11+ behavior : 'smooth' ,
12+ block : 'start' ,
13+ } ) ;
14+
15+ return true ;
16+ }
17+
18+ if ( process . env . NODE_ENV !== 'production' ) {
19+ console . warn (
20+ "gatsby-plugin-smoothscroll:\n The selector: '%s' wasn't found in the document.\n Make sure you pass in a valid CSS selector string." ,
21+ selector
22+ ) ;
23+ }
24+
25+ return false ;
1026} ;
1127
1228export default scrollTo ;
You can’t perform that action at this time.
0 commit comments