Browse Source

fix: rating repeated click is not update (#112)

mengdaoshizhongxinyang 4 years ago
parent
commit
7e1a0ac5c2

+ 1 - 1
packages/semi-foundation/rating/foundation.ts

@@ -106,7 +106,7 @@ export default class RatingFoundation<P = Record<string, any>, S = Record<string
         const isReset = allowClear ? newValue === value : false;
         this._adapter.updateValue(isReset ? 0 : newValue);
         if (isReset) {
-            this._adapter.notifyHoverChange(0, newValue);
+            this._adapter.notifyHoverChange(undefined, newValue);
         } else {
             this._adapter.clearValue(null);
         }

+ 12 - 0
packages/semi-ui/rating/__test__/rating.test.js

@@ -250,4 +250,16 @@ describe('Rating', () => {
         halfUl.simulate('keyDown', { keyCode: keyCodeRight });
         expect(HalfR.state().value).toEqual(2);
     })
+
+    it('click much times', () => {
+        const R = getRating({});
+        let stars = R.find('div[role="radio"]');
+        const event = {};
+        stars.at(1).simulate('click', event);
+        expect(R.find(`.${BASE_CLASS_PREFIX}-rating-star-full`).length).toEqual(2);
+        stars.at(1).simulate('click', event);
+        expect(R.find(`.${BASE_CLASS_PREFIX}-rating-star-full`).length).toEqual(0);
+        stars.at(1).simulate('click', event);
+        expect(R.find(`.${BASE_CLASS_PREFIX}-rating-star-full`).length).toEqual(2);
+    });
 });