nextui icon indicating copy to clipboard operation
nextui copied to clipboard

[BUG] - Scroll position can change in Safari when switching Tabs (<Tab>)

Open phev8 opened this issue 3 years ago • 9 comments

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

phev8 avatar Aug 22 '23 14:08 phev8

The reproduced link cannot be opened. Could you please share a new link or repository?

CHENFANGC avatar Aug 27 '23 17:08 CHENFANGC

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?

phev8 avatar Aug 27 '23 18:08 phev8

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>
  );
}

phev8 avatar Aug 27 '23 18:08 phev8

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.

phev8 avatar Aug 27 '23 18:08 phev8

This is a part of the code for the Tabs component. image

I added the "disableAnimation" parameter within the tag in your code, like this: image 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

CHENFANGC avatar Aug 28 '23 13:08 CHENFANGC

@phev8 This is happening for me in chrome too? Did you do something different for chrome to not have this?

ttiras avatar Oct 25 '23 07:10 ttiras

It also happens with Chrome and Firefox.

RibeyrollesMatthieu avatar Nov 20 '23 12:11 RibeyrollesMatthieu

@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.

RibeyrollesMatthieu avatar Nov 21 '23 18:11 RibeyrollesMatthieu

not able to reproduce on latest version.

wingkwong avatar May 26 '25 16:05 wingkwong