简体   繁体   English

展开时移除 MUI Accordion 间隙

[英]remove MUI Accordion gap when expanded

I'm trying to have the Accordion MUI component NOT move and NOT apply top and bottom margins to summary elements while it is in the expanded mode.我试图让 Accordion MUI 组件在处于展开模式时不移动并且不将顶部和底部边距应用于摘要元素。 I add this code to the summary element but that's not working.我将此代码添加到摘要元素中,但这不起作用。 what do you offer me?你给我什么? it worth mentioning that it works on the first accordion but not the others!!!!!!!!!!值得一提的是,它适用于第一部手风琴,但不适用于其他手风琴!!!!!!!!!!!!

sx={{
   "&.Mui-expanded": {
   minHeight: 0,
   margin: '12px 0',
   },
   "& .MuiAccordionSummary-content.Mui-expanded": {
   margin: 0,
   }
}}

Are you setting this prop on Accordion or AccordionSummary ?你是在Accordion还是AccordionSummary上设置这个道具? I've tested your code on StackBlitz by setting it on Accordion element and it worked properly.我已经通过在Accordion元素上设置它在 StackBlitz 上测试了您的代码,并且它工作正常。

I used MUI customized accordion and I change its setting to it: I used my icon.我使用了 MUI 定制的手风琴,并将其设置更改为它:我使用了我的图标。 it has a white background and no border and additional padding or margin:))))它有白色背景,没有边框和额外的填充或边距:))))

export const Accordion = styled((props: AccordionProps) => (
    <MuiAccordion disableGutters elevation={0} square {...props} />
))(({ theme }) => ({
    position: 'unset',
    border: 'none',
    boxShadow: 'none',
    maxWidth: 720,
    margin: '12 0',
    '&:before': {
        display: 'none',
        border: 'none'
    }
}));

export const AccordionSummary = styled((props: AccordionSummaryProps) => (
    <MuiAccordionSummary expandIcon={<ExpandMoreIcon />} {...props} />
))(({ theme }) => ({
    backgroundColor: 'white',
    padding: 0,
    flexDirection: 'row',
    '& .MuiAccordionSummary-expandIconWrapper.Mui-expanded': {
        transform: 'rotate(180deg)'
    }
}));

export const AccordionDetails = styled(MuiAccordionDetails)(({ theme }) => ({
    padding: 0,
    border: 'none'
}));

export const FAQText = styled(Typography)({
    maxWidth: 628
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM