Skip to content

Commit

Permalink
use react-requred-if for Search onFilterSelect prop
Browse files Browse the repository at this point in the history
onFilterSelect shouold only be required if props.filters is supplied
adding react-required-if solves this.
  • Loading branch information
guyfedwards committed Sep 17, 2018
1 parent a6878d4 commit 2658f54
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"prop-types": "15.6.0",
"react-input-autosize": "2.2.1",
"react-motion": "0.5.2",
"react-required-if": "^1.0.3",
"react-resize-aware": "2.7.0",
"react-router": "3.2.0"
},
Expand Down
4 changes: 3 additions & 1 deletion src/components/Search/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import styled from 'styled-components';
import { map, includes, without, isEmpty, last, noop } from 'lodash';
import PropTypes from 'prop-types';
import requiredIf from 'react-required-if';

import { copyPropTypes } from '../../utils/compose';
import Input from '../Input';
Expand Down Expand Up @@ -221,7 +222,7 @@ Search.propTypes = {
* Handler that runs when an item from the search filter dropdown is selected
* Returns the selected filter value.
*/
onFilterSelect: PropTypes.func.isRequired,
onFilterSelect: requiredIf(PropTypes.func, props => props.filters),
onFocus: PropTypes.func,
onBlur: PropTypes.func,
};
Expand All @@ -230,6 +231,7 @@ Search.defaultProps = {
placeholder: 'search',
disabled: false,
filters: [],
onFilterSelect: noop,
onPin: noop,
onFocus: noop,
onBlur: noop,
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6822,6 +6822,10 @@ react-reconciler@^0.7.0:
object-assign "^4.1.1"
prop-types "^15.6.0"

react-required-if@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/react-required-if/-/react-required-if-1.0.3.tgz#6a40a761b1d54815c1d4e6610910cbf92b5aa987"

react-resize-aware@2.7.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/react-resize-aware/-/react-resize-aware-2.7.0.tgz#1bb6d0b45a234d94d412b5c3f5e9d2ffbf973429"
Expand Down

0 comments on commit 2658f54

Please sign in to comment.