[BUG] - Scroll position can change in Safari when switching Tabs (<Tab>)
NextUI Version
v2.1.3
Describe the bug
When using Tabs, Safari keeps scrolling unless the Tabs component is wrapped in a parent which has fixed height. Likely, when switching tabs, the origin is unmounted, which causes the page to change overall height and to scroll.
Your Example Website or App
https://codesandbox.io/p/sandbox/kind-dream-99pw35?file=/App.jsx:42,18&utm_medium=sandpack
Steps to Reproduce the Bug or Issue
In Safari when scrolled to the bottom of the page and changing Tabs, the scroll position changes.
Expected behavior
Behaviour as in Chrome, so that scroll position is not changing.
Screenshots or Videos
https://github.com/nextui-org/nextui/assets/13927969/8257742e-e6d3-4b2b-b4bc-f955f5d8bf40
Operating System Version
macOS
Browser
Safari
The reproduced link cannot be opened. Could you please share a new link or repository?
Why not? I just tried from device where I am not logged in and works perfectly. @jrgarciadev already used the link and worked for him. Can you give some details what does not work for you?
But just in case, it's fairly trivial, just added some space on top of the example code:
import React from "react";
import { Tabs, Tab, Card, CardBody } from "@nextui-org/react";
export default function App() {
return (
<div className="flex w-full flex-col">
<div className="h-80 bg-content3 mb-unit-lg"></div>
<div className="h-80 bg-content2 mb-unit-lg"></div>
<div className="h-80 bg-content3 mb-unit-lg"></div>
<div className="h-80 bg-content2 mb-unit-lg"></div>
<div className="h-80 bg-content3 mb-unit-lg"></div>
<div className="h-80 bg-content2 mb-unit-lg"></div>
<div className="h-80 bg-content3 mb-unit-lg"></div>
<div className="h-80 bg-content2 mb-unit-lg"></div>
<Tab aria-label="Options">
<Tab key="photos" title="Photos">
<Card>
<CardBody>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat.
</CardBody>
</Card>
</Tab>
<Tab key="music" title="Music">
<Card>
<CardBody>
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat
nulla pariatur.
</CardBody>
</Card>
</Tab>
<Tab key="videos" title="Videos">
<Card>
<CardBody>
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
officia deserunt mollit anim id est laborum.
</CardBody>
</Card>
</Tab>
</Tabs>
</div>
);
}
I see, the reproduction code above was edited - basically using "disableAnimation" fixes the issue, but has hard transition. If Using with animation it jumps around.
This is a part of the code for the Tabs component.
I added the "disableAnimation" parameter within the
This disables the animation effect of the Tabs component. Then, I looked into the source code of the Tabs component and found that it references import {LayoutGroup} from "framer-motion";. Perhaps, this is an issue with framer-motion.https://www.framer.com/motion/layout-group
@phev8 This is happening for me in chrome too? Did you do something different for chrome to not have this?
It also happens with Chrome and Firefox.
@phev8 As I explored a bit, if you wrap your Tabs in a container with a fix height, it solves the issue. I think it's related to how FramerMotion handles animation.
not able to reproduce on latest version.