ember-power-select
ember-power-select copied to clipboard
Public API to trigger focus
Care to explain a bit more?
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).
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?
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);
}