Skip to content

Commit

Permalink
fix(search bar): fix clear button and missing deps
Browse files Browse the repository at this point in the history
  • Loading branch information
cbourget committed Mar 24, 2017
1 parent 193d879 commit 7f58664
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
}
}
],
"addons": [
"assets/fonts/*.+(otf|eot|svg|ttf|woff|woff2)"
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
Expand Down
Binary file added demo-app/assets/fonts/MaterialIcons-Regular.eot
Binary file not shown.
Binary file added demo-app/assets/fonts/MaterialIcons-Regular.ttf
Binary file not shown.
Binary file added demo-app/assets/fonts/MaterialIcons-Regular.woff
Binary file not shown.
Binary file added demo-app/assets/fonts/MaterialIcons-Regular.woff2
Binary file not shown.
40 changes: 39 additions & 1 deletion demo-app/styles.styl
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
@import '~@angular/material/core/theming/prebuilt/deeppurple-amber.css';
@import '~@angular/material/core/theming/prebuilt/deeppurple-amber.css';

@font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url(./assets/fonts/MaterialIcons-Regular.eot); /* For IE6-8 */
src: local('Material Icons'),
local('MaterialIcons-Regular'),
url(./assets/fonts/MaterialIcons-Regular.woff2) format('woff2'),
url(./assets/fonts/MaterialIcons-Regular.woff) format('woff'),
url(./assets/fonts/MaterialIcons-Regular.ttf) format('truetype');
}

.material-icons {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px;
display: inline-block;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
white-space: nowrap;
direction: ltr;

/* Support for all WebKit browsers. */
-webkit-font-smoothing: antialiased;
/* Support for Safari and Chrome. */
text-rendering: optimizeLegibility;

/* Support for Firefox. */
-moz-osx-font-smoothing: grayscale;

/* Support for IE. */
font-feature-settings: 'liga' 1;
-ms-font-feature-settings: 'liga' 1;
}
14 changes: 8 additions & 6 deletions lib/search/search-bar/search-bar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
[placeholder]="placeholder"
[ngModel]="term"
(keyup)="keyup($event)">
<button
md-icon-button
(click)="clear()"
*ngIf="term">
<md-icon>clear</md-icon>
</button>
</md-input-container>

<button
md-icon-button
[color]="buttonColor"
(click)="clear()"
*ngIf="term.length > 0 ? true : false">
<md-icon>clear</md-icon>
</button>
16 changes: 15 additions & 1 deletion lib/search/search-bar/search-bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class SearchBarComponent implements OnInit, OnDestroy {
set term(value: string) {
this._term = value;
}
private _term: string;
private _term: string = '';

@Input()
get placeholder() { return this._placeholder; }
Expand All @@ -33,6 +33,13 @@ export class SearchBarComponent implements OnInit, OnDestroy {
}
private _disabled: boolean = false;

@Input()
get buttonColor() { return this._buttonColor; }
set buttonColor(value: string) {
this._buttonColor = value;
}
private _buttonColor: string = 'primary';

@Input()
get debounce() { return this._debounce; }
set debounce(value: number) {
Expand Down Expand Up @@ -73,12 +80,19 @@ export class SearchBarComponent implements OnInit, OnDestroy {
if (this.disabled) { return; }

const term = (event.target as HTMLInputElement).value;
this.term = term;

if (this.keyIsValid(term) &&
(term.length >= this.length || term.length === 0)) {
this._stream$.next(term);
}
}

clear() {
this.term = '';
this._stream$.next(this.term);
}

private keyIsValid(key: string) {
return this._invalidKeys.find(value => value === key) === undefined;
}
Expand Down

0 comments on commit 7f58664

Please sign in to comment.