From 6cc5348d07852718d9b98de720efb580ecc4032d Mon Sep 17 00:00:00 2001 From: Bougie <1742070326@qq.com> Date: Mon, 2 Sep 2019 14:51:36 +0800 Subject: [PATCH 1/3] fix(checkbox): #603 --- components/checkbox/Group.js | 2 +- components/radio/Group.js | 2 +- package-lock.json | 21 ++++++++++++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/components/checkbox/Group.js b/components/checkbox/Group.js index a254d1187..8ea862e30 100644 --- a/components/checkbox/Group.js +++ b/components/checkbox/Group.js @@ -72,7 +72,7 @@ function getData (props) { const _value = hasValue(props) ? value : defaultValue return { data: data.map((item) => { - const isPlain = typeof item === 'string' + const isPlain = ['string', 'number'].includes(typeof item) const label = isPlain ? item : item.content const value = isPlain ? item : item.id const disabled = !isPlain && item.disabled diff --git a/components/radio/Group.js b/components/radio/Group.js index f833510f6..fe27aa992 100644 --- a/components/radio/Group.js +++ b/components/radio/Group.js @@ -80,7 +80,7 @@ function getData (props) { const _value = hasValue(props) ? value : defaultValue return { data: data.map((item) => { - const isPlain = typeof item === 'string' + const isPlain = ['string', 'number'].includes(typeof item) const label = isPlain ? item : item.content const value = isPlain ? item : item.id const disabled = !isPlain && item.disabled diff --git a/package-lock.json b/package-lock.json index 181fff307..8aa0e3243 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@hi-ui/hiui", - "version": "2.1.1", + "version": "2.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -3156,6 +3156,12 @@ "requires": { "ms": "2.0.0" } + }, + "qs": { + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", + "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==", + "dev": true } } }, @@ -6939,6 +6945,12 @@ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=", "dev": true + }, + "qs": { + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", + "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==", + "dev": true } } }, @@ -16539,10 +16551,9 @@ "dev": true }, "qs": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", - "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==", - "dev": true + "version": "6.8.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.8.0.tgz", + "integrity": "sha512-tPSkj8y92PfZVbinY1n84i1Qdx75lZjMQYx9WZhnkofyxzw2r7Ho39G3/aEvSUdebxpnnM4LZJCtvE/Aq3+s9w==" }, "query-string": { "version": "4.3.4", From 177f21389ac3ee862e71eef2fe2ed970f1f17914 Mon Sep 17 00:00:00 2001 From: Bougie <1742070326@qq.com> Date: Mon, 2 Sep 2019 16:01:52 +0800 Subject: [PATCH 2/3] fix(checkbox): #592, #607 --- components/checkbox/Group.js | 37 +++++++++++++++++------------------- components/radio/Group.js | 37 +++++++++++++++++------------------- 2 files changed, 34 insertions(+), 40 deletions(-) diff --git a/components/checkbox/Group.js b/components/checkbox/Group.js index 8ea862e30..26edc82d2 100644 --- a/components/checkbox/Group.js +++ b/components/checkbox/Group.js @@ -9,11 +9,11 @@ const prefixCls = 'hi-checkbox-group' class Group extends Component { constructor (props) { super(props) - this.state = getData(props) + this.state = { data: getData(props), value: props.value } } - static getDerivedStateFromProps (nextProps) { - if (hasValue(nextProps)) { - return getData(nextProps) + static getDerivedStateFromProps (nextProps, state) { + if (nextProps.value !== state.value || getData(nextProps) !== state.data) { + return { data: getData(nextProps), value: nextProps.value } } return null } @@ -63,27 +63,24 @@ class Group extends Component { } function hasValue (props) { - const has = (key) => Object.prototype.hasOwnProperty.call(props, key) - return has('value') + return props.value !== undefined } function getData (props) { const { data, value, defaultValue } = props const _value = hasValue(props) ? value : defaultValue - return { - data: data.map((item) => { - const isPlain = ['string', 'number'].includes(typeof item) - const label = isPlain ? item : item.content - const value = isPlain ? item : item.id - const disabled = !isPlain && item.disabled - return { - label, - value, - disabled, - checked: (_value || []).includes(value) - } - }) - } + return data.map((item) => { + const isPlain = ['string', 'number'].includes(typeof item) + const label = isPlain ? item : item.content + const value = isPlain ? item : item.id + const disabled = !isPlain && item.disabled + return { + label, + value, + disabled, + checked: (_value || []).includes(value) + } + }) } const PropTypesArrayOfStringOrNumber = PropTypes.oneOfType([ diff --git a/components/radio/Group.js b/components/radio/Group.js index fe27aa992..422ae68bb 100644 --- a/components/radio/Group.js +++ b/components/radio/Group.js @@ -10,11 +10,11 @@ const prefixCls = 'hi-radio-group' class Group extends React.Component { constructor (props) { super(props) - this.state = getData(props) + this.state = { data: getData(props), value: props.value } } - static getDerivedStateFromProps (nextProps) { - if (hasValue(nextProps)) { - return getData(nextProps) + static getDerivedStateFromProps (nextProps, state) { + if (nextProps.value !== state.value || getData(nextProps) !== state.data) { + return { data: getData(nextProps), value: nextProps.value } } return null } @@ -71,27 +71,24 @@ function GroupWrapper ({ children, type, ...restProps }) { } function hasValue (props) { - const has = (key) => Object.prototype.hasOwnProperty.call(props, key) - return has('value') + return props.value !== undefined } function getData (props) { const { data, value, defaultValue } = props const _value = hasValue(props) ? value : defaultValue - return { - data: data.map((item) => { - const isPlain = ['string', 'number'].includes(typeof item) - const label = isPlain ? item : item.content - const value = isPlain ? item : item.id - const disabled = !isPlain && item.disabled - return { - label, - value, - disabled, - checked: _value === value || Number(_value) === value - } - }) - } + return data.map((item) => { + const isPlain = ['string', 'number'].includes(typeof item) + const label = isPlain ? item : item.content + const value = isPlain ? item : item.id + const disabled = !isPlain && item.disabled + return { + label, + value, + disabled, + checked: _value === value || Number(_value) === value + } + }) } const PropTypesOfStringOrNumber = PropTypes.oneOfType([ From 1a94b0a618b3de6c07c307bc04506fe61d775fe8 Mon Sep 17 00:00:00 2001 From: Bougie <1742070326@qq.com> Date: Mon, 2 Sep 2019 16:33:58 +0800 Subject: [PATCH 3/3] fix(form): #608 --- components/form/Item.js | 3 ++- components/form/index.js | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/form/Item.js b/components/form/Item.js index 01c88b6e2..7b9f43006 100644 --- a/components/form/Item.js +++ b/components/form/Item.js @@ -2,6 +2,7 @@ import React, { Component } from 'react' import classNames from 'classnames' import AsyncValidator from 'async-validator' import PropTypes from 'prop-types' +import { depreactedPropsCompat } from '../_util' class FormItem extends Component { constructor (props, context) { @@ -215,4 +216,4 @@ FormItem.defaultProps = { size: 'small' } -export default FormItem +export default depreactedPropsCompat([['field', 'prop']])(FormItem) diff --git a/components/form/index.js b/components/form/index.js index 334e83aba..936f96218 100644 --- a/components/form/index.js +++ b/components/form/index.js @@ -1,8 +1,7 @@ import Form from './Form' import Item from './Item' import './style/index' -import { depreactedPropsCompat } from '../_util' -Form.Item = depreactedPropsCompat([['field', 'prop']])(Item) +Form.Item = Item export default Form