Assistance required with scrollable tab content in Chakra UI

When implementing the Tabs component in Chakra UI version 2, I encountered an issue where the content overflows instead of being scrollable:

function App() {
  return (
    <ChakraProvider>
      <Box
        width={300}
        height={300}
        borderWidth={2}
        borderRadius="lg"
        margin={4}
        padding={2}
      >
        <Flex direction="column">
          <Box flex="1">
            <Tabs height="full" display="flex" flexDirection="column">
              <TabList>
                <Tab>Tab 1</Tab>
                <Tab>Tab 2</Tab>
              </TabList>
              <TabPanels overflowY="scroll">
                <TabPanel>
                  <Text>Content for Tab 1</Text>
                </TabPanel>
                <TabPanel>
                  <LoremIpsum />
                </TabPanel>
              </TabPanels>
            </Tabs>
          </Box>
        </Flex>
      </Box>
    </ChakraProvider>
  );
}

The above code snippet demonstrates the issue visually.

https://i.sstatic.net/J6aVTZ2C.png

To resolve this problem, removing the 'Flex' and inner 'Box' components surrounding the 'Tabs' component seems to fix the overflow:

function App() {
  return (
    <ChakraProvider>
      <Box
        width={300}
        height={300}
        borderWidth={2}
        borderRadius="lg"
        margin={4}
        padding={2}
      >
            <Tabs height="full" display="flex" flexDirection="column">
              <TabList>
                <Tab>Tab 1</Tab>
                <Tab>Tab 2</Tab>
              </TabList>
              <TabPanels overflowY="scroll">
                <TabPanel>
                  <Text>Content for Tab 1</Text>
                </TabPanel>
                <TabPanel>
                  <LoremIpsum />
                </TabPanel>
              </TabPanels>
            </Tabs>
      </Box>
    </ChakraProvider>
  );
}

https://i.sstatic.net/E4osTJYZ.png

However, as mentioned, these additional components are essential in my code structure and cannot be removed. How can I address this issue without eliminating them?

If you want to test the solution, click here (allow some time for it to load).

(I appreciate any assistance provided, as this has been a persistent challenge that I am trying to overcome.)

Answer №1

It is crucial to ensure that all parent components define their height. Notably, once the height="full" attribute is included in both the Flex and the Box component that was previously removed in the second example, the layout issue is resolved and the tab content will scroll as intended:

