Skip to content

Dropdown

extends Collection

Dropdown: collapsed selection row that expands to an item list. Fires "select"; closes on selection, on toggle, or when focus moves away.

Properties

PropertyTypeDefaultDescription
textany"Select..."placeholder while nothing is selected
dropHeightnumber6maximum visible list rows
offsetnumber0list scroll offset
backgroundnumber|falsecolors.grayBackground color (false = transparent)
dropBackgroundnumbercolors.blackopen list background
widthnumber14Width in terminal cells
scrollbarItemViewScrollbarMode"auto""auto", "always" or "hidden"
scrollbarColornumbercolors.grayScrollbar track color
scrollbarThumbColornumbercolors.lightGrayScrollbar thumb color
heightnumberdynamicFollows the open state; setting it explicitly breaks expansion
openbooleanfalseWhether the list is expanded; the element floats above siblings while open

Methods

Returns the scrollbar geometry of the open list.

  • returns geometry (ItemViewGeometry) The itemview geometry

Scrolls the open list to an absolute offset (clamped).

  • offset (number) Items scrolled past above the viewport

  • returns (self)

Scrolls the given item index into the visible list area.

  • index (number) The item index to make visible

  • returns (self)

Selects an item, closes the list and fires the select event.

  • index (integer) The item index to select

  • emit (boolean, optional) false suppresses the select event

  • returns (self)

Initializes per-instance state and input handlers.

Removes all entries and resets selection, scroll and open state.

  • returns (self)

Removes an entry and clamps the dropdown scroll offset.

  • index (integer|CollectionEntry) Item index or entry

  • returns (self)

Routes mouse input in local coordinates (wheel scrolling etc.).

  • event (string) The mouse event name

  • btn (number) Button or scroll direction

  • x (number) Local x coordinate

  • y (number) Local y coordinate

  • returns consumer (Element|nil) The consuming element, or nil to pass through

Handles keyboard input while focused.

  • event (string) The key event name (key, key_up, char, paste)
  • a (any) Key code or typed text
  • b (any, optional) Secondary key-event value

Renders the element into the buffer.

  • buf (Render) The render buffer (local coordinates, pre-clipped)

Last updated:

Released under the MIT License.