Skip to content

Commit

Permalink
fix: combobox primary button click (#1165)
Browse files Browse the repository at this point in the history
* combobox primary button click

* Add example
  • Loading branch information
jmarkowski committed Aug 23, 2019
1 parent 13b069c commit 0ad23e9
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 4 deletions.
Expand Up @@ -16,13 +16,24 @@ <h2>Custom Filter</h2>
</component-example>
<code-example [exampleFiles]="comboboxDynamicExample"></code-example>

<separator></separator>
<h2>Custom Search Function</h2>
<description>
Custom search function can be provided by <code>[searchFunction]</code> to combobox. It will be called on mouse
click on combobox's primary button, or on enter key press, while focused on combobox input.
</description>
<component-example [name]="'ex3'">
<fd-combobox-search-function-example></fd-combobox-search-function-example>
</component-example>
<code-example [exampleFiles]="comboboxSearchFunctionExample"></code-example>

<separator></separator>
<h2>Display Object Property</h2>
<description>
Passing object arrays to the Combobox is supported through the <code>displayFn</code> input function. To
access the <code>this</code> keyword inside the passed function, use an arrow function.
</description>
<component-example [name]="'ex3'">
<component-example [name]="'ex4'">
<fd-combobox-displaywith-example></fd-combobox-displaywith-example>
</component-example>
<code-example [exampleFiles]="comboboxDisplayExample"></code-example>
Expand All @@ -36,7 +47,7 @@ <h2>Observable Async Example</h2>
<description>
This example also demonstrates how to create a callback function from data returned by the observable.
</description>
<component-example [name]="'ex4'">
<component-example [name]="'ex5'">
<fd-combobox-async-example></fd-combobox-async-example>
</component-example>
<code-example [exampleFiles]="comboboxAsyncExample"></code-example>
Expand All @@ -47,7 +58,7 @@ <h2>Custom Item Template</h2>
The way the items are rendered in the popover list can be customized through providing an <code>itemTemplate</code>
to the component.
</description>
<component-example [name]="'ex5'">
<component-example [name]="'ex6'">
<fd-combobox-template-example></fd-combobox-template-example>
</component-example>
<code-example [exampleFiles]="comboboxTemplateExample"></code-example>
Expand Up @@ -10,6 +10,8 @@ import * as comboboxDisplayHtml from '!raw-loader!./examples/combobox-displaywit
import * as comboboxDisplayTs from '!raw-loader!./examples/combobox-displaywith-example.component.ts';
import * as comboboxTemplateH from '!raw-loader!./examples/combobox-template-example.component.html';
import * as comboboxTemplateT from '!raw-loader!./examples/combobox-template-example.component.ts';
import * as comboboxSeaTs from '!raw-loader!./examples/combobox-search-function-example.component.ts';
import * as comboboxSeaHtml from '!raw-loader!./examples/combobox-search-function-example.component.html';
import { ExampleFile } from '../../core-helpers/code-example/example-file';

@Component({
Expand Down Expand Up @@ -40,6 +42,17 @@ export class ComboboxDocsComponent {
}
];

comboboxSearchFunctionExample: ExampleFile[] = [
{
language: 'html',
code: comboboxSeaHtml
},
{
language: 'typescript',
code: comboboxSeaTs
}
];

comboboxAsyncExample: ExampleFile[] = [
{
language: 'html',
Expand Down
@@ -0,0 +1,7 @@
<fd-combobox [(ngModel)]="searchTerm"
[dropdownValues]="dropdownValues"
[searchFunction]="customSearchFunction"
[placeholder]="'Type to filter the list...'">
</fd-combobox>
<br/>
<span>Search Term: {{searchTerm}}</span>
@@ -0,0 +1,24 @@
import { Component } from '@angular/core';

@Component({
selector: 'fd-combobox-search-function-example',
templateUrl: 'combobox-search-function-example.component.html'
})
export class ComboboxSearchFunctionExampleComponent {

searchTerm: string = '';

dropdownValues = [
'Apple',
'Pineapple',
'Banana',
'Kiwi',
'Strawberry'
];

customSearchFunction: Function = () => {
alert('Custom Function Called');
};


}
2 changes: 2 additions & 0 deletions docs/app/documentation/documentation.module.ts
Expand Up @@ -399,6 +399,7 @@ import { RadioFormGroupExampleComponent } from './component-docs/radio/examples/
import { RadioExamplesComponent } from './component-docs/radio/examples/radio-examples.component';
import { RadioDocsComponent } from './component-docs/radio/radio-docs.component';
import { RadioHeaderComponent } from './component-docs/radio/radio-header/radio-header.component';
import { ComboboxSearchFunctionExampleComponent } from './component-docs/combobox/examples/combobox-search-function-example.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -637,6 +638,7 @@ import { RadioHeaderComponent } from './component-docs/radio/radio-header/radio-
ComboboxAsyncExampleComponent,
ComboboxDisplaywithExampleComponent,
ComboboxDynamicExampleComponent,
ComboboxSearchFunctionExampleComponent,
ComboboxExampleComponent,
ComboboxTemplateExampleComponent,
LoadingSpinnerDocsComponent,
Expand Down
3 changes: 2 additions & 1 deletion library/src/lib/combobox/combobox.component.html
Expand Up @@ -19,7 +19,8 @@
type="button"
[fdType]="'light'"
[glyph]="glyph"
[disabled]="disabled">
[disabled]="disabled"
(click)="onPrimaryButtonClick()">
</button>
</span>
</div>
Expand Down
7 changes: 7 additions & 0 deletions library/src/lib/combobox/combobox.component.ts
Expand Up @@ -234,6 +234,13 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit, OnChange
this.displayedValues = this.filterFn(this.dropdownValues, this.inputText);
}

/** @hidden */
onPrimaryButtonClick(): void {
if (this.searchFunction) {
this.searchFunction();
}
}

private defaultDisplay(str: any): string {
return str;
}
Expand Down

0 comments on commit 0ad23e9

Please sign in to comment.