默认的“插入”属性填充。 ListItemText组件

时间:2019-10-17 18:41:08

标签: reactjs material-ui

我正在使用material-ui在React应用程序中设计嵌套列表的样式。默认的“插入”属性填充为大(56px),因此我尝试覆盖该默认值。但是我不能。 有什么建议么?谢谢!!

Overlay

2 个答案:

答案 0 :(得分:0)

ListItemTextinset prop的目的是使没有图标的项目的文本与有图标的项目的文本对齐(请参阅Inset List demo)。缩进嵌套列表项

如果查看Nested List demo,您会发现缩进是通过应用于嵌套列表项的paddingLeft完成的。在演示中,该值设置为32px(theme.spacing(4)),但是您可以将其设置为任意值。

以下是嵌套列表演示中的code

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>
  );
}

答案 1 :(得分:0)

Group-Menu

        <List component="nav" aria-label="patient-group">
            <ListItem>
                <ListItemText
                    primary="patients"
                    primaryTypographyProps={{variant:'button' }}
                />
            </ListItem>
            <PatientMenu />
            <Divider />
            <ListItem>
                <ListItemText
                    primary="delivery sheets"
                    primaryTypographyProps={{ variant: 'button' }}
                />
            </ListItem>
            <DeliverySheetMenu />
        </List>


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