From 4ea0c1c1d6ded707008a5ed09ab1cbc3c054a642 Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 30 Aug 2017 13:26:10 +0800 Subject: [PATCH 1/3] allow Number proptype on Option --- src/Option.jsx | 5 ++++- src/PropTypes.js | 11 ++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Option.jsx b/src/Option.jsx index 7b7151323..4b4e546b6 100644 --- a/src/Option.jsx +++ b/src/Option.jsx @@ -3,7 +3,10 @@ import PropTypes from 'prop-types'; export default class Option extends React.Component { static propTypes = { - value: PropTypes.string, + value: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.number, + ]), }; static isSelectOption = true; diff --git a/src/PropTypes.js b/src/PropTypes.js index 2beb509e0..fb87b9436 100644 --- a/src/PropTypes.js +++ b/src/PropTypes.js @@ -2,7 +2,10 @@ import PropTypes from 'prop-types'; function valueType(props, propName, componentName) { const labelInValueShape = PropTypes.shape({ - key: PropTypes.string.isRequired, + key: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.number, + ]).isRequired, label: PropTypes.string, }); if (props.labelInValue) { @@ -15,18 +18,20 @@ function valueType(props, propName, componentName) { return new Error( `Invalid prop \`${propName}\` supplied to \`${componentName}\`, ` + `when you set \`labelInValue\` to \`true\`, \`${propName}\` should in ` + - `shape of \`{ key: string, label?: string }\`.` + `shape of \`{ key: string || number, label?: string }\`.` ); } } else if (props.multiple && props[propName] === '') { return new Error( - `Invalid prop \`${propName}\` of type \`string\` supplied to \`${componentName}\`, ` + + `Invalid prop \`${propName}\` supplied to \`${componentName}\`, ` + `expected \`array\` when \`multiple\` is \`true\`.` ); } else { const validate = PropTypes.oneOfType([ PropTypes.arrayOf(PropTypes.string), + PropTypes.arrayOf(PropTypes.number), PropTypes.string, + PropTypes.number ]); return validate(...arguments); } From fdb2420e8e05c7ad356514667728fdd8a1ff4268 Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 30 Aug 2017 13:59:13 +0800 Subject: [PATCH 2/3] updated toMatch warning messages in test --- tests/Select.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Select.spec.js b/tests/Select.spec.js index 740f6e4bd..48b3c54e4 100644 --- a/tests/Select.spec.js +++ b/tests/Select.spec.js @@ -538,7 +538,7 @@ describe('Select', () => { expect(spy.mock.calls[0][0]).toMatch( 'Warning: Failed prop type: Invalid prop `value` supplied to `Select`, ' + 'when you set `labelInValue` to `true`,' + - ' `value` should in shape of `{ key: string, label?: string }`' + ' `value` should in shape of `{ key: string || number, label?: string }`' ); }); @@ -547,7 +547,7 @@ describe('Select', () => {