Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Option.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions src/PropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }`'
);
});

Expand All @@ -547,7 +547,7 @@ describe('Select', () => {
<Select multiple value="" />
);
expect(spy.mock.calls[0][0]).toMatch(
'Warning: Failed prop type: Invalid prop `value` of type `string` supplied to `Select`, ' +
'Warning: Failed prop type: Invalid prop `value` supplied to `Select`, ' +
'expected `array` when `multiple` is `true`'
);
});
Expand Down