Skip to content

Commit

Permalink
Merge pull request #17 from krjakbrjak/VNI-scrollbars
Browse files Browse the repository at this point in the history
Handle scrollbars
  • Loading branch information
krjakbrjak authored Dec 24, 2023
2 parents d6778e5 + 3062e58 commit 1a91922
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@krjakbrjak/virtualtable",
"version": "1.1.7",
"version": "1.1.8",
"description": "",
"repository": {
"type": "git",
Expand Down
12 changes: 9 additions & 3 deletions src/VirtualTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function get_initial_state<T>(): State<T> {
y: 0,
height: 0,
width: 0,
}
},
}
}
function calculatePageCount(pageHeight: number, itemHeight: number) {
Expand Down Expand Up @@ -123,6 +123,7 @@ function reducer<Type>(state: State<Type>, action: Action<Type>): State<Type> {
export default function VirtualTable<Type>({ height, renderer, fetcher, style }: Args<Type>): JSX.Element {
const ref = useRef(null);
const invisible = useRef(null);
const scrolldiv = useRef(null);
const [collection, setCollection] = useState<LazyPaginatedCollection<Type>>(() => new LazyPaginatedCollection<Type>(1, fetcher));
const [state, dispatch] = useReducer(reducer<Type>, get_initial_state<Type>());

Expand Down Expand Up @@ -256,6 +257,10 @@ export default function VirtualTable<Type>({ height, renderer, fetcher, style }:
}
});

let scrollbarWidth = 0;
if (scrolldiv && scrolldiv.current) {
scrollbarWidth = scrolldiv.current.offsetWidth - scrolldiv.current.children[0].offsetWidth;
}

return (
<Container>
Expand All @@ -279,11 +284,12 @@ export default function VirtualTable<Type>({ height, renderer, fetcher, style }:
{state.itemHeight !== 0 && generate(state.offset, slideItems(state.offset, state.page))}
</div>
<div
className='overflow-scroll position-absolute'
ref={scrolldiv}
className='overflow-auto position-absolute'
style={{
top: state.rect.y,
left: state.rect.x,
width: state.rect.width,
width: state.rect.width + scrollbarWidth,
height: state.rect.height,
}}
onMouseMove={(e) => {
Expand Down

0 comments on commit 1a91922

Please sign in to comment.