File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
packages/core/useElementVisibility Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,11 @@ describe('useElementVisibility', () => {
2525 expect ( visible . value ) . toBeFalsy ( )
2626 } )
2727
28+ it ( 'should allow set initial value' , ( ) => {
29+ const visible = useElementVisibility ( el , { initialValue : true } )
30+ expect ( visible . value ) . toBeTruthy ( )
31+ } )
32+
2833 describe ( 'when internally using useIntersectionObserver' , async ( ) => {
2934 beforeAll ( ( ) => {
3035 vi . resetAllMocks ( )
Original file line number Diff line number Diff line change @@ -8,6 +8,12 @@ import { defaultWindow } from '../_configurable'
88import { useIntersectionObserver } from '../useIntersectionObserver'
99
1010export interface UseElementVisibilityOptions extends ConfigurableWindow , Pick < UseIntersectionObserverOptions , 'threshold' > {
11+ /**
12+ * Initial value.
13+ *
14+ * @default false
15+ */
16+ initialValue ?: boolean
1117 /**
1218 * @see https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/rootMargin
1319 */
@@ -39,8 +45,9 @@ export function useElementVisibility(
3945 threshold = 0 ,
4046 rootMargin,
4147 once = false ,
48+ initialValue = false ,
4249 } = options
43- const elementIsVisible = shallowRef ( false )
50+ const elementIsVisible = shallowRef ( initialValue )
4451
4552 const { stop } = useIntersectionObserver (
4653 element ,
You can’t perform that action at this time.
0 commit comments