reactjs - 如何在 Material UI 的 NumberFormat 组件中设置变体轮廓和小尺寸?
问题描述
我试图传递customInput={<TextField size="small" variant="outlined"/>}
组件,但是当我以这种方式传递它时,货币掩码停止工作。它在 Material UI 文档中的显示方式有点不清楚。
import NumberFormat from 'react-number-format';
import { useFormikContext } from 'formik';
import TextField from '@material-ui/core/TextField';
export function TextFieldMoney({ name, label, disabled, maxLength }: TextFieldMoneyProps) {
const { setFieldValue, values } = useFormikContext<any>();
const handleChange = (event: any) => {
setFieldValue(name, event.value)
}
return (
<NumberFormat
isNumericString={true}
thousandSeparator={','}
decimalSeparator={'.'}
prefix={'R$ '}
decimalScale={2}
fixedDecimalScale={true}
customInput={TextField}
onValueChange={(value: any) => handleChange(value)}
type="text"
/>
);
}
解决方案
您只需要将它们作为道具传递给NumberFormat
组件,例如在线示例检查codesandbox。
<NumberFormat
isNumericString={true}
thousandSeparator={','}
decimalSeparator={'.'}
prefix={'R$ '}
decimalScale={2}
fixedDecimalScale={true}
customInput={TextField}
onValueChange={(value: any) => handleChange(value)}
variant="outlined"
size="small"
type="text"
/>
推荐阅读
- c# - 打开和关闭文件夹中的所有 Excel 文件
- angular - primeNG 升级到 8.0.1 错误加载 DataTable
- testcontainers - 测试容器中的 GenericContainer 应该如何参数化?
- python - Django:过滤多对多字段
- powershell - Write-verbose 的格式化输出
- javascript - 寻找与 HTML 5 和 Webvtt 文档同步视频的想法
- continuous-deployment - Symfony 应用程序 > 部署内容:未执行迁移任务
- javascript - 使用函数删除c3中的图形
- graphviz - 使用集群反转 rank=same 的顺序
- java - 如何在springboot中动态创建表?