-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(chips): ability to disable chip addition (input). (closes #500) #547
Changes from 6 commits
9b1fbd0
1d19cde
4c5d6ba
43bb340
bcb3145
f55d200
fc1e306
61d029e
fd1d598
e5a3cf2
f13979a
296dd60
f9c8338
b9e084e
d661d1a
4e1fe5a
cfa7d62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
</md-icon> | ||
</md-basic-chip> | ||
</ng-template> | ||
<div *ngIf="autoComplete"> | ||
<md-input-container floatPlaceholder="never" | ||
[style.width.px]="readOnly ? 0 : null" | ||
[color]="matches ? 'primary' : 'warn'"> | ||
|
@@ -23,11 +24,13 @@ | |
(focus)="handleFocus()" | ||
(blur)="handleBlur()"> | ||
</md-input-container> | ||
|
||
<md-autocomplete #autocomplete="mdAutocomplete"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a weird bug when you toggle the The fix is to put the e. g.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I move the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The alternative approach would be to change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think it should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cool thanks! |
||
<ng-template let-item ngFor [ngForOf]="filteredItems | async"> | ||
<md-option (click)="addChip(input.value)" [value]="item">{{item}}</md-option> | ||
</ng-template> | ||
</md-autocomplete> | ||
</div> | ||
</md-chip-list> | ||
<div class="mat-input-underline" | ||
[class.mat-disabled]="readOnly"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,7 @@ export class TdChipsComponent implements ControlValueAccessor, DoCheck, OnInit { | |
* Enables Autocompletion with the provided list of strings. | ||
*/ | ||
@Input('items') items: string[] = []; | ||
|
||
|
||
/** | ||
* requireMatch?: boolean | ||
|
@@ -79,6 +80,8 @@ export class TdChipsComponent implements ControlValueAccessor, DoCheck, OnInit { | |
return this._requireMatch; | ||
} | ||
|
||
|
||
|
||
/** | ||
* readOnly?: boolean | ||
* Disables the chips input and chip removal icon. | ||
|
@@ -96,6 +99,12 @@ export class TdChipsComponent implements ControlValueAccessor, DoCheck, OnInit { | |
return this._readOnly; | ||
} | ||
|
||
/** | ||
* autoComplete?: boolean | ||
* Disables autocomplete. If it doesn't exist autocomplete defaults to true. | ||
*/ | ||
@Input('autoComplete') autoComplete: boolean = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So calling the input I think we should call the property There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do I will make the change to allowAdd and the one bellow.Thanks! |
||
|
||
/** | ||
* placeholder?: string | ||
* Placeholder for the autocomplete input. | ||
|
@@ -227,6 +236,7 @@ export class TdChipsComponent implements ControlValueAccessor, DoCheck, OnInit { | |
case DELETE: | ||
case BACKSPACE: | ||
/** Check to see if input is empty when pressing left arrow to move to the last chip */ | ||
|
||
if (!this._inputChild.value) { | ||
this._focusLastChip(); | ||
event.preventDefault(); | ||
|
@@ -257,7 +267,7 @@ export class TdChipsComponent implements ControlValueAccessor, DoCheck, OnInit { | |
* Checks if deleting last single chip, to focus input afterwards | ||
* Else check if its not the last chip of the list to focus the next one. | ||
*/ | ||
if (index === (this._totalChips - 1) && index === 0) { | ||
if (index === (this._totalChips - 1) && index === 0 && this.autoComplete) { | ||
this.focus(); | ||
} else if (index < (this._totalChips - 1)) { | ||
this._focusChip(index + 1); | ||
|
@@ -267,20 +277,22 @@ export class TdChipsComponent implements ControlValueAccessor, DoCheck, OnInit { | |
break; | ||
case LEFT_ARROW: | ||
/** Check to see if left arrow was pressed while focusing the first chip to focus input next */ | ||
if (index === 0) { | ||
if (index === 0 && this.autoComplete) { | ||
this.focus(); | ||
event.stopPropagation(); | ||
} | ||
break; | ||
case RIGHT_ARROW: | ||
/** Check to see if right arrow was pressed while focusing the last chip to focus input next */ | ||
if (index === (this._totalChips - 1)) { | ||
if (index === (this._totalChips - 1) && this.autoComplete) { | ||
this.focus(); | ||
event.stopPropagation(); | ||
} | ||
break; | ||
case ESCAPE: | ||
if (this.autoComplete) { | ||
this.focus(); | ||
} | ||
break; | ||
default: | ||
// default | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add indentation for the content of the
<div *ngIf="allowAdd">
? 😄