What could be causing the tabs to disappear from the Material UI tab component in my React project?

What am I currently working on?

  • I am in the process of developing a horizontally scrollable tab component to select dates within a month
  • For this project, I have decided to utilize the Material UI library

Issues Encountered

  • The dates before the 14th Sunday are not displaying on the site (as indicated in the image below)
  • The initial tab should showcase the first day of the month but instead shows the 14th Sunday
  • While inspecting the browser elements tab, all tabs are present but they do not appear on the screen

Mobile Viewport (Unable to Scroll Before the 14th)

https://i.stack.imgur.com/zVeYh.png

Desktops Viewport (No Scrolling Allowed Before the 7th)

https://i.stack.imgur.com/LCPYk.png

Elements tab

https://i.stack.imgur.com/JAmEM.png

Highlighted code snippet presumed to be causing the issue:

export default function DayScrollView() {
  const [activeDate, setActiveDate] = useContext(dateContext)
  const [dates, setDates] = useState(getDatesInMonth(activeDate))
  return (
    <Box sx={
      {
        overflowX: 'scroll',
        scrollbarWidth: 'none',
        '-ms-overflow-style': 'none',
        '&::-webkit-scrollbar': {
          display: 'none',
        },
      }
    }>
      <Tabs defaultValue={0}>
        <StyledTabsList>
          {dates.map((date, index) => {
            console.log(`${date.getDate()} ${date.toLocaleString('default', { weekday: 'short' })}`)
            return (
              <StyledTab key={date.toDateString()} value={date.toDateString()} onClick={() => setActiveDate(date)}>
                <Typography variant='subtitle1'>{date.toLocaleString('default', { weekday: 'short' })}</Typography>
                <Typography variant='h5'>{date.getDate()}</Typography>
              </StyledTab>
            )
          })}
        </StyledTabsList>
      </Tabs>
      <Box mr={10} sx={{ width: 20 }} />
    </Box>
  );
}

Complete Component Code

import { useContext, useState } from 'react';
import * as React from 'react';
import { styled } from '@mui/system';
import Tabs from '@mui/base/Tabs';
import TabsList from '@mui/base/TabsList';
import TabPanel from '@mui/base/TabPanel';
import { buttonClasses } from '@mui/base/Button';
import Tab, { tabClasses } from '@mui/base/Tab';
import { Box, Typography } from '@mui/material';
import getDatesInMonth from '@/utils/getDatesInMonth';
import { dateContext } from '@/pages/mob';

export default function DayScrollView() {
  const [activeDate, setActiveDate] = useContext(dateContext)
  const [dates, setDates] = useState(getDatesInMonth(activeDate))
  return (
    <Box sx={
      {
        overflowX: 'scroll',
        scrollbarWidth: 'none',
        '-ms-overflow-style': 'none',
        '&::-webkit-scrollbar': {
          display: 'none',
        },
      }
    }>
      <Tabs defaultValue={0}>
        <StyledTabsList>
          {dates.map((date, index) => {
            console.log(date)
            return (
              <StyledTab key={index} value={index} onClick={() => setActiveDate(date)}>
                <Typography variant='subtitle1'>{date.toLocaleString('default', { weekday: 'short' })}</Typography>
                <Typography variant='h5'>{date.getDate()}</Typography>
              </StyledTab>
            )
          })}
        </StyledTabsList>
      </Tabs>
      <Box mr={10} sx={{ width: 20 }} />
    </Box>
  );
}

const StyledTab = styled(Tab)`
.... some css styles
`;

const StyledTabPanel = styled(TabPanel)(
  ({ theme }) => `
  width: 100%;
  ... more styles
  `,
);

const StyledTabsList = styled(TabsList)(
  ({ theme }) => `
  padding-right: 1rem;
  background: transparent;
  display: flex;
  flex-grow: 1;
  align-items: center;
  justify-content: center;
  align-content: space-between;
`,
);

getDatesInMonth()

function getDatesInMonth(date) {
    const year = date.getFullYear();
    const month = date.getMonth();
    const numDays = new Date(year, month + 1, 0).getDate();
    const dates = [];
    for (let i = 1; i <= numDays; i++) {
        dates.push(new Date(year, month, i));
    }
    return dates;
}
  • If further information is required, please leave a comment.
  • If you found this helpful, consider upvoting and sharing the question with others who may be able to assist.

Answer №1

This particular problem stems from a css flex-box issue.

Below is the suggested solution:

const StyledTabsList = styled(TabsList)(
  ({ theme }) => `
  padding-right: 1rem;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  align-content: center;
  `,
);

Modification made:

  • Switched from using justify-content: center to justify-content: flex-start;

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

Following a POST request, the redirection functionality in Next.js seems to be malfunctioning

I am facing an issue with redirecting the user after submitting a form. I have a button that triggers a post request to my API route, which then inserts a row in the database. The goal is to redirect the user to / once everything is done. However, the retu ...

