gwt-material icon indicating copy to clipboard operation
gwt-material copied to clipboard

MaterialDropDown: can't trigger the dropdown programmatically

Open gilberto-torrezan opened this issue 10 years ago • 5 comments

Consider this environment: a MaterialIcon inside a MaterialCollapsibleHeader, which shows options in the MaterialDropDown for the selected item when clicked (something like Google Inbox).

In this environment, when clicking on the icon, the header is activated and the MaterialCollapsible opens. But that's not the desired effect: when clicking on the icon, only the dropdown with the options should appear, without changing the state of the collapsible.

To avoid that, we can add a click handler to the icon, get the event and prevents its propagation (by calling event.stopPropagation()). That stops the MaterialCollapsible from opening... but now we have to trigger the dropdown manually.

@UiHandler("options")
void onOptionsClicked(ClickEvent e){
    e.stopPropagation();
    //open dropdown, since the icon was clicked
} 

And that's the main issue. Using the public API of the component, there's no way to do that. Even the Element activatorElem field can't be set directly.

My suggestion is to expose public methods on MaterialDropDown to either:

  • allow the user to directly set the activatorElem, skipping the DOMHelper.getElementByAttribute part;
  • manually open the dropdown at any time, like what can be done with modal dialogs

Of course those changes doesn't mean the current behaviour should change. It's just another way to use the same component.

gilberto-torrezan avatar Nov 25 '15 22:11 gilberto-torrezan

Yeah I agree we should expand this functionality. Perhaps providing the ability to pass in a jQuery scope(context) element for finding the activator or setting the activator manually.

BenDol avatar Nov 26 '15 00:11 BenDol

I need to open the MaterialDropdown by calling a method to do so (on Java, not UiBinder). Currently I'm using the standard PopupPanel from GWT (which opens by calling center() or showRelativeTo(component)).

The example above was to justify why do I need to call that from Java without using the activator feature (in this case, to prevent the event from propagating). But it could be outside collapsible items: a dynamic generated popup could not be created by using UiBinder and activators, for example.

gilberto-torrezan avatar Dec 01 '15 00:12 gilberto-torrezan

Yeah I agree, I am now adding a manual show/close of material dropdown will be available end of today.

On Tue, Dec 1, 2015 at 8:54 AM Gilberto Torrezan [email protected] wrote:

I need to open the MaterialDropdown by calling a method to do so (on Java, not UiBinder). Currently I'm using the standard PopupPanel from GWT (which opens by calling center() or showRelativeTo(component)).

The example above was to justify why do I need to call that from Java without using the activator feature (in this case, to prevent the event from propagating). But it could be outside collapsible items: a dynamic generated popup could not be created by using UiBinder and activators, for example.

— Reply to this email directly or view it on GitHub https://github.com/GwtMaterialDesign/gwt-material/issues/168#issuecomment-160811962 .

kevzlou7979 avatar Dec 01 '15 02:12 kevzlou7979

We just talk with @BenDol It will be nice if we submit a feature request direct to Materializecss , please follow this request https://github.com/Dogfalo/materialize/issues/2403 , I hope they will develop it .

kevzlou7979 avatar Dec 01 '15 03:12 kevzlou7979

This has been added to the latest materializecss sources, next update will be possible.

BenDol avatar Aug 05 '16 00:08 BenDol