diff --git a/.changeset/ninety-flowers-teach.md b/.changeset/ninety-flowers-teach.md new file mode 100644 index 0000000000..6189a49943 --- /dev/null +++ b/.changeset/ninety-flowers-teach.md @@ -0,0 +1,6 @@ +--- +"@heroui/use-data-scroll-overflow": patch +"@heroui/listbox": patch +--- + +fixed unexpected scrollShadow on virtualized listbox (#4553) diff --git a/packages/components/listbox/src/virtualized-listbox.tsx b/packages/components/listbox/src/virtualized-listbox.tsx index 0bd255bf01..5a8d57e762 100644 --- a/packages/components/listbox/src/virtualized-listbox.tsx +++ b/packages/components/listbox/src/virtualized-listbox.tsx @@ -105,7 +105,10 @@ const VirtualizedListbox = (props: Props) => { const virtualItems = rowVirtualizer.getVirtualItems(); - /* Here we need the base props for scroll shadow, contains the className (scrollbar-hide and scrollshadow config based on the user inputs on select props) */ + const virtualScrollHeight = rowVirtualizer.getTotalSize(); + + // Here we need the base props for scroll shadow, + // contains the className (scrollbar-hide and scrollshadow config based on the user inputs on select props) const {getBaseProps: getBasePropsScrollShadow} = useScrollShadow({...scrollShadowProps}); const renderRow = (virtualItem: VirtualItem) => { @@ -162,6 +165,7 @@ const VirtualizedListbox = (props: Props) => { return listboxItem; }; + // eslint-disable-next-line @typescript-eslint/no-unused-vars const [scrollState, setScrollState] = useState({ isTop: false, isBottom: true, @@ -169,7 +173,11 @@ const VirtualizedListbox = (props: Props) => { }); const content = ( - + {!state.collection.size && !hideEmptyContent && (
  • @@ -178,9 +186,6 @@ const VirtualizedListbox = (props: Props) => {
    { {listHeight > 0 && itemHeight > 0 && (
    offset : el.scrollLeft > offset; + const hasBefore = type === "vertical" ? scrollTop > offset : el.scrollLeft > offset; const hasAfter = type === "vertical" - ? el.scrollTop + el.clientHeight + offset < el.scrollHeight + ? scrollTop + el.clientHeight + offset < scrollHeight : el.scrollLeft + el.clientWidth + offset < el.scrollWidth; setAttributes(type, hasBefore, hasAfter, prefix, suffix); @@ -132,8 +142,7 @@ export function useDataScrollOverflow(props: UseDataScrollOverflowProps = {}) { }; // auto - checkOverflow(); - el.addEventListener("scroll", checkOverflow); + el.addEventListener("scroll", checkOverflow, true); // controlled if (visibility !== "auto") { @@ -152,7 +161,7 @@ export function useDataScrollOverflow(props: UseDataScrollOverflowProps = {}) { } return () => { - el.removeEventListener("scroll", checkOverflow); + el.removeEventListener("scroll", checkOverflow, true); clearOverflow(); }; }, [...updateDeps, isEnabled, visibility, overflowCheck, onVisibilityChange, domRef]);