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";
110
110
111
111
### 🔧 Customize Attributes
112
112
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 |
117
118
118
119
## 📝 Authors
119
120
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ const ScrollSpy = ({
53
53
useDataAttribute = "to-scrollspy-id" ,
54
54
activeClass = "active-scroll-spy" ,
55
55
56
- useBoxMethod = false ,
56
+ useBoxMethod = true ,
57
57
} : ScrollSpyProps ) => {
58
58
const scrollContainerRef = useRef < HTMLDivElement | null > ( null ) ;
59
59
const [ navContainerItems , setNavContainerItems ] = useState < NodeListOf < Element > | undefined > ( ) ; // prettier-ignore
@@ -85,17 +85,15 @@ const ScrollSpy = ({
85
85
} , [ navContainerItems ] ) ;
86
86
87
87
const isVisible = ( el : HTMLElement ) => {
88
- if ( useBoxMethod ) {
89
- var rectInView = el . getBoundingClientRect ( ) ;
88
+ const rectInView = el . getBoundingClientRect ( ) ;
90
89
90
+ if ( useBoxMethod ) {
91
91
const hitbox_top = window . innerHeight ;
92
92
const element_top = rectInView . top ;
93
93
const element_bottom = rectInView . top + window . innerHeight ;
94
94
95
95
return hitbox_top < element_bottom && hitbox_top > element_top ;
96
96
} else {
97
- const rectInView = el . getBoundingClientRect ( ) ;
98
-
99
97
// this decides how much of the element should be visible
100
98
const leniency = parentScrollContainerRef ?. current
101
99
? parentScrollContainerRef ?. current . offsetHeight * 0.5
You can’t perform that action at this time.
0 commit comments