skip to Main Content

Here is the sample layout that working on having a scroll bar vertically
enter image description here

My concern is, how will I remove it ? take note that before asking questions here, I have already research regarding how to hide scroll bar and just show it when I do have many items already, unfortunately, none of those works.

This happens when I added the style flex-grow min-h-screen in my home page, but I needed to add it because my layout will look like this if I don’t add it, you will see there that the bottom bar is not at the bottom of the screen
enter image description here

Will provide the code below

main.tsx:

import "@fontsource/roboto/300.css";
import "@fontsource/roboto/400.css";
import "@fontsource/roboto/500.css";
import "@fontsource/roboto/700.css";

import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App.tsx";
import { BrowserRouter } from "react-router-dom";

createRoot(document.getElementById("root")!).render(
  <StrictMode>
    <BrowserRouter>
      <App />
    </BrowserRouter>
  </StrictMode>
);

app.tsx:

import { Route, Routes } from "react-router-dom";

import RootLayout from "./layouts/root/RootLayout";
import Home from "./layouts/root/Home";

import "./globals.css";

function App() {
  return (
    <main>
      <Routes>
        <Route element={<RootLayout />}>
          <Route index element={<Home />} />
        </Route>
      </Routes>
    </main>
  );
}

export default App;

Rootlayout.tsx:

import { Outlet } from "react-router-dom";
import Bottombar from "../../components/shared/Bottombar";
import Topbar from "../../components/shared/Topbar";

const RootLayout = () => {
  return (
    <>
      <div className="flex flex-col flex-1">
        <Topbar />
        <Outlet />
      </div>
      <Bottombar />
    </>
  );
};

export default RootLayout;

Topbar.tsx:

import NotificationsIcon from "@mui/icons-material/Notifications";

import { Badge } from "@mui/material";
import AccountMenu from "../../components/shared/AccountMenu";

const Topbar = () => {
  return (
    <div className="ob-bg-color">
      <div className="flex flex-1 justify-between items-center p-6">
        <AccountMenu />

        <img src="" alt="logo" />

        <Badge badgeContent={1} color="primary">
          <NotificationsIcon color="action" />
        </Badge>
      </div>
    </div>
  );
};

export default Topbar;

Home.tsx:

import * as React from "react";
import Tabs from "@mui/material/Tabs";
import Tab from "@mui/material/Tab";
import Box from "@mui/material/Box";
import { Card } from "@mui/material";

interface TabPanelProps {
  children?: React.ReactNode;
  index: number;
  value: number;
}

function CustomTabPanel(props: TabPanelProps) {
  const { children, value, index, ...other } = props;

  return (
    <div
      role="tabpanel"
      hidden={value !== index}
      id={`simple-tabpanel-${index}`}
      aria-labelledby={`simple-tab-${index}`}
      {...other}
    >
      {value === index && (
        <Box
          sx={{
            p: 3,
            display: "flex",
            justifyContent: "center",
            alignItems: "center",
            height: "100%",
          }}
        >
          {children}
        </Box>
      )}
    </div>
  );
}

function a11yProps(index: number) {
  return {
    id: `simple-tab-${index}`,
    "aria-controls": `simple-tabpanel-${index}`,
  };
}

export default function Home() {
  const [value, setValue] = React.useState(0);

  const handleChange = (event: React.SyntheticEvent, newValue: number) => {
    setValue(newValue);
  };

  return (
    <Card className="rounded-t-3xl bg-blu flex flex-col flex-grow min-h-screen">
      <Box sx={{ width: "100%", alignItems: "center" }}>
        <Box>
          <Tabs
            value={value}
            onChange={handleChange}
            aria-label="Wishlist tabs"
            textColor="inherit"
            centered
            TabIndicatorProps={{
              style: {
                backgroundColor: "black",
              },
            }}
          >
            <Tab
              label="Active"
              className="normal-case mr-10"
              {...a11yProps(0)}
            />
            <Tab label="History" className="normal-case" {...a11yProps(1)} />
          </Tabs>
        </Box>

        {/* Make the content area take remaining space and scroll if needed */}
        <Box className="">
          <CustomTabPanel value={value} index={0}></CustomTabPanel>
          <CustomTabPanel value={value} index={1}></CustomTabPanel>
        </Box>
      </Box>
    </Card>
  );
}

