【问题标题】:Material UI stepper does not animate材质 UI 步进器没有动画
【发布时间】:2020-10-12 21:23:40
【问题描述】:

我在 Material UI 中使用了一个垂直步进器来呈现定价计算器。动画不再工作。以前,步进器会在步骤发生变化时制作折叠效果。

我怀疑这可能是由于嵌套了多个转换,但我不完全确定。

计算器的相关渲染方法如下。谢谢!

return (
    <Grid container>
      <Grid item xs={12} sm={12} md={8} className="nocPricingCalculatorContainer">
      <Collapse in={activeStep < 2}>
          <Stepper elevation={0} activeStep={activeStep} className="nocPricingCalculatorStepper" connector={<StepConnector classes={{ line: classes.stepConnector }} />} orientation="vertical">
            {steps.map((stepObj, index) => {
              return (
                <Step key={uuidv4()}>
                  <StepLabel classes={{ label: classes.stepLabel }} StepIconProps={{
                    classes: { text: classes.stepLabelText }
                  }}>{stepObj.label}</StepLabel>
                  <StepContent className={classes.stepContentBorder}>
                    <div className={classes.actionsContainer}>
                      <Grid container item xs={12}>
                        {getStepContent(index)}
                      </Grid>
                      <div>
                        {
                          (activeStep !== 0) ?
                            <Button
                              className="nocButtonClear"
                              onClick={handleBack}>
                              Back
                    </Button> :
                            <div></div>
                        }

                        <Button
                          variant="contained"
                          onClick={handleNext}
                          className="nocButtonYellow"
                          disableRipple
                        >
                          {activeStep === steps.length - 1 ? 'Finish' : 'Next'}
                        </Button>
                      </div>
                    </div>
                  </StepContent>
                </Step>
              )
            })}
          </Stepper>
        </Collapse>
        <Collapse in={activeStep >= 2}>
          {activeStep === steps.length && (
            <Grid item container className="nocPricingCalculatorFinalStep" alignItems="center" justify="center">
              <Grid item container xs={12} justify="center" className="nocPricingCalculatorResetArea">
                <Grid item>
                  <Button className="nocButtonClear nocPricingCalculatorResetButton" disableRipple onClick={handleReset}>
                    <RefreshIcon className="nocResetIcon" />Reset calculator
                  </Button>
                </Grid>
              </Grid>
              <Grid item container xs={12} justify="center" className="nocPricingCalculatorPriceArea">
                <Grid item container alignItems="center" justify="center" xs={12} className="nocPriceColumnLabel">
                  <CheckCircle className="nocPriceAreaCheckIcon" />
                  <Typography className="nocPricingCalculatorPricingHeader">
                    {pricingSectionTitle}
                  </Typography>
                </Grid>
                <Grid item container className="nocPricingCalculatorPriceColumn left" alignItems="center" justify="center" xs={12} sm={12} md={6}>

                  <Grid item xs={12}>
                    <Typography className="nocPricingCalculatorPricingRepairType">
                      {pricingColumnLeft.title}
                    </Typography>
                    <Typography className="nocPricingCalculatorPricingPrice">
                      {pricingColumnLeft.price}
                    </Typography>
                  </Grid>
                  <Grid item>
                    <List dense={true}>
                      {generateRenderableList(pricingColumnLeft.details)}
                    </List>
                  </Grid>
                </Grid>
                <Grid item container className="nocPricingCalculatorPriceColumn right" alignItems="center" justify="center" xs={12} sm={12} md={6}>
                  <Grid item xs={12}>
                    <Typography className="nocPricingCalculatorPricingRepairType">
                      {pricingColumnRight.title}
                    </Typography>
                    <Typography className="nocPricingCalculatorPricingPrice">
                      {pricingColumnRight.price}
                    </Typography>
                  </Grid>
                  <Grid item>
                    <List dense={true}>
                      {generateRenderableList(pricingColumnRight.details)}
                    </List>
                  </Grid>
                </Grid>
              </Grid>

            </Grid>
          )}
      </Collapse>
      </Grid>
    </Grid>
  );
}

【问题讨论】:

  • 你能在codesandbox.io重新创建这个问题吗?
  • 我修好了。看我的回答!我不小心添加的关键是导致步进器不断重新渲染。

标签: reactjs material-ui


【解决方案1】:

没关系。我不小心在 Step 上放置了一个随机 UUID 键,导致步进器在没有动画的情况下跳转到下一步。

#reactprobs

【讨论】:

    猜你喜欢
    • 2020-02-12
    • 1970-01-01
    • 2020-04-09
    • 1970-01-01
    • 2018-08-23
    • 2019-11-25
    • 1970-01-01
    • 2023-03-28
    • 2014-12-01
    相关资源
    最近更新 更多