segmentio / evergreen

🌲 Evergreen React UI Framework by Segment
https://evergreen.segment.com
MIT License
12.36k stars 833 forks source link

Property `selected` should include `PropTypes.number` to allow integer values #1625

Open ADTC opened 1 year ago

ADTC commented 1 year ago

https://github.com/segmentio/evergreen/blob/e13b9b4f2609ed3ecb5f7dc218dfe4fe1a1da048/src/select-menu/src/SelectedPropType.js#L8

Please allow PropTypes.number here. Sometimes the value is numeric - quite common when display label is a string, but internal value is an int.

Although the application works, this throws error in the console.

Warning: Failed prop type: Invalid prop `selected` supplied to `SelectMenu`, expected one of type [string].
SelectMenu@webpack-internal:///./node_modules/evergreen-ui/esm/select-menu/src/SelectMenu.js:39:15
▽ React 6
        printWarning
        error
        checkPropTypes
        validatePropTypes
        jsxWithValidation
        jsxWithValidationDynamic

Right now I'm overriding the propTypes to fix the error:

SelectMenu.propTypes = {
  ...SelectMenu.propTypes,
  selected: PropTypes.oneOfType([
    PropTypes.string,
    PropTypes.arrayOf(PropTypes.string),
    PropTypes.number,
  ]),
};
AbhiJain2196 commented 1 year ago

Added type number to proptypes #1627