cibernox / ember-power-select

The extensible select component built for ember.
http://www.ember-power-select.com
Other
541 stars 379 forks source link

Backspace in multiple-select doesn't clear entire item #969

Open drewcovi opened 6 years ago

drewcovi commented 6 years ago

Is it by design that backspace on a multiple-select converts pills into text? Many other libraries adopt a pattern of removing the entire pill.

cibernox commented 6 years ago

Yes, it is. But I took select2 as role model for this. Buy you can change it if you want

drewcovi commented 6 years ago

@cibernox how can i change it? you mean just fork it? or is this configurable?

cibernox commented 6 years ago

Ember Power Select is pretty customizable. By example, you can achieve the behaviour you want using only public API.

If you want to customize what the component does when the user presses a key, you can pass onkeydown=(action "yourCustomAction") and do whatever you want.

In this example:

{{#power-select-multiple options=options selected=selected onchange=(action (mut selected)) onkeydown=(action "handleKeydown") as |opt|}}
  {{opt}}
{{/power-select-multiple}}
  actions: {
    handleKeydown(select, e) {
      if (e.keyCode === 8 && Ember.isBlank(e.target.value)) { // press backspace on empty searchbox
        select.actions.select(select.selected.slice(0, select.selected.length - 1), e); // remove last selection
        return false; // prevent usual default behavior
      }
    } 
  }

You can see a twiddle here: https://ember-twiddle.com/42c561f23fc4184e143048813dda3ae7?openFiles=controllers.application.js%2C