forked from WebDevN-F/thenativeweb-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add smooth scrolling to Link component. (#348)
* feat: Add smooth scrolling to Link component. * Add unit tests for onClick and onMouseOver.
- Loading branch information
Matthias Wagler
authored
Feb 28, 2020
1 parent
77d5572
commit 28cfb0b
Showing
9 changed files
with
137 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { MouseEvent } from 'react'; | ||
|
||
const scrollToAnchor = function (event: MouseEvent<HTMLElement>): void { | ||
const href = event.currentTarget.getAttribute('href'); | ||
|
||
if (!href) { | ||
return; | ||
} | ||
|
||
const targetToScrollTo = document.querySelector(href); | ||
|
||
if (!targetToScrollTo) { | ||
return; | ||
} | ||
|
||
event.preventDefault(); | ||
|
||
targetToScrollTo.scrollIntoView({ behavior: 'smooth' }); | ||
}; | ||
|
||
export { scrollToAnchor }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters