Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions projects/components/src/multi-select/multi-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import { MultiSelectJustify } from './multi-select-justify';
<div class="multi-select-content" [ngStyle]="{ 'min-width.px': triggerContainer.offsetWidth }">
<ng-container *ngIf="this.enableSearch">
<ng-container *ngIf="this.allOptions$ | async as allOptions">
<ng-container *ngIf="allOptions.length > 5">
<ng-container *ngIf="!this.enableImplicitOptionsSearch || allOptions.length > 5">
<ht-search-box
class="search-bar"
(valueChange)="this.searchOptions($event)"
Expand All @@ -78,7 +78,7 @@ import { MultiSelectJustify } from './multi-select-justify';

<ht-button
class="select-all"
*ngIf="!this.isAnyOptionSelected()"
*ngIf="allOptions.length > 0 && !this.isAnyOptionSelected()"
role="${ButtonRole.Primary}"
display="${ButtonStyle.Text}"
label="Select All"
Expand Down Expand Up @@ -136,6 +136,9 @@ export class MultiSelectComponent<V> implements AfterContentInit, OnChanges {
@Input()
public enableSearch: boolean = false;

@Input()
public enableImplicitOptionsSearch: boolean = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we took a page out of the table api (hah!) and took in some like a searchProvider object instead. We could default it to a client side version, but provide a server implementation in other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh god. let me check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds complicated. Can we do it with just may be a searchMode enum (Implicit and external)? I think eventually, we would have a separate basic filter multi select component, but we need this as a stepping stone.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK looked at multiselect - the search provider wouldn't work as well because the data is actually coming in as content children vs an array like some of the other components, so an output is the only way that comes to mind to accomplish this - but let's clean up the ambiguity between the two enable search inputs as you mentioned.

Copy link
Contributor Author

@anandtiwary anandtiwary Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so does this look good?

@Input()
public enableSearch: boolean = false;

@Input()
public searchMode: MultiSelectSearchMode = MultiSelectSearchMode.Implicit;

...


export const enum MultiSelectSearchMode {
  Implicit = 'implicit',
  External = 'external'
}

Copy link
Contributor

@aaron-steinfeld aaron-steinfeld Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather boil down another input and make the enum values more explicit, but same idea:

@Input()
public searchMode: MultiSelectSearchMode = MultiSelectSearchMode.Disabled;
@Output
public searchValueChange: EventEmitter<string> = new EventEmitter<string>();

...

export const enum MultiSelectSearchMode {
  Disabled = 'disabled', // Search is not available
  CaseInsensitive = 'case-insensitive', // Current available values are filtered in a case insensitive way and an emit is triggered
  EmitOnly = 'emit-only' // Current available values not filtered, but an emit still triggered
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool.


@Input()
public justify: MultiSelectJustify = MultiSelectJustify.Left;

Expand All @@ -145,6 +148,9 @@ export class MultiSelectComponent<V> implements AfterContentInit, OnChanges {
@Output()
public readonly selectedChange: EventEmitter<V[]> = new EventEmitter<V[]>();

@Output()
public readonly optionsSearchChange: EventEmitter<string> = new EventEmitter<string>();

@ContentChildren(SelectOptionComponent)
private readonly allOptionsList?: QueryList<SelectOptionComponent<V>>;
public allOptions$!: Observable<QueryList<SelectOptionComponent<V>>>;
Expand All @@ -170,7 +176,11 @@ export class MultiSelectComponent<V> implements AfterContentInit, OnChanges {
}

public searchOptions(searchText: string): void {
this.searchSubject.next(searchText);
if (!this.enableImplicitOptionsSearch) {
this.optionsSearchChange.emit(searchText);
} else {
this.searchSubject.next(searchText);
}
}

public onSelectAll(): void {
Expand Down