ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
Dropdown.hpp File Reference

A select-style dropdown with a popup list. More...

#include "Common.hpp"
#include "Layout.hpp"
#include "Button.hpp"
#include "Text.hpp"
#include "ScrollView.hpp"

Go to the source code of this file.

Classes

class  ZenitUI::UI::Dropdown
 A single-select dropdown. More...

Detailed Description

A select-style dropdown with a popup list.

The dropdown is a Vertical container with two children:

  1. A Button (class "dropdown-trigger") whose label shows the currently selected option.
  2. A ScrollView (portal) that contains one Label (class "dropdown-item") per option.

The list is always a portal, so it draws above everything else and is not clipped by ancestors. It is shown / hidden by toggling its enabled flag and opacity, and its size is computed dynamically in arrange from the available space below the trigger, with automatic flip above if there is not enough room.

Interaction:

  • Click on the trigger toggles the list.
  • Click on an item selects it and closes the list.
  • Click outside the trigger and list closes the list.
  • Escape closes the list when open and restores previous focus.
  • Up / Down navigate options when the dropdown has focus and the list is open; Down also opens the list from the closed state.
  • Enter / Space toggle the list.
Note
setSelected fires onChange even when the index is unchanged. This differs from the usual "only fire on change" convention but is relied upon by some tests (Dropdown_basic.setSelected_same_value_fires_onChange).