Skip to content

Commit ee7bd72

Browse files
authored
feat: remove create option when empty searchString (#859)
1 parent 0495b2d commit ee7bd72

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

projects/components/src/combo-box/combo-box.component.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
ViewChildren
1515
} from '@angular/core';
1616
import { IconType } from '@hypertrace/assets-library';
17-
import { DomElementScrollIntoViewService, TypedSimpleChanges } from '@hypertrace/common';
17+
import { DomElementScrollIntoViewService, isNonEmptyString, TypedSimpleChanges } from '@hypertrace/common';
1818
import { isNil } from 'lodash-es';
1919
import { IconSize } from '../icon/icon-size';
2020
import { PopoverRef } from '../popover/popover-ref';
@@ -208,10 +208,18 @@ export class ComboBoxComponent<TValue = string> implements AfterViewInit, OnChan
208208
searchText === undefined
209209
? this.options ?? []
210210
: (this.options ?? []).filter(option => option.text.toLowerCase().includes(searchText.toLowerCase()));
211-
this.createOption = this.provideCreateOption ? this.buildCreateOption(searchText ?? '') : undefined;
211+
this.createOption = this.isShowCreateOption(searchText) ? this.buildCreateOption(searchText) : undefined;
212212
this.setHighlightedOptionIndex();
213213
}
214214

215+
private isShowCreateOption(searchText?: string): searchText is string {
216+
return (
217+
this.provideCreateOption &&
218+
isNonEmptyString(searchText) &&
219+
this.filteredOptions.find(option => option.text === searchText) === undefined
220+
);
221+
}
222+
215223
private setText(text: string = ''): void {
216224
if (text !== this.text) {
217225
this.text = text;

0 commit comments

Comments
 (0)