Skip to content

Commit

Permalink
[docs] Do not show 'Add' if user input matches existing option (#24333)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramdog committed Jan 10, 2021
1 parent df073cd commit f8b846b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ export default function FreeSoloCreateOption() {
filterOptions={(options, params) => {
const filtered = filter(options, params);

const { inputValue } = params;
// Suggest the creation of a new value
if (params.inputValue !== '') {
const isExisting = options.some((option) => inputValue === option.title);
if (inputValue !== '' && !isExisting) {
filtered.push({
inputValue: params.inputValue,
title: `Add "${params.inputValue}"`,
inputValue,
title: `Add "${inputValue}"`,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ export default function FreeSoloCreateOption() {
filterOptions={(options, params) => {
const filtered = filter(options, params);

const { inputValue } = params;
// Suggest the creation of a new value
if (params.inputValue !== '') {
const isExisting = options.some((option) => inputValue === option.title);
if (inputValue !== '' && !isExisting) {
filtered.push({
inputValue: params.inputValue,
title: `Add "${params.inputValue}"`,
inputValue,
title: `Add "${inputValue}"`,
});
}

Expand Down

0 comments on commit f8b846b

Please sign in to comment.