From 5f41fa5e99a5e685dbde511c09b9230918189a98 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Wed, 3 Jul 2019 21:56:30 +0800 Subject: [PATCH] cr vc-rate --- .../__tests__/__snapshots__/demo.test.js.snap | 2 +- .../__tests__/__snapshots__/demo.test.js.snap | 510 ++++++++++-------- components/vc-rate/src/Rate.jsx | 11 +- components/vc-rate/src/Star.jsx | 27 +- 4 files changed, 316 insertions(+), 234 deletions(-) diff --git a/components/form/__tests__/__snapshots__/demo.test.js.snap b/components/form/__tests__/__snapshots__/demo.test.js.snap index 7278af140..05684c0aa 100644 --- a/components/form/__tests__/__snapshots__/demo.test.js.snap +++ b/components/form/__tests__/__snapshots__/demo.test.js.snap @@ -647,7 +647,7 @@ exports[`renders ./components/form/demo/validate-other.vue correctly 1`] = `
-
+
diff --git a/components/rate/__tests__/__snapshots__/demo.test.js.snap b/components/rate/__tests__/__snapshots__/demo.test.js.snap index 987618ff9..5933cad43 100644 --- a/components/rate/__tests__/__snapshots__/demo.test.js.snap +++ b/components/rate/__tests__/__snapshots__/demo.test.js.snap @@ -2,45 +2,55 @@ exports[`renders ./components/rate/demo/basic.md correctly 1`] = ` `; @@ -48,89 +58,119 @@ exports[`renders ./components/rate/demo/basic.md correctly 1`] = ` exports[`renders ./components/rate/demo/character.md correctly 1`] = `
    -
  • +
    +
    +
    +
  • -
  • +
    +
    +
    +
  • -
  • +
    +
    +
    +
  • -
  • +
    +
    +
    +
  • -
  • +
    +
    +
    +

    -
  • +
    +
    A
    +
    A
    +
  • -
  • +
    +
    A
    +
    A
    +
  • -
  • +
    +
    A
    +
    A
    +
  • -
  • +
    +
    A
    +
    A
    +
  • -
  • +
    +
    A
    +
    A
    +

    -
  • +
    +
    +
    +
  • -
  • +
    +
    +
    +
  • -
  • +
    +
    +
    +
  • -
  • +
    +
    +
    +
  • -
  • +
    +
    +
    +

@@ -139,182 +179,222 @@ exports[`renders ./components/rate/demo/character.md correctly 1`] = ` exports[`renders ./components/rate/demo/clear.md correctly 1`] = `
    -
  • +
    +
    +
    +
    +
  • +
  • +
    +
    +
    +
    +
  • +
  • +
    +
    +
    +
    +
  • +
  • +
    +
    +
    +
    +
  • +
  • +
    +
    +
    +
    +
  • +
allowClear: true +
+
    +
  • +
    +
    +
    +
    +
  • +
  • +
    +
    +
    +
    +
  • +
  • +
    +
    +
    +
    +
  • +
  • +
    +
    +
    +
    +
  • +
  • +
    +
    +
    +
    +
  • +
allowClear: false +
+
+`; + +exports[`renders ./components/rate/demo/disabled.md correctly 1`] = ` +
+ +
  • +
    -
  • -
    + +
  • +
    -
  • - +
  • +
    -
  • - +
  • +
    -
  • - allowClear: true -
    - +`; + +exports[`renders ./components/rate/demo/half.md correctly 1`] = ` + allowClear: false -
    - -`; - -exports[`renders ./components/rate/demo/disabled.md correctly 1`] = ` - -`; - -exports[`renders ./components/rate/demo/half.md correctly 1`] = ` - `; -exports[`renders ./components/rate/demo/text.md correctly 1`] = ` normal`; +exports[`renders ./components/rate/demo/text.md correctly 1`] = ` normal`; diff --git a/components/vc-rate/src/Rate.jsx b/components/vc-rate/src/Rate.jsx index 52dfde9a1..3fce65bec 100644 --- a/components/vc-rate/src/Rate.jsx +++ b/components/vc-rate/src/Rate.jsx @@ -89,15 +89,16 @@ export default { this.$emit('hoverChange', undefined); }, onClick(event, index) { - const value = this.getStarValue(index, event.pageX); + const { allowClear, sValue: value } = this; + const newValue = this.getStarValue(index, event.pageX); let isReset = false; - if (this.allowClear) { - isReset = value === this.sValue; + if (allowClear) { + isReset = newValue === value; } this.onMouseLeave(true); - this.changeValue(isReset ? 0 : value); + this.changeValue(isReset ? 0 : newValue); this.setState({ - cleanedValue: isReset ? value : null, + cleanedValue: isReset ? newValue : null, }); }, onFocus() { diff --git a/components/vc-rate/src/Star.jsx b/components/vc-rate/src/Star.jsx index 84c46d805..346acf656 100644 --- a/components/vc-rate/src/Star.jsx +++ b/components/vc-rate/src/Star.jsx @@ -67,19 +67,20 @@ export default { const character = getComponentFromProp(this, 'character'); let star = ( -
  • +
    index ? 'true' : 'false'} + aria-posinset={index + 1} + aria-setsize={count} + tabIndex={0} + > +
    {character}
    +
    {character}
    +
  • ); if (characterRender) {