File tree Expand file tree Collapse file tree 4 files changed +28
-11
lines changed Expand file tree Collapse file tree 4 files changed +28
-11
lines changed Original file line number Diff line number Diff line change 1+ # Change Log
2+
3+ All notable changes to this project will be documented in this file.
4+
5+ ## [ 2.1.0] - 2021-11-13
6+
7+ ### Added
8+
9+ - Set ` useBoxMethod ` as default way to check if ` Element ` is in ` viewport ` .
10+ - Can be overridden by setting ` useBoxMethod ` to ` false ` .
11+
12+ ### Fixed
13+
14+ - Problems when div to Spy is not ` 100vh ` .
15+
16+ ## [ 2.0.1] (Beta) - 2021-11-9
17+
18+ - Beta version to test ` 2.1.0 ` release.
Original file line number Diff line number Diff line change @@ -110,10 +110,11 @@ import ScrollSpy from "react-ui-scrollspy";
110110
111111### 🔧 Customize Attributes
112112
113- | Attributes | Type | Description | Default | Required |
114- | :----------------- | :------- | :-------------------------------------------------------- | :-------------------- | :------- |
115- | ` useDataAttribute ` | ` string ` | To customize the string after ` data- ` | ` "to-scrollspy-id" ` | no |
116- | ` activeClass ` | ` string ` | To customize the ` class ` added when the ` Element ` in view | ` "active-scroll-spy" ` | no |
113+ | Attributes | Type | Description | Default | Required |
114+ | :----------------- | :-------- | :------------------------------------------------------------------------------- | :-------------------- | :------- |
115+ | ` useDataAttribute ` | ` string ` | To customize the string after ` data- ` | ` "to-scrollspy-id" ` | no |
116+ | ` activeClass ` | ` string ` | To customize the ` class ` added when the ` Element ` in view | ` "active-scroll-spy" ` | no |
117+ | ` useBoxMethod ` | ` boolean ` | Set to ` false ` if you want your spy to be active if 50% of that ` div ` is in view | ` true ` | no |
117118
118119## 📝 Authors
119120
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ const ScrollSpy = ({
5353 useDataAttribute = "to-scrollspy-id" ,
5454 activeClass = "active-scroll-spy" ,
5555
56- useBoxMethod = false ,
56+ useBoxMethod = true ,
5757} : ScrollSpyProps ) => {
5858 const scrollContainerRef = useRef < HTMLDivElement | null > ( null ) ;
5959 const [ navContainerItems , setNavContainerItems ] = useState < NodeListOf < Element > | undefined > ( ) ; // prettier-ignore
@@ -85,17 +85,15 @@ const ScrollSpy = ({
8585 } , [ navContainerItems ] ) ;
8686
8787 const isVisible = ( el : HTMLElement ) => {
88- if ( useBoxMethod ) {
89- var rectInView = el . getBoundingClientRect ( ) ;
88+ const rectInView = el . getBoundingClientRect ( ) ;
9089
90+ if ( useBoxMethod ) {
9191 const hitbox_top = window . innerHeight ;
9292 const element_top = rectInView . top ;
9393 const element_bottom = rectInView . top + window . innerHeight ;
9494
9595 return hitbox_top < element_bottom && hitbox_top > element_top ;
9696 } else {
97- const rectInView = el . getBoundingClientRect ( ) ;
98-
9997 // this decides how much of the element should be visible
10098 const leniency = parentScrollContainerRef ?. current
10199 ? parentScrollContainerRef ?. current . offsetHeight * 0.5
You can’t perform that action at this time.
0 commit comments