The ListItemText Component utilizes the default padding property known as "inset"

I'm currently working on styling a nested list within a React application using material-ui. The default padding for the "inset" property is set to 56px, which I find too large. I have been attempting to override this default value without success. Does anyone have any suggestions or solutions? Thank you in advance!

     <Fragment>
        <ListItem button onClick={this.handleClick}>
          <ListItemText
            primary="Zones"            
            primaryTypographyProps={{ variant: 'subtitle2' }}
        />
          {this.state.open ? <ExpandLess /> : <ExpandMore />}
        </ListItem>
        <Collapse in={this.state.open} timeout="auto" unmountOnExit>
          <List component="div" disablePadding>
            <ListItem button             
              component={Link}
              to={`${this.props.match.url}/zone/all-zones`}
              onClick={THIS.handleMenuOpen}
            >
              <ListItemText
                inset                
                primary="Show all"
                primaryTypographyProps={{ variant: 'subtitle2' }}
              />
            </ListItem>
          </List>
        </Collapse>
      </Fragment>

Answer №1

The main function of the inset attribute on ListItemText is to align text for items with and without icons (refer to the Inset List demo). This attribute is not intended for indenting nested list items.

If you examine the Nested List demo, you'll notice that the indentation is achieved through the use of paddingLeft on the nested list items. In the demo, this value is set at 32px (theme.spacing(4)), but you have the flexibility to adjust it as needed.

Below is the link to access the source code from the Nested List demo:

import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import ListSubheader from "@material-ui/core/ListSubheader";
import List from "@material-ui/core/List";
import ListItem from "@material-ui/core/ListItem";
import ListItemIcon from "@material-ui/core/ListItemIcon";
import ListItemText from "@material-ui/core/ListItemText";
import Collapse from "@material-ui/core/Collapse";
import InboxIcon from "@material-ui/icons/MoveToInbox";
import DraftsIcon from "@material-ui/icons/Drafts";
import SendIcon from "@material-ui/icons/Send";
import ExpandLess from "@material-ui/icons/ExpandLess";
import ExpandMore from "@material-ui/icons/ExpandMore";
import StarBorder from "@material-ui/icons/StarBorder";

const useStyles = makeStyles(theme => ({
  root: {
    width: "100%",
    maxWidth: 360,
    backgroundColor: theme.palette.background.paper
  },
  nested: {
    paddingLeft: theme.spacing(4)
  }
}));

export default function NestedList() {
  const classes = useStyles();
  const [open, setOpen] = React.useState(true);

  const handleClick = () => {
    setOpen(!open);
  };

  return (
    <List
      component="nav"
      aria-labelledby="nested-list-subheader"
      subheader={
        <ListSubheader component="div" id="nested-list-subheader">
          Nested List Items
        </ListSubheader>
      }
      className={classes.root}
    >
      <ListItem button>
        <ListItemIcon>
          <SendIcon />
        </ListItemIcon>
        <ListItemText primary="Sent mail" />
      </ListItem>
      <ListItem button>
        <ListItemIcon>
          <DraftsIcon />
        </ListItemIcon>
        <ListItemText primary="Drafts" />
      </ListItem>
      <ListItem button onClick={handleClick}>
        <ListItemIcon>
          <InboxIcon />
        </ListItemIcon>
        <ListItemText primary="Inbox" />
        {open ? <ExpandLess /> : <ExpandMore />}
      </ListItem>
      <Collapse in={open} timeout="auto" unmountOnExit>
        <List component="div" disablePadding>
          <ListItem button className={classes.nested}>
            <ListItemIcon>
              <StarBorder />
            </ListItemIcon>
            <ListItemText primary="Starred" />
          </ListItem>
        </List>
      </Collapse>
    </List>
  );
}

Answer №2

Menu-Group

        <List component="nav" aria-label="group-menu">
            <ListItem>
                <ListItemText
                    primary="members"
                    primaryTypographyProps={{variant:'button' }}
                />
            </ListItem>
            <MemberMenu />
            <Divider />
            <ListItem>
                <ListItemText
                    primary="event schedules"
                    primaryTypographyProps={{ variant: 'button' }}
                />
            </ListItem>
            <EventScheduleMenu />
        </List>


 Person-Menu
      <Fragment>
        <List component="div" disablePadding>
          <ListItem button
            component={Link}
            to={`${this.props.match.url}/person/all_persons`}
            onClick={this.handleOnClick};              
          >
            <ListItemText 
              className='nested'
              style={{paddingLeft: 20 }}                      
              primary="Show all persons" 
              primaryTypographyProps={{variant:'subtitle2'}}
            />
          </ListItem>
        </List>
      </Fragment>

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

What is the reason for having both the Video.js npm module and the <script> tag in place?

After referring to the official Video.js documentation at , it is recommended to add script tags for both js and css to your webpage. Additionally, you can install the package manager through npm or bower. What is the purpose of utilizing both approaches? ...

When attempting to implement styled-components in Next.js, there is an issue with the node module in React.js causing an error