Enhancing functionality by integrating Jquery/JS with input fields and labels

I am currently facing a challenge in applying CSS to the label element when the corresponding input is selected. After attempting and failing to use input:checked + label due to limitations in the HTML structure that cannot be altered, I seek alternative ...

What steps can be taken to prevent a child component from re-rendering when the parent updates the context or state in React JS?

How can I prevent a child component from re-rendering when the parent updates the context or state in React JS? I have already implemented React.memo, but the component still re-renders. Below is my child component: const Ab = () => { console.log(&q ...

Tips for determining if a React app is being accessed in a web browser or on a mobile device

I am working with a react web application and an IOS app (web view). I am looking to incorporate some additional features into the IOS app. Is there a method available to identify whether the app is being accessed through a web browser or on a mobile dev ...

Incorporating a transparent icon onto an HTML background

I'm struggling to place a transparent white envelope icon on a green background. I don't understand why it's not working, especially when the telephone icon worked fine. Side Question.: Any recommendations for how to add something above the ...

"Stuck in a Standstill: Express/React Commit

Currently, I have set up an Express backend server on port 5000 along with a React frontend running on port 3000. My goal is to fetch some data from an Express post route and return it to the frontend, however, I am encountering an issue where my Promise n ...

transferring a function from a main component to a nested component using swipeout functionality in react-native

I am attempting to transfer a function from a parent container to a child container within react native. The user is presented with a list of items on the screen, where they can swipe the list to reveal additional options. Child import React from &ap ...

Strategies for avoiding overflow-x issues in Safari and mobile devices

I am currently facing an issue where I have a div containing a table with overflow enabled, allowing the whole table to be viewed by scrolling. However, on Safari and mobile Safari browsers, there is a horizontal scroll on the html and body elements. Whil ...

Could you tell me the kind of theme used in Material-UI version 5?

I've decided to switch my project over to MUI version 5 and embrace the use of emotion CSS. It's come to my attention that I need to incorporate the theme property, but now TypeScript is prompting me for a type definition for it. The current code ...

What is the best way to ensure all my borders are uniform in size?

As I work on a JavaScript project that organizes words into blocks based on their size, I encountered an issue with inconsistent border thickness in certain areas. I'm using spans to contain each word, but I can't figure out how to make the borde ...

Start a new redux-saga process when the user logs in and logs out

Currently diving into the world of Redux-Saga and facing a challenge in understanding how to properly connect users to a chat service (specifically Chatkit by Pusher) upon login and disconnect them on logout. At this point, I have an "auth" saga that wait ...

Format the MUI TextField input to display both numbers and decimals

Trying to customize the input value of this MUI component, aiming to display a maximum of 3 numbers followed by up to 2 decimals separated by a dot, such as 233.99. The intention is to save this formatted value in a react state called 'value' (co ...

Is there a way to insert a colored square into a <button> tag rather than text?

Looking for help with the following HTML: <button name="darkBlue" onclick="setThemeColor(this.name)">Blue</button> <button name="black" onclick="setThemeColor(this.name)">Black</button> I'm interested in replacing the text on ...

Arranging fixed-width <div>s in rows of four for a sequential display

Below is the code that I am working with: <div style="margin: 0 auto; display:block; width: 916px; overflow: auto;"> <?php echo ""; echo "<i>Owned: $line->phone </i><br><br>"; $query ...

Uniformly arranging text and an icon in a snackbar

Being completely new to this (to the point that this is my first ever task), I'm attempting to format an icon and some text in a snackbar so that they are evenly spaced and properly aligned. <SnackbarContent message={ <div& ...

Utilizing Reactjs to efficiently transmit name and value to Material UI autocomplete

I am trying to customize the Material UI Autocomplete component. I need to pass name, value and onchange similarly to how it is done for TextField. Can someone please help me achieve this? My current code is not functioning as expected. < ...

What are the steps to integrate Material UI into the Electron React Boilerplate?

Background I am a new user to Electron and recently cloned and installed the recommended React + Electron repository from here: https://github.com/electron-react-boilerplate/electron-react-boilerplate Now, I am trying to integrate Material-UI into my pro ...

CSS: Fixed item at the bottom of a container that scrolls horizontally

I am working on creating a sticky footer within a horizontally scrolling element. I want the sticky footer to be positioned at the bottom, adjust its height based on the content inside it, and match the width of the scrollable parent (in this case 200px). ...

Why does my Div seem to be ignoring the height inherited from the html or body elements?

Is there a way to make the landing-wrapper div expand to fill 100% of the screen on a landing page? Many suggestions advise setting the html/body height to 100%. I've already tried that, but it doesn't seem to be working. I'm using React and ...

The slider causing conflicts with widgets and content positioned below it in an HTML layout

When implementing a slider with a fade effect, there seems to be an issue with the placement of widgets on the homepage. The problem arises from the margin-top setting as when images change in the slider, the widgets clash with the slider. During the trans ...