Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Fix: Ensure 'start buffer' is margin padded into the non-virtualized space on horizontal layouts",
"packageName": "@fluentui/react-virtualizer",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export function useVirtualizer_unstable(props: VirtualizerProps): VirtualizerSta
// Local updates
updateChildRows(index);
updateCurrentItemSizes(index);

// State setters
setActualIndex(index);
};
Expand Down Expand Up @@ -277,7 +276,7 @@ export function useVirtualizer_unstable(props: VirtualizerProps): VirtualizerSta
}, [getItemSize, itemSize, numItems]);

const calculateBefore = useCallback(() => {
const currentIndex = Math.min(actualIndex, numItems);
const currentIndex = Math.min(actualIndex, numItems - 1);

if (!getItemSize) {
// The missing items from before virtualization starts height
Expand All @@ -293,19 +292,19 @@ export function useVirtualizer_unstable(props: VirtualizerProps): VirtualizerSta
}, [actualIndex, getItemSize, itemSize, numItems]);

const calculateAfter = useCallback(() => {
if (numItems === 0) {
if (numItems === 0 || actualIndex + virtualizerLength >= numItems) {
return 0;
}

const lastItemIndex = Math.min(actualIndex + virtualizerLength, numItems - 1);
const lastItemIndex = Math.min(actualIndex + virtualizerLength, numItems);
if (!getItemSize) {
// The missing items from after virtualization ends height
const remainingItems = numItems - lastItemIndex - 1;
const remainingItems = numItems - lastItemIndex;
return remainingItems * itemSize;
}

// Time for custom size calcs
return childProgressiveSizes.current[numItems - 1] - childProgressiveSizes.current[lastItemIndex];
return childProgressiveSizes.current[numItems - 1] - childProgressiveSizes.current[lastItemIndex - 1];
}, [actualIndex, getItemSize, itemSize, numItems, virtualizerLength]);

const updateChildRows = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ export const useVirtualizerStyles_unstable = (state: VirtualizerState): Virtuali
// Column-Reverse
...(reversed && !horizontal && { marginTop: `-${bufferPx}` }),
// Row
...(!reversed && horizontal && { marginLeft: `-${bufferPx}` }),
...(!reversed && horizontal && { marginRight: `-${bufferPx}` }),
// Row-Reverse
...(reversed && horizontal && { marginRight: `-${bufferPx}` }),
...(reversed && horizontal && { marginLeft: `-${bufferPx}` }),
};

const afterBuffer = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ const useStyles = makeStyles({
display: 'flex',
width: '100%',
height: '100%',
overflowAnchor: 'none',
},
vertical: {
flexDirection: 'column',
overflowAnchor: 'none',
overflowY: 'auto',
},
horizontal: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const useStyles = makeStyles({
display: 'flex',
width: '100%',
height: '100%',
overflowAnchor: 'none',
},
vertical: {
flexDirection: 'column',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ export const useDynamicVirtualizerMeasure = <TElement extends HTMLElement>(
/*
* Number of items to append at each end, i.e. 'preload' each side before entering view.
*/
const bufferItems = Math.max(Math.floor(length / 4), 2);
const bufferItems = Math.max(Math.floor(length / 4), 4);

/*
* This is how far we deviate into the bufferItems to detect a redraw.
*/
const bufferSize = Math.max(Math.floor((length / 8) * defaultItemSize), 1);

const totalLength = length + bufferItems * 2 + 3;
const totalLength = length + bufferItems * 2 + 1;
setState({
virtualizerLength: totalLength,
virtualizerBufferSize: bufferSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const useStyles = makeStyles({
container: {
display: 'flex',
flexDirection: 'column',
overflowAnchor: 'none',
overflowY: 'auto',
width: '100%',
height: '100%',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const useStyles = makeStyles({
*/
display: 'flex',
flexDirection: 'column',
overflowAnchor: 'none',
maxHeight: '300VH',
width: '100%',
height: '100%',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const useStyles = makeStyles({
container: {
display: 'flex',
flexDirection: 'column',
overflowAnchor: 'none',
overflowY: 'auto',
width: '100%',
height: '100%',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const useStyles = makeStyles({
container: {
display: 'flex',
flexDirection: 'row',
overflowAnchor: 'none',
overflowY: 'auto',
width: '100%',
height: '100%',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const useStyles = makeStyles({
*/
display: 'flex',
flexDirection: 'column',
overflowAnchor: 'none',
maxHeight: '300VH',
width: '100%',
height: '100%',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const useStyles = makeStyles({
container: {
display: 'flex',
flexDirection: 'row',
overflowAnchor: 'none',
overflowY: 'auto',
width: '100%',
height: '100%',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const useStyles = makeStyles({
container: {
display: 'flex',
flexDirection: 'column-reverse',
overflowAnchor: 'none',
overflowY: 'auto',
width: '100%',
height: '100%',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const useStyles = makeStyles({
container: {
display: 'flex',
flexDirection: 'row-reverse',
overflowAnchor: 'none',
overflowY: 'auto',
width: '100%',
height: '100%',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Button, makeStyles, shorthands, useArrowNavigationGroup } from '@fluentui/react-components';
import * as React from 'react';
import { VirtualizerScrollView } from '@fluentui/react-components/unstable';

const useStyles = makeStyles({
container: {
maxHeight: '300px',
width: '100%',
maxWidth: '100%',
scrollSnapType: 'x mandatory',
scrollBehavior: 'auto',
...shorthands.padding('10px', '2px'),
...shorthands.gap('10px'),
},
child: {
scrollSnapAlign: 'start',
height: '100px',
width: '100px',
midWidth: '100px',
},
button: {
width: '100%',
height: '100%',
},
});

export const SnapToAlignment = () => {
const styles = useStyles();
const childLength = 1000;
const attributes = useArrowNavigationGroup({
axis: 'horizontal',
memorizeCurrent: true,
});

return (
<VirtualizerScrollView
numItems={childLength}
itemSize={100}
axis="horizontal"
container={{ role: 'list', className: styles.container, ...attributes }}
>
{(index: number) => {
return (
<div
role={'listitem'}
aria-posinset={index}
aria-setsize={childLength}
key={`test-virtualizer-child-${index}`}
className={styles.child}
>
<Button className={styles.button}>{`Node-${index}`}</Button>
</div>
);
}}
</VirtualizerScrollView>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import descriptionMd from './VirtualizerScrollViewDescription.md';

export { Default } from './Default.stories';
export { ScrollTo } from './ScrollTo.stories';
export { SnapToAlignment } from './SnapToAlignment.stories';

export default {
title: 'Preview Components/VirtualizerScrollView',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const Default = () => {
useEffect(() => {
let _totalSize = 0;
for (let i = 0; i < childLength; i++) {
arraySize.current[i] = Math.random() * 150 + minHeight;
arraySize.current[i] = Math.floor(Math.random() * 150 + minHeight);
_totalSize += arraySize.current[i];
}
setTotalSize(_totalSize);
Expand Down