Ember-power-select: e.preventDefault() in onopen handler does not prevent opening

Created on 12 Apr 2016  路  2Comments  路  Source: cibernox/ember-power-select

If I handle the onopen action, and call e.preventDefault, the dropdown still opens.

Example. In my case I want to prevent clicks on the select box from opening the options list.

{{#power-select-multiple
   ...
  options=(readonly items)
  opened=false
  onopen=(action "opened")
   ...
  as |item|
}}
...
...
    opened(select, e) {
      if(e.type === 'mousedown')  {
        e.preventDefault();      // this does not work
        select.actions.close();  // this does work
      }
    },
...
bug

All 2 comments

@Ramblurr Yes, I understand that this is confusing, but at the moment onopen is more a hook than an event. It doesn't happen when the component is about to open but when the component has been already opened.

I think that this is probably wrong and I'm going to change it

@Ramblurr Fixed in master.

At the moment there is two ways of preventing the dropdown from opening/close: return false or calling preventDefault on the event. I'm not sure if I'll keep both ways in the future, but if I only keep one it will be return false.

Use that for safety.

Was this page helpful?
0 / 5 - 0 ratings