【问题标题】:How to mask a Material-ui FilledInput如何屏蔽 Material-ui FilledInput
【发布时间】:2020-04-11 04:18:49
【问题描述】:

我正在尝试使用此包屏蔽 FilledInput Material-ui 组件以显示为货币:https://www.npmjs.com/package/react-currency-format

我尝试了许多不同的方法,但没有一个是正确的。我创建了一个带有问题的代码框:https://codesandbox.io/s/fancy-silence-vjkxq

现在我正在以这种方式实现:

function Amount({ handleChange, values, t }) {
    return (
        <FormControl fullWidth variant="filled">
            <InputLabel htmlFor="amount">{t("Send")}</InputLabel>
            <FilledInput
                name="amount"
                onChange={handleChange}
                value={values.amount}
                startAdornment={
                    <InputAdornment position="start">€</InputAdornment>
                }
            />
        </FormControl>
    );
}

export default function ExchangeRateProvider() {

  return (

    <CurrencyFormat
          customInput={Amount}
          handleChange={handleAmount}
          t={t}
          value={values.amount}
          thousandSeparator={true}
    />

  )
}

代码工作正常,它更新了数字并应用了material-ui 组件,但是掩码不起作用。

提前致谢

【问题讨论】:

标签: javascript reactjs material-ui


【解决方案1】:

这样的?

CODESANDBOX HERE

function App() {
  const [value, setValue] = useState("0");

  const handleChange = event => {
    const { value } = event.target;
    setValue(value);
  };

  return (
    <div className="App">
      <CurrencyFormat
        value={value}
        onChange={handleChange}
        displayType={"input"}
        customInput={FilledInput}
        thousandSeparator={true}
        startAdornment={<InputAdornment position="start">€</InputAdornment>}
      />
    </div>
  );
}

【讨论】:

    猜你喜欢
    • 2019-05-25
    • 2020-02-29
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    • 2011-03-04
    • 2011-08-11
    • 2017-07-02
    相关资源
    最近更新 更多