drf-react-by-schema 0.17.6 → 0.17.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -165,17 +165,35 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, ref) =
|
|
|
165
165
|
if (filteredOptions.length === 0) {
|
|
166
166
|
return [];
|
|
167
167
|
}
|
|
168
|
-
|
|
168
|
+
let filtered = filter(filteredOptions, params);
|
|
169
169
|
const { inputValue } = params;
|
|
170
170
|
const inputValueSlug = (0, utils_1.slugify)(inputValue);
|
|
171
|
+
const inputValueLength = inputValueSlug.length;
|
|
171
172
|
// Suggest the creation of a new value
|
|
172
|
-
const isExisting = filteredOptions.
|
|
173
|
+
const isExisting = filteredOptions.find((option) => inputValueSlug === (0, utils_1.slugify)(option.label));
|
|
173
174
|
if (inputValue !== '' && !isExisting) {
|
|
174
175
|
filtered.push({
|
|
175
176
|
inputValue,
|
|
176
177
|
label: `Criar "${inputValue}"`,
|
|
177
178
|
});
|
|
178
179
|
}
|
|
180
|
+
// Show first the exact match:
|
|
181
|
+
if (isExisting) {
|
|
182
|
+
filtered = [
|
|
183
|
+
isExisting,
|
|
184
|
+
...filtered.filter((option) => isExisting.id !== option.id),
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
// Show first the options that start with inputValue:
|
|
188
|
+
const startsWith = filtered.filter((option) => inputValueSlug ===
|
|
189
|
+
(0, utils_1.slugify)(option.label).substring(0, inputValueLength));
|
|
190
|
+
if (startsWith.length > 0) {
|
|
191
|
+
const startsWithIds = startsWith.map((option) => option.id);
|
|
192
|
+
filtered = [
|
|
193
|
+
...startsWith,
|
|
194
|
+
...filtered.filter((option) => !startsWithIds.includes(option.id)),
|
|
195
|
+
];
|
|
196
|
+
}
|
|
179
197
|
return filtered;
|
|
180
198
|
}, handleHomeEndKeys: true, getOptionLabel: getOptionLabel
|
|
181
199
|
? getOptionLabel
|
package/package.json
CHANGED