Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
feat(Picky): Add getFilterValue prop
Browse files Browse the repository at this point in the history
Callback added so the user can override the filter mechanism

fix #118
  • Loading branch information
Aidurber committed Apr 18, 2019
1 parent 8846fb0 commit fb8fe77
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Picky.propTypes = {
defaultFocusFilter: PropTypes.bool,
className: PropTypes.string,
renderList: PropTypes.func,
getFilterValue: PropTypes.func,
};
```

Expand Down Expand Up @@ -158,6 +159,7 @@ Picky.propTypes = {
- `defaultFocusFilter` - If set to true, will focus the filter by default when opened.
- `renderList` - Render prop for whole list, you can use this to add virtualization/windowing if necessary
- `filterPlaceholder` - Override the filter placeholder. Defaults to 'Filter...'
- `getFilterValue` - Will provide the input value of filter to the picky dropdown, so that if we have a larger list of options then we can only supply the matching options based on this value.

## Custom rendering

Expand All @@ -178,6 +180,7 @@ You can render out custom items for the dropdown.
multiple={true}
includeSelectAll={true}
includeFilter={true}
getFilterValue={this.getFilterValue}
dropdownHeight={600}
render={({
style,
Expand Down Expand Up @@ -257,7 +260,7 @@ Gets called with the following properties:
- `tabIndex`: number used for specifying tab index.
- `multiple`: boolean true if multiselect.

##= Render List
### Render List

```javascript
<Picky
Expand Down
7 changes: 5 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,17 @@ declare module 'react-picky' {
*/
renderList?: (props: RenderListProps) => any;


/**
* Override the placeholder of the filter
*
* @type {string}
* @memberof PickyProps
*/
filterPlaceholder?:string;
filterPlaceholder?: string;
/**
* Will provide the input value of filter to the picky dropdown, so that if we have a larger list of options then we can only supply the matching options based on this value.
*/
getFilterValue: (term: string) => any;
}

export default class Picky extends React.PureComponent<PickyProps, any> {
Expand Down
12 changes: 6 additions & 6 deletions src/Picky.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,13 @@ class Picky extends React.PureComponent {
* @memberof Picky
*/
onFilterChange(term) {
/**

/**
* getFilterValue function will provide the input value of filter to the picky dropdown, so that if we have a larger list of options then we can only supply the matching options based on this value
*/

if (this.props.getFilterValue) {
this.props.getFilterValue(term)
}
*/
if (this.props.getFilterValue) {
this.props.getFilterValue(term)
}
if (!term.trim()) {
return this.setState({
filtered: false,
Expand Down

0 comments on commit fb8fe77

Please sign in to comment.