Skip to content

Commit

Permalink
fix(NumberPicker): enable input -0.0, close alibaba-fusion#2989
Browse files Browse the repository at this point in the history
  • Loading branch information
galo.gm authored and youluna committed May 14, 2021
1 parent bca6089 commit 9a93440
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/number-picker/number-picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ class NumberPicker extends React.Component {
// 避免原生input将number类型的-0,渲染为0
return typeof format === 'function' && !hasFocused
? format(value)
: value !== '-0.' && 1 / value === -Infinity
: typeof value === 'number' && 1 / value === -Infinity
? '-0'
: value;
}
Expand Down
22 changes: 21 additions & 1 deletion test/number-picker/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('number-picker', () => {
done();
});

it('should support input with -.x or .x', () => {
it('should support input with -.x or .x or -0.0x', () => {
let onChange = value => {
assert(value === -0.2);
};
Expand Down Expand Up @@ -312,6 +312,26 @@ describe('number-picker', () => {
wrapper.find('input').simulate('blur');
assert(wrapper.find('input').prop('value') == '-0');
assert(onChange.calledTwice);

wrapper = mount(
<NumberPicker defaultValue={0} precision={2} />
);

wrapper
.find('input')
.simulate('change', { target: { value: '-0.0' } });
wrapper.find('input').simulate('blur');
assert(wrapper.find('input').prop('value') == '-0');
wrapper
.find('input')
.simulate('change', { target: { value: '-0.0' } });
assert(wrapper.find('input').prop('value') == '-0.0');
wrapper
.find('input')
.simulate('change', { target: { value: '-0.01' } });
wrapper.find('input').simulate('blur');
assert(wrapper.find('input').prop('value') == '-0.01');

});


Expand Down

0 comments on commit 9a93440

Please sign in to comment.