Trigger focus from an action
See original GitHub issueI am not sure if I am doing this wrong, or if this just isn’t supported. I have an action in the component and I would like this action to open and set focus to the ember-power-select element.
When I focus the element, by tabbing or clicking it the onfocus does fire. However, when I use the jquery trigger from the focusSearch() action: power select does not get focus, nor does the onfocus handler fire. I have tried grabbing the classes assocuated with other divs and no luck.
Is there a way to trigger it to open from an action and I am just doing it wrong?
Component.hbs
{{#power-select class='ls-search-box' options=searchList selected=selected onfocus=(action "onfocus") as |item| }} ...
Component.js
actions: { focusSearch(){ //console.log('focus Search'); var input = Ember.$(".ls-search-box ember-power-select-trigger"); if(input) {input.focus();} }, onfocus(){ console.log('onfocus'); },
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (3 by maintainers)
Top GitHub Comments
@brancusi Yes, there is cleaner ways.
If the only thing you want to do is to render the component open initially, you can pass
initiallyOpened=true
. In your example that is enough.If what you want to do is open or close the component after it has been rendered, there is another way that is not public API yet, but it will be soon, although maybe with a different name. The select accepts an action named
registerAPI
(I might change that name, but the idea will remain) that will be invoked with an instance of the public API that you can grab and store somewhere to use it as a “remote controller” of the componen later on.Then in your code
For other people looking for this, the correct way to access the publicAPI is:
as described by @cibernox in https://github.com/cibernox/ember-power-select/issues/549#issuecomment-227229404