Skip to content

Commit

Permalink
fix(Slider): Fixed the issue where entering a minus sign triggered an…
Browse files Browse the repository at this point in the history
… onChange event with NaN.
  • Loading branch information
lrenc authored and yinkaihui committed Apr 26, 2024
1 parent 4740d8c commit e29b485
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
14 changes: 10 additions & 4 deletions components/Slider/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ const Input = function (props: InputProps) {
value={innerValue[0]}
key={0}
onChange={(val, reason) => {
handleChange([val, innerValue[1]]);
beginExtraProps?.onChange && beginExtraProps?.onChange(val, reason);
// eslint-disable-next-line no-self-compare
if (!(isNaN(val) && val !== val)) {
handleChange([val, innerValue[1]]);
beginExtraProps?.onChange && beginExtraProps?.onChange(val, reason);
}
}}
/>,
<div key={1} className={`${prefixCls}-input-range`}>
Expand All @@ -62,8 +65,11 @@ const Input = function (props: InputProps) {
key={2}
value={innerValue[1]}
onChange={(val, reason) => {
handleChange([innerValue[0], val]);
endExtraProps?.onChange && endExtraProps?.onChange(val, reason);
// eslint-disable-next-line no-self-compare
if (!(isNaN(val) && val !== val)) {
handleChange([innerValue[0], val]);
endExtraProps?.onChange && endExtraProps?.onChange(val, reason);
}
}}
/>
</div>
Expand Down
8 changes: 5 additions & 3 deletions components/Tabs/tab-header/tab-ink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ const TabInk = ({

if (newStyle && !isEqualWith(inkStyleRef.current, newStyle)) {
inkStyleRef.current = newStyle;
Object.keys(newStyle).forEach((key) => {
inkRef.current.style[key] = newStyle[key];
});
if (inkRef.current) {
Object.keys(newStyle).forEach((key) => {
inkRef.current.style[key] = newStyle[key];
});
}
}
});

Expand Down
17 changes: 17 additions & 0 deletions stories/Slider.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ function DemoSlider() {

export const Demo = () => <DemoSlider />;

export function Input() {
return (
<>
<Slider
defaultValue={80}
showInput
step={0.1}
min={-10}
style={{ width: 280 }}
onChange={(v) => {
console.log(v);
}}
/>
</>
);
}

export default {
title: 'Slider',
};

0 comments on commit e29b485

Please sign in to comment.