Bottombar.tsx:

import Badge from "@mui/material/Badge";
import AddIcon from "../../assets/icons/add-icon.svg";
import MyWishList from "../../assets/icons/my-wishlist-container.svg";
import FriendsIcon from "@mui/icons-material/Diversity1";
import { NavLink } from "react-router-dom";
import { useState } from "react";

const Bottombar = () => {
  const [active, setActive] = useState({
    home: true,
    addItem: false,
    friends: false,
  });

  const handleActive = (key: string) => {
    setActive((prevState) => ({
      ...prevState,
      home: key === "home",
      addItem: key === "addItem",
      friends: key === "friends",
    }));
  };

  return (
    <>
      <div className=" flex justify-between items-center w-full sticky bottom-0  bg-red-600 z-50">
        <NavLink to="/" onClick={() => handleActive("home")}>
          <div className="flex flex-col items-center  p-5">
            <img
              src={MyWishList}
              alt="my wishlist"
              className="cursor-pointer"
            />
            <p
              className={`text-[14px] leading-[140%] ${
                active.home ? "font-bold" : "font-normal"
              }`}
            >
              My Wishlist
            </p>
          </div>
        </NavLink>

        <NavLink to="/add-item" onClick={() => handleActive("addItem")}>
          <div className="flex flex-col items-center ">
            <img
              src={AddIcon}
              alt="my wishlist"
              className="relative -top-5 right-4"
            />
            <p
              className={`text-[14px]  leading-[140%] relative -top-5 right-4 ${
                active.addItem ? "font-bold" : "font-normal"
              }`}
            >
              Add Item
            </p>
          </div>
        </NavLink>

        <NavLink to="/friends" onClick={() => handleActive("friends")}>
          <div className="flex flex-col items-center p-4">
            <Badge badgeContent={3} color="error">
              <FriendsIcon color="action" />
            </Badge>
            <p
              className={`text-[14px] leading-[140%] ${
                active.friends ? "font-bold" : "font-normal"
              } `}
            >
              Friends
            </p>
          </div>
        </NavLink>
      </div>
    </>
  );
};

export default Bottombar;

globals.css:

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer utilities {
    /* UTILITIES */
    

 .flex-center {
    @apply flex justify-center items-center;
 }

 .facebook {
    background: #415DAE;
 }

 .google { 
    background: #FFFFFF;
 }

 .google-button {
    border: 1px solid #DADADA
 }

 .ob-bg-color {
    background: #91EA9F
 }

 .headers {
    font-family: 'Nohemi', sans-serif;
    font-size: 22px;
    font-weight: 700;
    line-height: 28px;
    color: #193028;
 }

 .primary {
    background: #B2B4FA;
 }

 .share-button {
   background: #1930280D;
 }
}

2

Answers


  1. If you want to hide scrollbars for the entire beside try the below code or else attach the css properties to that specific container or class:

    html {
        overflow: -moz-scrollbars-none; 
        scrollbar-width: none;
    }
    
    body {
        overflow: auto;
    }
    
    
    body::-webkit-scrollbar {
        display: none;
    }
    
    Login or Signup to reply.
  2. You simply need to change the positioning of your Bottombar from sticky to fixed.

    The reason for this is that sticky positioning is used in scrollable elements where you want to make an element "stick" at a position rather than be scrolled out of view. As you have it now, when there isn’t a lot of content, main isn’t tall enough to be scrolled and thus doesn’t "stick". When you set the Card to min-h-screen, main stretches beyond the screen height and thus your Bottombar could now stick to the position set (bottom:0) and appear to be working.
    Fixed positioning however will position your element relative to the viewport so it is always consistently at the bottom.

    Doing this, you also don’t need to set the Card element in the Home component to min-h-screen anymore. This was causing the scroll bar because your Home component being 100vh plus the Topbar (or any other element) made main greater than the viewport. If you want, you can set the container of Topbar and Outlet to h-screen so it is always the height of the viewport, and its contents won’t make it overflow. If you want to make the Topbar stay in view even when the content is greater than the viewport, than consider making it fixed too.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search