material icon indicating copy to clipboard operation
material copied to clipboard

<md-select> add setting to stop handle keydown event

Open dmaslov opened this issue 11 years ago • 7 comments

Hi! Is it possible to add a setting to <md-select> directive to stop handle keydown event?

The issue is that I have a select with search input to filter option items. When I press a button, input loses focus and cursor moves to matched option in the list. I want to prevent that behavior. Or maybe there is more elegant way to do what I want? Thanks in advance!

My code:

<md-select multiple ng-model="selectedItems">
  <md-input-container>
    <input type="text" ng-model="search">
  </md-input-container>
  <md-option ng-repeat="item in items | filter:search" ng-value="item.id">{{ item.value }}</md-option>
</md-select>

dmaslov avatar Aug 19 '15 15:08 dmaslov

@dmaslov -- Did you find a way to handle this? I'm running in to the same issue.

holly-weisser avatar Sep 03 '15 15:09 holly-weisser

@holly-weisser

Yes. The main thing is ng-keydown with stopPropagation in handler. Let me know if you need the full implementation (i am using custom wrapper over Angular and i need to convert my code to common view to make it understandable)

<md-select>
  <md-input-container>
    <input ng-model="controller.filterQuery" ng-keydown="controller.onSearchChange($event)">
  </md-input-container>
  <md-option ng-repeat="item in controller.items track by item.id" ng-value="item.id">
</md-select>
controller.onSearchChange = function($event) {
  $event.stopPropagation();
  // Here you could use default Angular filter service, or use your own implementation of filter function
  this.items = functionToFilterItemsByQuery(this.filterQuery);
}

dmaslov avatar Sep 04 '15 09:09 dmaslov

Awesome, thank you!

holly-weisser avatar Sep 04 '15 12:09 holly-weisser

hello. i have tried adding $event.stopPropagation(); but still it does not stops the keydown event in the md-select. you have idea on this?

hsiri avatar Apr 04 '16 05:04 hsiri

@hsiri I faced the same issue as you just a couple of hours before where I made a silly mistake. I guess you might also put ng-keydown directive at the wrong element? It should be on <input>, not on <md-select> itself. 😛

kavare avatar May 29 '16 00:05 kavare

@kavare fixed this already. anyways, thanks for informing

hsiri avatar May 29 '16 09:05 hsiri

ng-keydown="$event.stopPropagation()"

felipemangalo avatar Mar 30 '17 13:03 felipemangalo