Skip to content
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

Merged
merged 17 commits into from
May 5, 2017

Conversation

JoshSchoen
Copy link
Contributor

@JoshSchoen JoshSchoen commented May 3, 2017

Description

Feature Request: Turn off autocomplete for chips #500

What's included?

  • modified: src/platform/core/chips/chips.component.ts
  • modified: src/platform/core/chips/chips.component.html
  • modified: src/app/components/components/chips/chips.component.html
  • modified: src/app/components/components/chips/chips.component.ts

Test Steps

Manual Test

  • edit src/app/components/components/chips/chips.component.ts
  • Change autocomplete to false
  • Save
  • Navigate to http://localhost:4200/#/components/chips
  • Make sure autocomplete is disabled under Chips & Autocomplete
  • edit src/app/components/components/chips/chips.component.html
  • Remove [autoComplete]="autoComplete"
  • Save
  • Navigate to http://localhost:4200/#/components/chips
  • Make sure autocomplete is enabled under Chips & Autocomplete

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

auto-complete-chips

@emoralesb05 emoralesb05 changed the title Feature/chips feat(chips): ability to disable chip addition (input). (closes #500) May 3, 2017
* autoComplete?: boolean
* Disables autocomplete. If it doesn't exist autocomplete defaults to true.
*/
@Input('autoComplete') autoComplete: 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.

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.

Copy link
Contributor Author

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!

@emoralesb05
Copy link
Contributor

emoralesb05 commented May 3, 2017

Also, can you fix the lint issues? 😄

@JoshSchoen
Copy link
Contributor Author

@emoralesb05 updated autoComplete to allowAdd and fixed the lint issue. Does the dependency-ci check take a while or is that a manual thing?

@emoralesb05
Copy link
Contributor

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 🎉

@emoralesb05 emoralesb05 added this to the Beta 4 milestone May 3, 2017
@@ -9,6 +9,7 @@
</md-icon>
</md-basic-chip>
</ng-template>
<div *ngIf="allowAdd">
<md-input-container floatPlaceholder="never"
Copy link
Contributor

@emoralesb05 emoralesb05 May 4, 2017

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">? 😄

@emoralesb05
Copy link
Contributor

There is a need to check for allowAdd in the focus() since it fails when focusing it when allowAdd is false.

e.g.

focus(): void {
    if (this.allowAdd) {
      this._inputChild.focus();
    }
}

@@ -23,11 +24,13 @@
(focus)="handleFocus()"
(blur)="handleBlur()">
</md-input-container>

<md-autocomplete #autocomplete="mdAutocomplete">
Copy link
Contributor

@emoralesb05 emoralesb05 May 4, 2017

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>

Copy link
Contributor Author

@JoshSchoen JoshSchoen May 4, 2017

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.

Copy link
Contributor Author

@JoshSchoen JoshSchoen May 4, 2017

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.

Copy link
Contributor

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.

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 thanks!

@JoshSchoen
Copy link
Contributor Author

Sounds good I'll make the changes and push again. Thanks!

@kyleledbetter
Copy link
Contributor

small thing, but for the API should allowAdd be named something more like addChips? or since the real goal is disabling the input should it be more like disableInput?

@kyleledbetter
Copy link
Contributor

Also, if the input is disabled, the .mat-input-underline should be hidden, since underline is to imply that there's an input text field

@kyleledbetter
Copy link
Contributor

this would have an *ngIf conditional on it

<div class="mat-input-underline"

@emoralesb05
Copy link
Contributor

emoralesb05 commented May 4, 2017

@kyleledbetter the reason i wanted to call it allowAdd is because after this there will be an addition of allowRemove. So its a cleaner API when you state what you are enabling/disabling in either case as an action, not as an internal component.

The ng1 chips called it md-removable, but they didnt have a sense of disabling the add since they used it as a mix of readOnly and md-removable i think

@kyleledbetter
Copy link
Contributor

ok maybe it should be chipAddition and we can also add a flag to allow the removal of chips chipRemoval

@JoshSchoen
Copy link
Contributor Author

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?

@JoshSchoen
Copy link
Contributor Author

@kyleledbetter @emoralesb05 I pushed the change to hide the .mat-input-underline and allowAdd to chipAddition I figured it's probably best to get that out of the way and do another PR for chipRemoval Let me know about the question in my last comment about expected chipRemoval behavior and I can take that on as well. Let me know if there is anything else. Thx!

@emoralesb05
Copy link
Contributor

@JoshSchoen ill create an issue later with the specifications of how chipRemoval should work.

Merging this for now. Nice work dude! 💥

@emoralesb05 emoralesb05 merged commit 1c75d35 into Teradata:develop May 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants