You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
fix(roles): do not allow manual skill selection (if not in the list)
* Fix an issue which was allowing users to be able to add non-existing skills.
* The `Typeahead` component was also firing the `onChange` event on Blur, Enter and Esc presses.
* To overcome this, added a property (`enforceListOnlySelection`) to the component. If it's set, the `onChange` event will be fired only if the input is in the suggestion list.
* Add `minLengthForSuggestions` property to the `Typeahead` component.
* This is the minimum length to retrieve & display suggestions and was hardcoded (with 3) in the component.
* The new property allows to specify it. The ability to set it to `1` is useful for displaying skills like `C`, `C#`, which have less than 3 characters.
Adresses https://github.com/topcoder-platform/taas-app/issues/426
Copy file name to clipboardExpand all lines: src/components/Typeahead/index.jsx
+22-10
Original file line number
Diff line number
Diff line change
@@ -74,6 +74,8 @@ const selectComponents = {
74
74
* @param {function} props.onChange function called when value changes
75
75
* @param {function} [props.onInputChange] function called when input value changes
76
76
* @param {function} [props.onBlur] function called on input blur
77
+
* @param {number} [props.minLengthForSuggestions] the minimum string lenth for displaying suggestions (default 3)
78
+
* @param {Boolean} [props.enforceListOnlySelection] enforces user to select from the list - manual inputs (if not in the list) won't affect the selection
77
79
* @param {string} props.value input value
78
80
* @param {function} props.getSuggestions the function to get suggestions
79
81
* @param {string} props.targetProp the target property of the returned object from getSuggestions
@@ -87,6 +89,8 @@ const Typeahead = ({
87
89
onChange,
88
90
onInputChange,
89
91
onBlur,
92
+
minLengthForSuggestions =3,
93
+
enforceListOnlySelection =false,
90
94
placeholder,
91
95
value,
92
96
getSuggestions,
@@ -139,7 +143,12 @@ const Typeahead = ({
139
143
setIsMenuFocused(false);
140
144
setIsMenuOpen(false);
141
145
setIsLoading(false);
142
-
onChange(inputValue);
146
+
// fire onChange event
147
+
// - if `enforceListOnlySelection` is not set,
148
+
// - or if it's set and options list contains the value
0 commit comments