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

Feature Request: Turn off autocomplete for chips #500

Closed
JoshSchoen opened this issue Apr 12, 2017 · 1 comment
Closed

Feature Request: Turn off autocomplete for chips #500

JoshSchoen opened this issue Apr 12, 2017 · 1 comment

Comments

@JoshSchoen
Copy link
Contributor

JoshSchoen commented Apr 12, 2017

feature

Feature Request: Turn off autocomplete for chips

Currently, chips are only available with autocomplete, while this a great feature sometimes it can be overkill for curtain use cases.

Example Template HTML

<td-chips placeholder="Enter string"
[autoComplete]="autoComplete"
[items]="items"
[(ngModel)]="model"
[readOnly]="readOnly"
(add)="add($event)"
(remove)="remove($event)"
requireMatch>
</td-chips>

where the autoComplete is type boolean to turn on or off the auto complete feature. [autoComplete]="autoComplete"

chips.component.html

<div *ngIf="autoComplete">    
<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>
    <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>
    </div>

chips.component.ts

  /**
   * autoComplete?: boolean
   * disables autocomplete on chips.
   * Defaults to 'true' or autocomplete enabled.
   */
  @Input('autoComplete') autoComplete: boolean = true;
Example

chips-example

@emoralesb05 emoralesb05 added this to the Beta 4 (maybe RC?) milestone Apr 12, 2017
@JoshSchoen
Copy link
Contributor Author

Looks like there also needs to be a check if autoComplete is enabled in the _chipKeydown method whenever this.focus() is called 4 total.

Example

      case LEFT_ARROW:
        /** Check to see if left arrow was pressed while focusing the first chip to focus input next */
        if (index === 0 && this.autoComplete) {
          this.focus();
          event.stopPropagation();
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants