Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: offset四舍五入导致hiddenTabs计算逻辑错误 #667

Closed
Closed
Changes from 1 commit
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
26 changes: 17 additions & 9 deletions src/TabNavList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export interface TabNavListProps {
}

const getSize = (refObj: React.RefObject<HTMLElement>): SizeInfo => {
const { offsetWidth = 0, offsetHeight = 0 } = refObj.current || {};
return [offsetWidth, offsetHeight];
const { width = 0, height = 0 } = refObj?.current?.getBoundingClientRect() || {};
return [width, height];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};

/**
Expand Down Expand Up @@ -311,19 +311,28 @@ function TabNavList(props: TabNavListProps, ref: React.Ref<HTMLDivElement>) {
setTabSizes(() => {
const newSizes: TabSizeMap = new Map();
tabs.forEach(({ key }) => {
const btnNode = tabListRef.current?.querySelector<HTMLElement>(`[data-node-key="${genDataNodeKey(key)}"]`);
const btnNode = tabListRef.current?.querySelector<HTMLElement>(
`[data-node-key="${genDataNodeKey(key)}"]`,
);
if (btnNode) {
const {
width = 0,
height = 0,
left = 0,
top = 0,
} = btnNode.getBoundingClientRect() || {};
const { left: parentLeft = 0, top: parentTop = 0 } =
tabListRef?.current?.getBoundingClientRect() || {};
newSizes.set(key, {
width: btnNode.offsetWidth,
height: btnNode.offsetHeight,
left: btnNode.offsetLeft,
top: btnNode.offsetTop,
width,
height,
left: left - parentLeft,
top: top - parentTop,
});
}
});
return newSizes;
});

useEffect(() => {
updateTabSizes();
}, [tabs.map(tab => tab.key).join('_')]);
Expand All @@ -350,7 +359,6 @@ function TabNavList(props: TabNavListProps, ref: React.Ref<HTMLDivElement>) {
tabContentFullSize[0] - newAddSize[0],
tabContentFullSize[1] - newAddSize[1],
]);

// Update buttons records
updateTabSizes();
});
Expand Down
Loading