Skip to content

Commit 6bf57ca

Browse files
committed
fix(pf4): enabled downshift multi select searchable
1 parent b227500 commit 6bf57ca

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

packages/pf4-component-mapper/demo/demo-schemas/select-schema.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ const selectSchema = {
3232
options,
3333
isMulti: true
3434
},
35+
{
36+
component: componentTypes.SELECT,
37+
name: 'multi-searchable-select',
38+
label: 'Searchable multi select',
39+
options,
40+
isMulti: true,
41+
isSearchable: true
42+
},
3543
{
3644
component: componentTypes.SELECT,
3745
name: 'simple-select',

packages/pf4-component-mapper/src/common/select/input.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@ import { Divider } from '@patternfly/react-core';
44

55
import './input.scss';
66

7-
const Input = ({ inputRef, isSearchable, isDisabled, getInputProps, ...props }) => {
7+
const Input = ({ inputRef, isSearchable, isDisabled, getInputProps, value, ...props }) => {
8+
const inputProps = getInputProps({ disabled: isDisabled });
89
return (
910
<Fragment>
1011
<div className="pf-c-select__menu-search">
1112
<input
1213
autoFocus
14+
value=""
1315
{...props}
1416
{...(!isSearchable && { tabIndex: '-1' })}
1517
className="pf-c-form-control pf-m-search"
1618
ref={inputRef}
17-
{...getInputProps({
18-
disabled: isDisabled
19-
})}
19+
{...{
20+
...inputProps,
21+
value: inputProps.value || '',
22+
onChange: inputProps.onChange || Function
23+
}}
2024
/>
2125
</div>
2226
<Divider />

packages/pf4-component-mapper/src/common/select/select.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ const stateReducer = (state, changes, keepMenuOpen) => {
8484
return {
8585
...changes,
8686
isOpen: keepMenuOpen ? state.isOpen : !state.isOpen,
87-
highlightedIndex: state.highlightedIndex
87+
highlightedIndex: state.highlightedIndex,
88+
inputValue: state.inputValue // prevent filter value change after option click
89+
};
90+
case Downshift.stateChangeTypes.controlledPropUpdatedSelectedItem:
91+
return {
92+
...changes,
93+
inputValue: typeof changes.inputValue === 'string' ? changes.inputValue : state.inputValue
8894
};
8995
default:
9096
return changes;

0 commit comments

Comments
 (0)