Skip to content

Commit

Permalink
fix: Add gap to overflow calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasBoll authored Nov 4, 2024
1 parent a46b224 commit 3ef2add
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions modules/react/collection/lib/useOverflowListMeasure.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import * as React from 'react';

import {createElemPropsHook, useForkRef, useResizeObserver} from '@workday/canvas-kit-react/common';
import {
createElemPropsHook,
useMountLayout,
useResizeObserver,
useLocalRef,
} from '@workday/canvas-kit-react/common';

import {useOverflowListModel} from './useOverflowListModel';

Expand All @@ -9,12 +14,22 @@ import {useOverflowListModel} from './useOverflowListModel';
* overflow detection.
*/
export const useOverflowListMeasure = createElemPropsHook(useOverflowListModel)((model, ref) => {
const localRef = React.useRef(null);
const {ref: resizeRef} = useResizeObserver({
// const localRef = React.useRef(null);
const {elementRef, localRef} = useLocalRef(ref as React.Ref<HTMLElement>);
const gapProperty = model.state.orientation === 'horizontal' ? 'columnGap' : 'rowGap';

useResizeObserver({
ref: localRef,
onResize: model.events.setContainerWidth,
});
const elementRef = useForkRef(ref, resizeRef);
useMountLayout(() => {
if (localRef.current) {
const styles = getComputedStyle(localRef.current);
model.events.setContainerGap({
size: styles.gap === 'normal' ? 0 : Number(styles[gapProperty].replace('px', '')),
});
}
});

return {
ref: elementRef,
Expand Down

0 comments on commit 3ef2add

Please sign in to comment.