angular-mdc-web icon indicating copy to clipboard operation
angular-mdc-web copied to clipboard

Input chip usage example?

Open gpulido opened this issue 4 years ago • 10 comments

I'm trying to use a set of chips as input chips, but after reviewing the documentation I'm not sure of how it works or make it work with an input text field. Reading the documentation upstream it specifically says:

The MDC Chips package does not handle the process of converting text into chips, in order to remain framework-agnostic.

I can understand that, but angular-mdc is not framework-agnostic so I guess it should have to provide the mechanism (or some guidelines) to do it.

I can add a text field an catch the input keydowns to "addchip", but I can't figure out how to show the chipset inside the input / text-field on a similar way that angular material is doing.

Any suggestion / idea / guide on how to do it?

gpulido avatar Mar 04 '20 22:03 gpulido

Good suggestion. We're missing sample usage for using chips as inputs. See if I can come up with a quick demo for ya.

trimox avatar Mar 05 '20 12:03 trimox

Hey @trimox, hope you are doing well. Any updates on this one ?

westdabestdb avatar Mar 16 '20 12:03 westdabestdb

@gpulido @westdabestdb Sorry for the delay. I began to review material docs and got side tracked with the Bazel upgrade #1983 (took bit more effort than anticipated). Lemme circle back tomorrow.

trimox avatar Mar 17 '20 01:03 trimox

Tested and working on a proper solution for this.

trimox avatar Mar 19 '20 11:03 trimox

Awesome @trimox !

westdabestdb avatar Mar 29 '20 14:03 westdabestdb

Btw, I managed to handle it on my own, I can post the code and screenshots here if you want?

westdabestdb avatar Mar 30 '20 10:03 westdabestdb

@westdabestdb it would be awesome if you can provide some insight to this. thank you!

gpulido avatar Mar 31 '20 21:03 gpulido

Shit dude @gpulido, I totally forgot to reply this. I apologize. Here check the screenshots and code. Screen Shot 2020-04-04 at 12 37 05 AM Screen Shot 2020-04-04 at 12 37 14 AM Screen Shot 2020-04-04 at 12 37 24 AM

<div class="search">
    <div class="leading-search">
      <mdc-icon class="search-icon">search</mdc-icon>
    </div>
    <mdc-chip-set input *ngIf="inputs.length > 0">
      <mdc-chip *ngFor="let query of inputs">
        <mdc-chip-text class="font">{{query}}</mdc-chip-text>
        <mdc-chip-icon trailing>cancel</mdc-chip-icon>
      </mdc-chip>
    </mdc-chip-set>
    <input class="font" #query placeholder="Search by term, skill or company" type="text" (keyup.enter)="handleInput(query.value); query.value = ''" />
    <div *ngIf="inputs.length > 0" class="reset-search" (click)="clearQueries()">
      <mdc-icon>clear</mdc-icon>
    </div>
  </div>

So basically my search class is flex, and has white background color. My input has transparent background color, and I display the chips when inputs.length > 0. It's a bit tricky way to achieve this but yeah, it works till we get a better example.

westdabestdb avatar Apr 03 '20 21:04 westdabestdb

@westdabestdb Thanks for the code, would you mind completing it with the css /sass classes and the #query management code on the ts file?

Now I have to make it work with an autocomplete mode to pick values from a list.

gpulido avatar Apr 11 '20 16:04 gpulido

@gpulido any update on documentation ?

k11k2 avatar May 29 '20 14:05 k11k2