mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
fix(tabs): tab cursor (#5769)
This commit is contained in:
parent
1f17962932
commit
812f7939d9
@ -66,17 +66,6 @@ const Tabs = forwardRef(function Tabs<T extends object>(
|
||||
};
|
||||
}
|
||||
|
||||
if (variant === "bordered") {
|
||||
const borderWidth = 2;
|
||||
|
||||
return {
|
||||
...baseStyles,
|
||||
top: `${relativeTop - borderWidth}px`,
|
||||
width: `${tabRect.width - borderWidth}px`,
|
||||
height: `${tabRect.height}px`,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...baseStyles,
|
||||
top: `${relativeTop}px`,
|
||||
@ -84,16 +73,13 @@ const Tabs = forwardRef(function Tabs<T extends object>(
|
||||
};
|
||||
};
|
||||
|
||||
const updateCursorPosition = (
|
||||
node: HTMLSpanElement,
|
||||
selectedTab: HTMLElement,
|
||||
parentRect: DOMRect,
|
||||
) => {
|
||||
const tabRect = selectedTab.getBoundingClientRect();
|
||||
const relativeLeft = tabRect.left - parentRect.left;
|
||||
const relativeTop = tabRect.top - parentRect.top;
|
||||
const updateCursorPosition = (node: HTMLSpanElement, selectedTab: HTMLElement) => {
|
||||
const tabRect = {
|
||||
width: selectedTab.offsetWidth,
|
||||
height: selectedTab.offsetHeight,
|
||||
} as DOMRect;
|
||||
|
||||
const styles = getCursorStyles(tabRect, relativeLeft, relativeTop);
|
||||
const styles = getCursorStyles(tabRect, selectedTab.offsetLeft, selectedTab.offsetTop);
|
||||
|
||||
node.style.left = styles.left;
|
||||
node.style.top = styles.top;
|
||||
@ -116,9 +102,7 @@ const Tabs = forwardRef(function Tabs<T extends object>(
|
||||
prevSelectedKey.current = selectedKey;
|
||||
prevVariant.current = variant;
|
||||
|
||||
const parentRect = domRef.current.getBoundingClientRect();
|
||||
|
||||
updateCursorPosition(node, selectedTab, parentRect);
|
||||
updateCursorPosition(node, selectedTab);
|
||||
};
|
||||
|
||||
const renderTabs = useMemo(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user