The <select> dropdown with <option> children
The <select> dropdown with <option> children.
Try it: focus it and press Enter or Space to open, then arrows to choose.
cpp
// Copyright 2026 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
//
// The <select> dropdown with <option> children.
//
// Try it: focus it and press Enter or Space to open, then arrows to choose.
#include <rtxui/rtxui.hpp>
#include <string>
#include <string_view>
using namespace rtxui;
class SelectDemo : public Component<SelectDemo> {
public:
std::string theme = "light";
std::string_view view = R"html(
<div class="card">
<h1>Select</h1>
<p>Focus it, press Enter or Space to open, arrows to choose.</p>
<select value="{theme}">
<option value="dark">Dark theme</option>
<option value="light">Light theme</option>
<option value="solarized">Solarized</option>
</select>
<div class="readout">
<span>value</span>
<span class="value">{theme}</span>
</div>
</div>
<style>
self {
--border: rgb(48, 54, 61);
--muted: rgb(139, 148, 158);
--accent: rgb(88, 166, 255);
display: flex;
align-items: center;
justify-content: center;
width: 100%;
color: rgb(230, 237, 243);
}
.card {
border: tall;
border-color: var(--border);
background-color: rgb(22, 27, 34);
padding: 1 3;
width: 50;
}
h1 {
color: var(--accent);
}
p {
color: var(--muted);
}
select {
border: tall;
border-color: var(--border);
background-color: rgb(13, 17, 23);
padding: 0 1;
width: 100%;
}
select:focus {
border-color: var(--accent);
}
.readout {
display: flex;
justify-content: space-between;
border-top: solid;
border-color: var(--border);
margin-top: 1;
padding-top: 1;
color: var(--muted);
}
.value {
color: var(--accent);
font-weight: bold;
}
</style>
)html";
SelectDemo() { Bind(theme); }
};
int main() {
auto app = Ref<SelectDemo>::New();
Screen screen(app);
screen.Loop();
return 0;
}- Source file:
example/select.cpp - Standalone terminal: ⛶ Open Fullscreen
- Guide: Relevant Documentation
- ← Back to Examples Index

