material icon indicating copy to clipboard operation
material copied to clipboard

md-on-select on md-chips gets called twice due to keyboard selection

Open vshanbha opened this issue 10 years ago • 5 comments

I have a md-chips with an internal md-autocomplete used to search for chips asynchronously from server. I also have a method calls associated with md-on-select. In the sample given below inside the

                        <md-chips ng-model="ctrl.selectedChips" md-autocomplete-snap
                                md-transform-chip="ctrl.transformChip($chip)"
                                md-on-select="selectChip($chip)"
                                md-on-add="addChip($chip)"
                                md-on-remove="removeChip($chip)"
                                md-require-match="true">
                            <md-autocomplete
                                md-selected-item="ctrl.selectedItem"
                                md-search-text="ctrl.searchText"
                                md-items="item in ctrl.chipSearch(ctrl.searchText)"
                                md-item-text="item.text"
                                placeholder="+ text">
                                <span md-highlight-text="ctrl.searchText">{{item.text}}</span>
                            </md-autocomplete>
                            <md-chip-template>
                                <span>{{$chip.text}}</span>
                            </md-chip-template>
                        </md-chips>

content of selectChip

selectChip() { 
console.log('selected');
}

Everytime I use keyboard (arrow or backspace) to perform selection the selectChip() gets called twice. Whereas if I click on a chip using mouse the same method only gets called once. I have some logic that should only be run once each time the user selects a chip. This seems like a bug. However if I have made a mistake in my configuration, happy to change. Please suggest.

vshanbha avatar Mar 12 '16 17:03 vshanbha

You are right. If I click the chip the method only get called once but using key-board keys including delete the method gets call twice. +1

Nextt1 avatar Mar 12 '16 21:03 Nextt1

@vshanbha Can you please convert your code above into an actual Codepen so that we can debug it a bit and find the root cause? Thanks!

topherfangio avatar Mar 16 '16 19:03 topherfangio

@topherfangio Here is a minimal code that recreates that issue. http://codepen.io/vshanbha/pen/zqNZbq

vshanbha avatar Mar 17 '16 09:03 vshanbha

@vshanbha Perfect; thanks!

topherfangio avatar Mar 17 '16 16:03 topherfangio

This issue is closed as part of our ‘Surge Focus on Material 2' efforts. For details, see our forum posting @ http://bit.ly/1UhZyWs.

ThomasBurleson avatar Jun 02 '16 07:06 ThomasBurleson