MaterialUI Divider is designed to dynamically adjust based on the screen size. It appears horizontally on small screens and vertically on

I am currently using a MaterialUI divider that is set to be vertical on md and large screens. However, I want it to switch to being horizontal on xs and sm screens:

<Divider orientation="vertical" variant="middle" flexItem />

I have attempted the following:

const theme = useTheme();
const isSmallScreen = useMediaQuery(theme.breakpoints.down('xs'));

<Divider orientation={isSmallScreen ? 'horizontal' : 'vertical'} variant='middle' flexItem />

I also tried enclosing it in a Grid.

However, the divider does not seem to appear on xs and sm screens.

This is the complete JSX section:

<Card>
      <Grid2 container spacing={4} sx={{ minWidth: { xs: '100%', md: '715px' } }}>
        <Grid2 xs={12} md={4}>
          {booking_items.map(item => (
            <React.Fragment key={`${id}-${item.title}`}>
              <Typography variant='subtitle2'>{item.title}</Typography>
              <CardMedia component='img' image={item.imageUrl} title={item.title} />
            </React.Fragment>
          ))}
        </Grid2>
        <Divider orientation={isSmallScreen ? 'horizontal' : 'vertical'} variant='middle' flexItem /> 

        <Grid2 xs={12} md={8}>
          <CardContent>
            <Stack direction='row' spacing={1}>
              <CalendarBlankIcon sx={iconStyle} />
              <Typography variant='body1'>
                {formatDate(start_date)} - {formatDate(end_date).split(' at ')[1]}
              </Typography>
            </Stack>
            <Stack direction='row' spacing={1}>
              <UserAltIcon sx={iconStyle} />
              <Typography variant='body1'>{people} people</Typography>
            </Stack>
            <Stack direction='row' spacing={1}>
              <MapMarkerIcon sx={iconStyle} />
              <Typography variant='body1'>{address}</Typography>
            </Stack>

            <Box sx={{ display: 'flex', justifyContent: 'flex-end', mt: '25px' }}>
              <Button variant='text' color='secondary' endIcon={<ChevronRightIcon />}>
                View Booking
              </Button>
            </Box>
          </CardContent>
        </Grid2>
      </Grid2>
    </Card>

Has anyone encountered this issue before?

Answer №1

The term "xs" essentially represents a value of 0px. Therefore, the condition isSmallScreen will only be true if your screen size somehow has negative values.

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

How can I pass props from a page to components in Next.js using getServerSideProps?

Struggling to fetch the coingecko-api for accessing live bitcoin prices. Trying to pass return props of getServerSideProps to my <CalculatorBuy /> component within the <Main /> component. Facing issues when importing async function in calcula ...

Show a variety of pictures using React

Is it possible to repeat an image (e.g. photo.jpg) n times in Reactjs using a provided value for n in props? If yes, how can this be achieved? function Card(props) { for (let i = 0; i < props.rating; i++) { <img className="star" src ...

Combining files/namespaces/modules in Typescript: How to do it?

Even though I believe the solution may be simple, understanding how to merge enums across multiple files is eluding me when reading through the documentation. // a.ts enum Color{ RED, BLUE } // b.ts enum Day{ MONDAY, TUESDAY } // c ...

Modify the data in a set of text boxes

I have a component that consists of a form: import React from 'react' import Relay from 'react-relay' import { browserHistory } from 'react-router' import MenuItem from 'material-ui/MenuItem' import TextField from ...

When you try to iterate over the Array Object in React, no output is displayed

When working in React, I encountered an issue where the values of userQuizes array object were not printed and appeared blank. Here is the Array-Object: View the array containing only one object that needs to be iterated Below is the code snippet causing ...

Tips on incorporating a callback function within the setState function

I've encountered a problem with my click handler. Initially, it was working fine like this: handleClick = () => { const { isCalendarOpen } = this.state; this.setState ({ isCalendarOpen: !isCalendarOpen }); ...

Using this.setState in ReactJS removes filters

Hey everyone, I've been struggling with a technical issue for the past few days and would really appreciate any hints or solutions. The problem lies in creating a table using the material-table library. Specifically, I need to extract the docID and do ...

Sharing user input between files in Reactjs

I am facing an issue with reusing the email input on different pages after login, such as on absent and news pages. How can I retrieve the user-entered email from the login page and display it on other pages? In my Login.jsx file, I have the following fu ...

Unable to transfer the properties of reactjs to react-chartist

How can I pass the state from the parent component "main.js" into the child component "bar.js"? //main.js import React, { Component } from 'react'; import BarChart from './Bar-chart'; class Hero extends Component { cons ...

Unable to make changes to MuiTypography-root

Currently, I am facing a challenge while modifying the child of MuiTypography. I specifically need to remove the line-height from muitypography-root, but it should only be applicable to this particular section. See below for the jsx code snippet and an ima ...

When directly called from index.js, Next.js getStaticProps and getInitialProps return undefined for a component

I've been following this tutorial: https://nextjs.org/learn/basics/data-fetching/implement-getstaticprops, but I decided to create a new component instead of adding the code directly to the index.js file. Although the tutorial's method works fin ...

What could be causing the react route to malfunction in Next.js?

The following is the content found in pages/index.js: import { BrowserRouter as Router,History, Switch, Route } from 'react-router-dom'; import TestSocket from '../components/testSocket/TestSocket'; export default function Index(){ ...

Error arises when attempting to pass interface props to a component in a React Typescript application

I am currently delving into the world of React js and typescript. As part of my learning process, I have created a demo application that allows users to input their name and age. The app features an ErrorModal that should pop up on the screen whenever inco ...

Comparing dates in Angular 6 can be done by using a simple

Just starting with angular 6, I have a task of comparing two date inputs and finding the greatest one. input 1 : 2018-12-29T00:00:00 input 2 : Mon Dec 31 2018 00:00:00 GMT+0530 (India Standard Time) The input 1 is retrieved from MSSQL database and the in ...

The issue with Elastic UI in NextJS is that it does not recognize the Window as defined

Struggling to integrate a button component from the Elastic UI library into my code. Every time I try to add the button, I encounter a window is not defined error. The API call and other functionalities work smoothly until I introduce the button component ...

Autocomplete feature in Material UI with an embedded datepicker is failing to display as expected

I've been attempting to integrate a datetime picker into the Material-UI autocomplete paper. I tried using the MUI datepicker and even attempted to forcefully open it, but without success. The native option seems to function partially, but requires ad ...

"Discovering the method to showcase a list of camera roll image file names in a React Native

When attempting to display a list of images from the user's camera roll, I utilized expo-media-library to fetch assets using MediaLibrary.getAssetsAsync(). Initially, I aimed to showcase a list of filenames as the datasource for the images. Below is m ...

Removing scrollbar from table in React using Material UI

I successfully created a basic table using react and material UI by following the instructions found at: https://material-ui.com/components/tables/#table. The table is functioning properly, but I am finding the scrollbar to be a bit inconvenient. https:// ...

Upgrading from Material UI Version 0.20 to v4.3.0: The Ultimate Transformation

I have been working on an application that was built using an older version of material UI (V0.20). Now, I am considering upgrading to the latest version of material UI and adding new modules to the application. However, I am concerned about the potentia ...

A class in Typescript containing static methods that adhere to an interface with a string index

Take a look at this code snippet: interface StringDoers { [key: string]: (s: string) => void; } class MyStringDoers implements StringDoers { public static print(s: string) { console.log(s); } public static printTwice(s: string) { conso ...