-
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
Conversation
* 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 comment
The reason will be displayed to describe this comment to others. Learn more.
So calling the input autocomplete
can make it misleading about what it actually does since the autocomplete
part is technically an add-on to the mdInput
.
I think we should call the property allowAdd
or something like this since later on we can possibly add later on an allowRemove
which can enable/disable the x
buttons from the chips.
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.
Will do I will make the change to allowAdd and the one bellow.Thanks!
Also, can you fix the lint issues? 😄 |
@emoralesb05 updated autoComplete to allowAdd and fixed the lint issue. Does the dependency-ci check take a while or is that a manual thing? |
Not sure why it hangs when its a PR from a fork 🤔 .. but dont worry about it haha 😄 Awesome dude! Gonna test the PR tonight 🎉 |
@@ -9,6 +9,7 @@ | |||
</md-icon> | |||
</md-basic-chip> | |||
</ng-template> | |||
<div *ngIf="allowAdd"> | |||
<md-input-container floatPlaceholder="never" |
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">
? 😄
There is a need to check for e.g.
|
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
There is a weird bug when you toggle the allowAdd
to false and then back to true, once you focus the input
the autocomplete doesnt appear until you type on it.
The fix is to put the md-autocomplete
out of the <div *ngIf="allowAdd">
so its added as soon as the md-input
is rendered without affecting the autocomplete rendering.
e. g.
<div *ngIf="allowAdd">
<md-input-container floatPlaceholder="never"
[style.width.px]="readOnly ? 0 : null"
[color]="matches ? 'primary' : 'warn'">
<input mdInput
flex="100"
#input
[mdAutocomplete]="autocomplete"
[formControl]="inputControl"
[placeholder]="readOnly? '' : placeholder"
(keydown)="_inputKeydown($event)"
(keyup.enter)="addChip(input.value)"
(focus)="handleFocus()"
(blur)="handleBlur()">
</md-input-container>
</div>
<md-autocomplete #autocomplete="mdAutocomplete">
<ng-template let-item ngFor [ngForOf]="filteredItems | async">
<md-option (click)="addChip(input.value)" [value]="item">{{item}}</md-option>
</ng-template>
</md-autocomplete>
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.
When I move the md-autocomplete
outside <div *ngIf="allowAdd">
it breaks the ability add chips, the input.value is undefined. One way to get around this to visually with CSS hide it rather than removing it from the DOM with *ngIf. Let me know if this is acceptable otherwise I can look into an alternative.
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.
The alternative approach would be to change (click)="addChip(input.value)
to (click)="addChip(item)
. I might be wrong but for the click event wouldn't this be a little more concise to match the available list if we are only allowing the items in the list array anyway? Of course the input is a different thing but I don't see any errors and the focus event works as excepted when toggling from false back to true.
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.
Yeah, I think it should use addChip(item)
either way to be more consistent.
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.
cool thanks!
Sounds good I'll make the changes and push again. Thanks! |
…k to inputChild focus
small thing, but for the API should |
Also, if the input is disabled, the |
this would have an
|
@kyleledbetter the reason i wanted to call it The ng1 chips called it |
ok maybe it should be |
Sure, I can make the changes. To be clear when you say chipRemoval does that mean when the user clicks on one of the chip list items when typing in autocomplete is the expected behavior to remove from the selected/filtered list rather than add to the selected/filtered list? If so does there need to be a toggle to add them back? |
@kyleledbetter @emoralesb05 I pushed the change to hide the |
@JoshSchoen ill create an issue later with the specifications of how Merging this for now. Nice work dude! 💥 |
Description
Feature Request: Turn off autocomplete for chips #500
What's included?
Test Steps
Manual Test
General Tests for Every PR
ng serve --aot
still works.npm run lint
passes.npm test
passes and code coverage is not lower.npm run build
still works.Screenshots or link to CodePen/Plunker/JSfiddle