Ember-power-select: Trigger dropdown from js

Created on 27 May 2016  路  3Comments  路  Source: cibernox/ember-power-select

Hello.

Great component, however, quite rigid.
How can I trigger dropdown from js?
I have custom placeholder with z-index > than trigger and I want to trigger dropdown openning by invoking the action. I haven't found any native thing like "dropdownOpened" which might simplify many things.

This isn't working btw:

  triggerDropdown() {
      run(this, function() {
        this.$('.ember-basic-dropdown-trigger').mousedown();
      });
    },

Most helpful comment

Yes, that is a simper solution. For the record, the problem with your code above is that you are using jQuery. jQuery event's are very bad citizens and do not trigger native event handlers (those added with element.addEventListener('mousedown', fn).

The native event works.

 triggerDropdown() {
      run(this, function() {
        $('.ember-basic-dropdown-trigger').get(0).dispatchEvent(new MouseEvent('mousedown')); 
      });
    },

All 3 comments

pointer-events: none;
fixes the thing :)

Yes, that is a simper solution. For the record, the problem with your code above is that you are using jQuery. jQuery event's are very bad citizens and do not trigger native event handlers (those added with element.addEventListener('mousedown', fn).

The native event works.

 triggerDropdown() {
      run(this, function() {
        $('.ember-basic-dropdown-trigger').get(0).dispatchEvent(new MouseEvent('mousedown')); 
      });
    },

@cibernox is this still the recommended way to trigger the opening of a power-select from an external ember action (eg in reaction to clicking a button)? I realize that use case doesn't fit super cleanly into ember's DDAU paradigm (without forcing code using the component to reflect all it's internal state changes), but resorting to triggering a synthetic DOM event seems a bit...messy

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhujy8833 picture zhujy8833  路  10Comments

nhemanth007 picture nhemanth007  路  10Comments

jorkas picture jorkas  路  8Comments

luketheobscure picture luketheobscure  路  10Comments

zidjian257 picture zidjian257  路  6Comments