function App() {
  return (
    <ChakraProvider>
      <Box
        width={300}
        height={300}
        borderWidth={2}
        borderRadius="lg"
        margin={4}
        padding={2}
      >
        <Flex height="full" direction="column">
          <Box height="full" flex="1">
            <Tabs height="full" display="flex" flexDirection="column">
              <TabList>
                <Tab>Tab 1</Tab>
                <Tab>Tab 2</Tab>
              </TabList>
              <TabPanels overflowY="scroll">
                <TabPanel>
                  <Text>Content for Tab 1</Text>
                </TabPanel>
                <TabPanel>
                  <LoremIpsum />
                </TabPanel>
              </TabPanels>
            </Tabs>
          </Box>
        </Flex>
      </Box>
    </ChakraProvider>
  );
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it more beneficial to include a JSON or CSV file in a web application in order to store default data?

In the process of developing a React web application, I am enabling users to select from a predefined list of data in order to generate a version that they can modify as needed. At present, the data is stored in an excel file. My initial plan was to conve ...

Encountering 404 error and various other errors during the deployment of GitHub pages

I've been working on deploying my portfolio website that was built with React. I'm utilizing Github Pages for deployment. During the process, I encountered a 404 error while trying to deploy my site. Here's the discussion thread where I fou ...

How can I retrieve the current background color and revert it back after a .hover event?

I am trying to use the .hover function to change the background color of a menu. Each menu item has a different background color, so I want it to return to its original color when the user hovers off. In other words, I want the script to read the current b ...

Building a dropdown feature for rows in a table using ReactJS

I am utilizing a Material UI Table, and within one of the columns I have a SelectField component that displays a dropdown with a few selectable items. Here is a snippet of the code: <TableBody displayRowCheckbox={this.state.showCheckboxes} ...

Dynamic sidebar that adheres to the content and is placed alongside it using JavaScript

I am in need of creating a sticky sidebar that will float beside my content column. The purpose of this sidebar is to contain jump links on the page, similar to what can be seen on this page, but with the navigation buttons positioned directly next to the ...

Maximizing Reusability: Implementing Redux Toolkit Reducers with TypeScript

Below is an example of a slice that I have: const authSlice = createSlice({ name: "auth", initialState: { ...initialUserInfo, ...initialBasicAsyncState, }, reducers: { setUser: (state, { payload }: PayloadAction<{ userObj: ...

How can I retrieve the most recent date from a collection of hashes and then extract the corresponding name key/value pair?

I am dealing with an array of hashes structured like this: [ { "Address": 25, "AlertType": 1, "Area": "North", "MeasureDate": "2019-02-01T00:01:01.001Z", "MeasureValue": -1 }, { "Address": 26, "AlertType": 1, "Area": "West", "MeasureDa ...

What is the best way to send a string without using quotation marks as a parameter in a function?

If I have an API that takes the query as http://localhost:8000/api/v1/rental/?place__startswith=kathmandu, how can I implement a generic search in ReactJS? What I attempted to do is pass the default parameter as search(query=kathmandu) so that the result ...

Error message indicating that the host has been configured in both the settings() and useEmulator() functions for the Firebase Firestore emulator, therefore the emulator host will

Initially, I encountered the complete error message. @firebase/firestore: Firestore (8.1.1): Host has been set in both settings() and useEmulator(), emulator host will be used Error [FirebaseError]: Firestore has already been started and its settings c ...

Visualizing Data with d3.js Radar Charts Featuring Image Labels

After following a tutorial on creating a d3.js radar chart from http://bl.ocks.org/nbremer/21746a9668ffdf6d8242, I attempted to customize it by adding images to the labels. However, I encountered an issue with aligning the images properly. You can view my ...

How to eliminate space between two rectangles using CSS

I have created a menu item using jquery and CSS, but there seems to be a gap in the menu items. One item is placed on top of the other. I want to remove this gap and gradually push each element to the right as shown in the image. How can I achieve this? H ...

What significance do the variations of `p-N` hold within Bootstrap v4?

The naming convention used in Bootstrap v4 seems a bit cryptic to me. While I understand the desire to keep classes minimal and clean, I am struggling to make sense of it. I can make educated guesses, but I'm unable to find definitive answers. p-1, ...

The element 'Component' cannot be utilized as a JSX component since its type 'ReactElement<any, any> | Component<{}, any, any>' is not a valid JSX element

I'm currently facing an issue while running "yarn build" and/or "npm run build" on a repository. The error persists for both commands. My goal is to build and deploy this code to an AWS environment, but I am stuck at resolving the errors that indicate ...

The modifications made to the input type="time" in View do not get updated in the Model within Angular

I have been attempting to validate the input type "time", but I am encountering an issue where changes in the view are not reflected in the model if any of the input fields are left empty. For example: https://i.sstatic.net/1U0sO.png When a user change ...

Tips for handling an empty jQuery selection

Below is the code snippet: PHP CODE: if($data2_array[7]['status'] == "OK"){ $degtorad = 0.01745329; $radtodeg = 57.29577951; $dlong = ($lng - $supermercado_lng); $dvalue = (sin($lat * $degtorad) * sin($superm ...

Utilize JavaScript to compel image caching

I've run into an issue where I am trying to duplicate a randomly generated image, but despite using the same URL, a different image is being loaded every time. This problem has been confirmed in both Chrome and Firefox browsers. Unfortunately, since ...

Checkboxes display on a separate line when rendered inlines

I'm having an issue with the rendering of my checkbox in CSS. The checkbox is currently displaying on a separate line from the text, but I would like it to be inline with the rest of the content. For reference, here is the full CSS and HTML code: htt ...

Triggering a prop event handler results in the React state being reset

I'm struggling to understand what's happening here. When the "Click me" button is clicked, the number increments as expected. However, when the click is triggered by the Child component, it resets the state and always prints 0. function Child(pr ...

Is it possible to view a live stream from a Raspberry Pi Camera Module on a web browser using NodeJS?

I have been working on creating a time-lapse camera web application using Raspberry Pi and the Camera Module. The current version of my web app, developed with NodeJS, Express, AngularJS, and Bootstrap 3, allows me to control the Camera Module features t ...

Assistance with TextField in Reactjs

I'm trying to figure out how to seamlessly sync error validation and character limit without disrupting its existing functionality. Please take a look at this link const [formError, setFormError] = useState(false); const CHARACTER_LIMIT = 1000; ...