Skip to content

Commit d527efd

Browse files
committed
Show visual feedback if number is invalid
1 parent 6acedc9 commit d527efd

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

js/dataframe/filter-numeric.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ const FilterNumericImpl: React.FC<FilterNumericImplProps> = (props) => {
5454
const [min, max] = props.value;
5555
const { editing, onFocus } = props;
5656

57+
const minInputRef = useRef<HTMLInputElement>(null);
58+
const maxInputRef = useRef<HTMLInputElement>(null);
59+
5760
return (
5861
<div
5962
onBlur={(e) => {
@@ -69,24 +72,36 @@ const FilterNumericImpl: React.FC<FilterNumericImplProps> = (props) => {
6972
}}
7073
>
7174
<input
75+
ref={minInputRef}
7276
className="form-control form-control-sm"
7377
style={{ flex: "1 1 0", width: "0" }}
7478
type="number"
7579
placeholder={createPlaceholder(editing, "Min", props.range[0])}
7680
value={min}
77-
onChange={(e) =>
78-
props.onValueChange([coerceToNum(e.target.value), max])
79-
}
81+
onChange={(e) => {
82+
const value = coerceToNum(e.target.value);
83+
minInputRef.current.classList.toggle(
84+
"is-invalid",
85+
!e.target.checkValidity()
86+
);
87+
props.onValueChange([value, max]);
88+
}}
8089
/>
8190
<input
91+
ref={maxInputRef}
8292
className="form-control form-control-sm"
8393
style={{ flex: "1 1 0", width: "0" }}
8494
type="number"
8595
placeholder={createPlaceholder(editing, "Max", props.range[1])}
8696
value={max}
87-
onChange={(e) =>
88-
props.onValueChange([min, coerceToNum(e.target.value)])
89-
}
97+
onChange={(e) => {
98+
const value = coerceToNum(e.target.value);
99+
minInputRef.current.classList.toggle(
100+
"is-invalid",
101+
!e.target.checkValidity()
102+
);
103+
props.onValueChange([min, value]);
104+
}}
90105
/>
91106
</div>
92107
);

0 commit comments

Comments
 (0)