Skip to content

Commit

Permalink
Fixed #7516 - DataTable is not displayed within the TabView when rend…
Browse files Browse the repository at this point in the history
…erActiveOnly={false} is set.
  • Loading branch information
mertsincan committed Dec 20, 2024
1 parent 505c4da commit f089480
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions components/lib/virtualscroller/VirtualScroller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { PrimeReactContext } from '../api/Api';
import { useEventListener, useMergeProps, useMountEffect, usePrevious, useResizeListener, useStyle, useUpdateEffect } from '../hooks/Hooks';
import { useEventListener, useMergeProps, usePrevious, useResizeListener, useStyle, useUpdateEffect } from '../hooks/Hooks';
import { SpinnerIcon } from '../icons/spinner';
import { DomHandler, IconUtils, ObjectUtils, classNames } from '../utils/Utils';
import { VirtualScrollerBase } from './VirtualScrollerBase';
Expand Down Expand Up @@ -52,6 +52,7 @@ export const VirtualScroller = React.memo(
const defaultContentHeight = React.useRef(null);
const isItemRangeChanged = React.useRef(false);
const lazyLoadState = React.useRef(null);
const viewInitialized = React.useRef(false);

const [bindWindowResizeListener] = useResizeListener({ listener: (event) => onResize(event), when: !props.disabled });
const [bindOrientationChangeListener] = useEventListener({ target: 'window', type: 'orientationchange', listener: (event) => onResize(event), when: !props.disabled });
Expand Down Expand Up @@ -540,15 +541,24 @@ export const VirtualScroller = React.memo(
};

const init = () => {
if (!props.disabled) {
if (!props.disabled && isVisible(elementRef.current)) {
setSize();
calculateOptions();
setSpacerSize();
}
};

useMountEffect(() => {
viewInit();
const isVisible = () => {
const rect = elementRef.current.getBoundingClientRect();

return rect.width > 0 && rect.height > 0;
};

React.useEffect(() => {
if (!viewInitialized.current && isVisible(elementRef.current)) {
viewInit();
viewInitialized.current = true;
}
});

useUpdateEffect(() => {
Expand Down

0 comments on commit f089480

Please sign in to comment.