【问题标题】:MUI Multiline event.target.value not showing \nMUI 多行 event.target.value 未显示 \\n
【发布时间】:2022-12-14 12:20:48
【问题描述】:

我目前有一个多行文本框,每当通过网站创建新行时,它都不会用 \n 反映在后端。

目标是在调用 event.target.value 时让每个新行都等于 \n。

`

const [welcomeText, setwelcomeText] = React.useState(welcome.welcomeText);
  const handleWelcomeTextChange = (event) => {
    setwelcomeText(event.target.value);

  };

`

`

 <TextField
          id="outlined-multiline-flexible"
          label="Welcome Text Description"
          multiline
          fullWidth
          maxRows={10}
          value={welcomeText}
          defaultValue={welcome.welcomeText}
          onChange={handleWelcomeTextChange}
        />

`

我试图实施一个修复程序来检测间距并将其转换为 \n 但这没有用。

【问题讨论】:

    标签: material-ui textbox


    【解决方案1】:

    你实际上可以使用 add a style prop to the typography component

    <Typography style={{ whiteSpace: 'pre-line' }}>{'hello 
    MUI'}</Typography>
    

    我也花了将近一个小时来寻找那个愚蠢的 的解决方案。

    希望能帮助到你。

    【讨论】:

      猜你喜欢
      • 2021-12-13
      • 2022-06-13
      • 1970-01-01
      • 2021-12-30
      • 2020-03-10
      • 2022-08-23
      • 2021-11-30
      • 2021-03-26
      • 2017-03-31
      相关资源
      最近更新 更多