Skip to content

Commit e28a652

Browse files
committed
fix(pf4): prevent select filter trigger on value selection
1 parent 51e913c commit e28a652

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,29 @@ const loadOptions = (inputValue = '') => {
3636
);
3737
};
3838

39+
const loadOptionsLong = (inputValue = '') => {
40+
const options = [...Array(99)].map((_v, index) => ({ label: `${index}`, value: `${index}` }));
41+
return new Promise((res) =>
42+
setTimeout(() => {
43+
if (inputValue.length === 0) {
44+
return res(options.slice(0, 80));
45+
}
46+
47+
return res(options.filter(({ label }) => label.toLocaleLowerCase().includes(inputValue.toLocaleLowerCase())));
48+
}, 1500)
49+
);
50+
};
51+
3952
const selectSchema = {
4053
fields: [
54+
{
55+
component: componentTypes.SELECT,
56+
name: 'long-searchable-async-select',
57+
label: 'Long searchable async select',
58+
loadOptions: loadOptionsLong,
59+
isSearchable: true,
60+
menuIsPortal: true
61+
},
4162
{
4263
component: componentTypes.SELECT,
4364
name: 'simple-portal-select',
@@ -165,5 +186,6 @@ const selectSchema = {
165186
};
166187

167188
export default {
168-
...selectSchema
189+
...selectSchema,
190+
fields: [selectSchema.fields[0]]
169191
};

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ const InternalSelect = ({
163163
itemToString={(value) => itemToString(value, isMulti, showMore, handleShowMore, handleChange)}
164164
selectedItem={value || ''}
165165
stateReducer={(state, changes) => stateReducer(state, changes, isMulti)}
166-
onInputValueChange={(inputValue) => {
167-
if (onInputChange && typeof inputValue === 'string') {
166+
onInputValueChange={(inputValue, { selectedItem }) => {
167+
/**
168+
* Prevent firing te load options callback when selecting value not filtering
169+
*/
170+
if (onInputChange && typeof inputValue === 'string' && selectedItem?.label !== inputValue) {
168171
onInputChange(inputValue);
169172
}
170173
}}

0 commit comments

Comments
 (0)