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

Manually close dropdown?

Open Glarregle opened this issue 5 years ago • 1 comments

Hey!, thanks for the great work here :)

Is there a way of closing the dropdown from the outside? I'm trying to open/close the dropdown from a wrapper component.

I can open it dispatching a mousedown event, but closing it is not possible. When the second mousedown event is triggered the dropdown is first rapidly closed and then opened again. Is this intermediate closing caused by blur event? I didn't get any output when debugging onBlur action/event.

Thanks!

Glarregle avatar Jul 27 '19 03:07 Glarregle

@Glarregle dispatching a mousedown from the outside works, but there's also another way.

The select has a registerAPI property in the component that will be invoked when the component is instantiated and also on every internal state change. If you get hold of a reference to that object you can use it to control the select remotely from the outisde. Example:

<PowerSelect @selected={{selected}} @onChange={{action (mut selected)}} @registerAPI={{action (mut selectRemoteControl)}} as |opt|>
  {{opt}}
</PowerSelect>

Then you can, from your code, do something like:

onSomeOtherButtonClick() {
  this.selectRemoteControl.actions.close()
}

cibernox avatar Jul 29 '19 19:07 cibernox