Close Dropdown when user clicks outside of it #335
Replies: 1 comment
-
The Dropdown + InputManager scripts under Nova\Sample\UIControls behave this way. You can play around with it yourself in the To step through the implementation in code, look for references to Another option would be using the "background" click target approach as you describe, and have your Dropdown controls subscribe to Gesture.OnClick or Gesture.OnPress events, depending on your preferred behavior, on the Root UIBlock (accessible via // subscribe to press events on the UIBlock hierarchy root (assuming a connected UIBlock hierarchy)
uiBlock.Root.AddGestureHandler<Gesture.OnPress>(HandleSomethingPressed);
...
private void HandleSomethingPressed(Gesture.OnPress evt)
{
if (evt.Receiver.transform.IsChildOf(transform))
{
// something within the dropdown hierarchy
// was pressed, so we don't want to (necessarily)
// collapse in that case, and we'll handle the new
// option selected in a different event handler
return;
}
// pointer down outside the dropdown hierarchy, so collapse the dropdown.
Collapse();
} Beyond that, there are many variations of either approach (or some combination of the two) to implement this functionality, so we'll defer to you to choose what works best for your project/code structure. Going to mark this as "Feature Added" since the out-of-box examples already support this :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
First of all, not sure this is feasible since it would likely involve intertwining Unity and Nova input systems. In most UI, you can close an open dropdown by clicking outside of that dropdown. However since Nova only registers clicks on UIBlocks, I'm not sure how you could interpret an "outside UI" click apart from making a giant UIBlock that encompasses the "background" of your screen space.
Maybe that's a viable solution, though?
Beta Was this translation helpful? Give feedback.
All reactions