ember-power-select icon indicating copy to clipboard operation
ember-power-select copied to clipboard

Public API to trigger focus

Open bjornharrtell opened this issue 6 years ago • 4 comments
trafficstars

bjornharrtell avatar Oct 02 '19 13:10 bjornharrtell

Care to explain a bit more?

cibernox avatar Oct 05 '19 13:10 cibernox

This is tied to https://github.com/cibernox/ember-power-select/issues/1284 and as mentioned it might only make sense when customizing so that the trigger and search component are combined into one.

The use case I have in mind is that after a user has chosen an option, the next natural step might be to populate the search component and focus it so that the user can further refine the search (without manually focusing the search component again).

bjornharrtell avatar Oct 05 '19 14:10 bjornharrtell

We have two power selects next to each other. We used to autofocus the second one after the first one was filled in using

    const trigger = document.querySelectorAll(`#${this.elementId} .ember-power-select-trigger`)[0];
    const event = document.createEvent('Event');
    event.initEvent('mousedown', true, true);
    if (trigger) {
      trigger.dispatchEvent(event);
    }

But this is no longer possible. Is there an alternative way I might be able to accomplish a programmatic shift of focus?

erikmellum avatar Mar 17 '20 23:03 erikmellum

Old way was deprecated https://developer.mozilla.org/en-US/docs/Web/API/Event/initEvent. Fixed with:

const evt = new MouseEvent('click', {
      bubbles: true,
      cancelable: true,
      view: window,
    });
    if (trigger) {
      trigger.dispatchEvent(evt);
    }

erikmellum avatar Mar 26 '20 21:03 erikmellum