Files
react-test/docs/data/joy/components/input/InputReactNumberFormat.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.3 KiB
JavaScript
Raw Normal View History

2025-12-12 14:26:25 +09:00
import * as React from 'react';
import PropTypes from 'prop-types';
import { NumericFormat } from 'react-number-format';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Input from '@mui/joy/Input';
const NumericFormatAdapter = React.forwardRef(
function NumericFormatAdapter(props, ref) {
const { onChange, ...other } = props;
return (
<NumericFormat
{...other}
getInputRef={ref}
onValueChange={(values) => {
onChange({
target: {
name: props.name,
value: values.value,
},
});
}}
thousandSeparator
valueIsNumericString
prefix="$"
/>
);
},
);
NumericFormatAdapter.propTypes = {
name: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
};
export default function InputReactNumberFormat() {
const [value, setValue] = React.useState('1320');
return (
<FormControl>
<FormLabel>React number format</FormLabel>
<Input
value={value}
onChange={(event) => setValue(event.target.value)}
placeholder="Placeholder"
slotProps={{
input: {
component: NumericFormatAdapter,
},
}}
/>
</FormControl>
);
}