我想为日期范围制作一个掩码。但是,当我删除开始日期中的最后一个字符时,它会被结束日期中的数字替换。
是否可以使得当删除最新字符时,placeholderChar 中的值被替换?
https://codesandbox.io/p/sandbox/hungry-resonance-dyqrmx
import { IMask, useIMask } from "react-imask";
export default function App() {
const { ref } = useIMask<HTMLInputElement>(
{
mask: "from - to",
pattern: "d`.m`.0000 - d`.m`.0000",
blocks: {
from: {
mask: Date,
blocks: {
d: {
mask: IMask.MaskedRange,
placeholderChar: "д",
from: 1,
to: 31,
maxLength: 2,
},
m: {
mask: IMask.MaskedRange,
placeholderChar: "м",
from: 1,
to: 12,
maxLength: 2,
},
Y: {
mask: IMask.MaskedRange,
placeholderChar: "г",
from: 1900,
to: 2999,
maxLength: 4,
},
},
},
to: {
mask: Date,
blocks: {
d: {
mask: IMask.MaskedRange,
placeholderChar: "д",
from: 1,
to: 31,
maxLength: 2,
},
m: {
mask: IMask.MaskedRange,
placeholderChar: "м",
from: 1,
to: 12,
maxLength: 2,
},
Y: {
mask: IMask.MaskedRange,
placeholderChar: "г",
from: 1900,
to: 2999,
maxLength: 4,
},
},
},
},
lazy: true,
placeholderChar: " ",
}
);
return (
<div className="App">
<input ref={ref} style={{ width: 180 }} />
</div>
);
}
你需要使用`:
d`.m`.0000` - d`.m`.0000