I am trying to incorporate styled-components in my next.js react project. This is the approach I am taking: import styled from 'styled-components'; export const MainTitleContainer = styled.div` text-align:right; margin:3rem 0; paddin ...

Is there a way to retrieve a particular object from the state and access one of its elements?

I have a component called Tweets.js: import React, {Component} from "react"; export default class Tweets extends Component { constructor(props) { super(props); this.state = {tweets: [], users: []}; } componentDi ...

Issue encountered while executing the build command using npm run in a ReactJS project

Encountering an error when running "craco build" The command being executed is: npm run dist When I try to run npm run build from the same folder, I face the same error. Here are the commands in the package.json file: "scripts": { "start": "npm ru ...

Inject a function into the headerTitle component of React Navigation

I'm having trouble implementing a deletePost button in my header component. Here's the issue: export class PostScreen extends Component { // Custom headerTitle component. static navigationOptions = ({ navigation }) => { const { par ...

When trying to implement formik-material-ui for material-ui styling, validation needs to happen before onSubmit

Looking to incorporate material-ui into my formik app by utilizing the formik-material-ui library. However, I am facing an issue where validation is triggering before submission when using material-ui textfield components within the fields. I suspect it ma ...

The render props on the child component are not appearing on the screen as expected

Recently diving into React Native, I created a stateless component designed to iterate through props that contain objects with arrays of tags. The goal was to extract and display a single tag from each array item. (Refer to the console log in the screensh ...

Tips for enhancing a TypeScript interface for a React component in (Material-UI) by utilizing styled-components

I've been struggling to find a solution for this overload issue with no luck so far. My stack includes Typescript, Styled-components, and Material-UI. I am utilizing styled(MUIButton) to extend the default Button from MUI. While my props are being pas ...

What are some creative ways to incorporate images into websites outside of a ReactJS environment?

I'm currently working on a ReactJS application that is client-side only and intended for local use. One of the requirements is to save and load images using filepaths, including URLs and local file system paths. While I am able to store paths in loca ...

Steps to eliminate pre-chosen alternatives upon loading select control?

When using react-select with pre-selected options and multiple select enabled, the issue arises where clicking on the Select box still displays the already pre-selected options. How can I remove these duplicate options from the list? Below is a snippet of ...

Encountering an error when attempting to assign a value within the onChange callback of a React dropdown component

I have implemented a Dropdown component using react-dropdown to show a list of options. I am facing an issue where, upon selecting an option from the list for the first time, the value changes successfully. However, upon selecting a second option, it thr ...

Modify the class name of the clicked button and another button when a button is clicked in ReactJs

I have a React component that displays two buttons. When the user clicks on the left button, it should change the class of both buttons and render the ListView component. Similarly, when the user clicks on the right button, it should change the class of bo ...

Exploring tabs functionality with Material UI, Jest, and Enzyme testing

I am currently testing a component with tabs. My initial test is to verify the correct initial state, followed by testing whether clicking on another tab changes the state. The technologies I am using for this are material-ui, jest, and enzyme. import Rea ...

Is there a way to identify and count duplicate data-items within an array, and then showcase this information using a react view?

If we have an array like this: [{id: 1, name: "chocolate bar"}, {id:2, name: "Gummy worms"}, {id:3, name:"chocolate bar"}] Is there a way to show on the dom that we have "2 chocolate bars and 1 Gummy Worms"? ...

Step-by-Step Guide on Resetting Versions in Package.json

I currently have around 20 react projects, each with their own package.json files. These package.json files contain various packages and their versions: "@material-ui/core": "4.11.4", "@material-ui/icons": "4.11.2", ...

Attempting to use a string as an index for the type `{ firstName: { inputWarning: string; inputRegex: RegExp; }` is not allowed

const checkRegexSignUp = { firstName: { inputWarning: "only letters", inputRegex: /^[a-z ,.'-]+$/i }, lastName: { inputWarning: "only letters", inputRegex: /^[a-z ,.'-]+$/i }, } const change = (e: ChangeEvent<HT ...

Customize MUI Tabs to resemble the design of Bootstrap Nav Tabs

Looking to customize Material UI Tabs to resemble Bootstrap Tabs. Made significant changes, but struggling with removing the border-bottom on the activeTab. In Bootstrap, they use marginBottom: -1px on the active tab, but it doesn't work for me. Any s ...

Using the updated state value in a React Axios request for dynamic URL usage

I'm looking to make an axios request, but I need a state update with geolocation value beforehand. I attempted the following: const Home = () => { const [latitude, setLatitude] = useState(); const [longitude, setLongitude] = useState(); f ...

Clue model cannot be overwritten once compiled due to an OverwriteModelError in Mongoose for NextJS

Currently, I am in the process of developing a straightforward web application using NextJS and am aiming to integrate Mongoose for handling my database operations. The error that is plaguing me can be seen at this link: https://i.stack.imgur.com/OA1JD.pn ...

What methods can be used to transfer data from mapped objects to their parent component in React?

I'm in the midst of creating a cutting-edge shopping cart application. Each item is beautifully displayed as a card component within the app. To achieve this, I've utilized mapping with dummy object data: const Home = () => { const dumm ...