Keep time units upon time entry
Fixes: #26549 Signed-off-by: Hynek Mlnarik <hmlnarik@redhat.com>
This commit is contained in:
parent
0e1f3ec402
commit
0df5452507
1 changed files with 5 additions and 1 deletions
|
@ -60,6 +60,8 @@ export const TimeSelector = ({
|
|||
}: TimeSelectorProps) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [lastMultiplier, setLastMultiplier] = useState<number>();
|
||||
|
||||
const defaultMultiplier = useMemo(
|
||||
() => allTimes.find((time) => time.unit === units[0])?.multiplier,
|
||||
[units],
|
||||
|
@ -88,9 +90,11 @@ export const TimeSelector = ({
|
|||
if (value) {
|
||||
setMultiplier(multiplier);
|
||||
setTimeValue(value / multiplier);
|
||||
setLastMultiplier(multiplier);
|
||||
} else {
|
||||
setTimeValue(value || "");
|
||||
setMultiplier(defaultMultiplier);
|
||||
setMultiplier(lastMultiplier ?? defaultMultiplier);
|
||||
setLastMultiplier(lastMultiplier ?? defaultMultiplier);
|
||||
}
|
||||
}, [value, defaultMultiplier]);
|
||||
|
||||
|
|
Loading…
Reference in a new issue