CamoSelect
Concept
1. Why
A select lets the user pick one value from a list: a country, a category, a payment method. It looks like a text field (label, value, supporting/error text) and opens a picker. Your Flutter convention already names the right shape: never DropdownButton, but a select field that opens a picker sheet, with async variants for options loaded from an API. CamoSelect makes that the standard, and adds a compact menu presentation for short lists on wide windows.
2. Shape
SelectPresentation.Auto (the default) chooses:
- a Menu when there are 7 or fewer options on a wide window (at least 600) or with a pointer;
- a Sheet otherwise (phones, long lists, searchable, async).
Material mapping preview: M3 exposed dropdown menu. The field is the outlined text field with a trailing ▾ in onSurfaceVariant. The menu matches CamoMenu, and the sheet matches CamoBottomSheet with CamoListItem rows.
3. API
Contract
fun <T> CamoSelect(
value: T?,
onValueChange: (T) -> Unit,
options: List<SelectOption<T>>,
label: String? = null,
placeholder: String? = null,
supportingText: String? = null,
error: String? = null,
presentation: SelectPresentation = Auto, // Auto | Menu | Sheet
searchable: Boolean = false, // a search field at the top of the sheet
prefixIcon: Widget? = null,
enabled: Boolean = true,
)
data class SelectOption<T>(val value: T, val label: String, val supporting: String? = null,
val leading: Widget? = null, val enabled: Boolean = true)
// async: options from an API, controlled like CamoPagedList (ADR-29)
fun <T> CamoAsyncSelect(
value: T?, onValueChange: (T) -> Unit,
options: CamoPagedListState<SelectOption<T>>, // the same state type as CamoPagedList
onOpen: () -> Unit, // load the first page when the picker opens
onQueryChange: (String) -> Unit, // debounced by the component (SelectTheme.searchDebounce)
onLoadMore: () -> Unit, onRetry: () -> Unit,
onRefresh: (() -> Unit)? = null,
selectedLabel: String?, // the label for the current value (options may not be loaded yet)
label: String? = null, /* … same field parameters … */
)
// inside a form: CamoSelectFormField<T>(key, initialValue, rules, options, …)
State → renderer: the field reuses the text-field renderer (TextFieldState with a read-only value and a chevron suffix), the menu reuses MenuRenderer, and the sheet reuses BottomSheetRenderer + ListItemRenderer. There's no separate select renderer, so a skin gets CamoSelect for free.
Tokens used
It uses the tokens of the text field, menu, bottom sheet and list item. SelectTheme only adds presentation rules.
Component theme
theme.components.select: SelectTheme?. Every field is nullable in the theme. The skin's defaults(theme) fills whatever isn't set (Material defaults shown). See Theme §3.10.
| Field | Type | Material default | What it's for |
|---|---|---|---|
autoMenuMaxOptions | Int | 7 | the largest list shown as a menu in Auto |
autoMenuMinWidth | Dp | 600 | the window width from which Auto may use a menu |
showCheckOnSelected | Boolean | true | a check mark on the current option in the picker |
searchDebounce | Duration | 500 ms | the delay before onQueryChange fires (async select) |
Accessibility
- The field is announced as a combo box / pop-up button: "Country, Indonesia, pop-up button, collapsed".
- The opened menu or sheet follows those components' accessibility. The current option is marked selected.
- Keyboard: Enter/Space/Down opens it. In the menu, type-ahead jumps to options. Esc closes without changing.
erroris linked and announced as on the text field.
4. Build steps
CamoSelectfield (read-only text-field frame + chevron, open/close, semantics).- Menu presentation (the
CamoMenupopup) and sheet presentation (the sheet frame + list + optionalCamoSearchField). Autorules fromSelectTheme.CamoAsyncSelect: the sheet's list is aCamoPagedListfed byoptions; the component only debounces the query and forwards callbacks. It never fetches (the author'sCoreAsyncSelectDelegatepattern).CamoSelectFormField.- Sample: country (searchable sheet), sort order (menu), a city from an API (async).
- Tests:
- picking sets the value;
Autochooses menu vs sheet by width and count;- search filters;
- async:
onOpenfires on open, the query is debounced, and loading, next-page and error states come fromoptions; - Esc keeps the old value;
- announcements.
Done when
- All three samples work on phones (sheet) and desktop (menu), by touch, keyboard and screen reader.
5. Edge cases
| Case | Decided behavior |
|---|---|
value not in options | The field shows value.toString() (or selectedLabel for async). A debug warning is logged. |
| Multi-select | Not in v1. It would be a later CamoMultiSelect, with chips in the field. |
| Async errors | Rendered by the picker's CamoPagedList (first-page error with Retry, or a retry row). The field keeps its value. |
| Very long option labels | They wrap in the sheet, and ellipsize in the field (the full value is in semantics). |
- There's no select renderer, so
SelectStyle's defaults are core's (7 options, 600 wide, check on, 500 ms) andSelectThemeoverrides them; it also gainsstrings(search placeholder, "No results"). - The chevron is
TextFieldTheme.dropdownIcon, so a brand's field theme styles it; the sheet's check isMenuTheme.checkIcon. Autodecides by window width and option count only, and asearchableselect is always a sheet.- The menu always marks the current option, since a radio item needs its check to be announced;
showCheckOnSelectedapplies to the sheet's rows. - The menu is at least as wide as the field.
- The async select's sheet always has a search field, and
onOpenfires once each time it opens.
Implementation
1. Why
CamoSelect has no renderer of its own: it composes core pieces. Kotlin's job is the wiring: a read-only field built on the text-field frame, the Auto choice between a menu and a sheet from the window size, and CamoAsyncSelect driven by a controlled CamoPagedListState (ADR-29), with the query debounced in the component.
2. Shape
3. API
@Composable
public fun <T> CamoSelect(
value: T?,
onValueChange: (T) -> Unit,
options: List<SelectOption<T>>,
modifier: Modifier = Modifier,
label: String? = null, placeholder: String? = null,
supportingText: String? = null, error: String? = null,
presentation: SelectPresentation = SelectPresentation.Auto,
searchable: Boolean = false,
prefixIcon: (@Composable () -> Unit)? = null,
enabled: Boolean = true,
)
@Composable
public fun <T> CamoAsyncSelect(
value: T?,
onValueChange: (T) -> Unit,
options: CamoPagedListState<SelectOption<T>>,
onOpen: () -> Unit,
onQueryChange: (String) -> Unit,
onLoadMore: () -> Unit,
onRetry: () -> Unit,
selectedLabel: String?,
modifier: Modifier = Modifier,
onRefresh: (() -> Unit)? = null,
label: String? = null, /* … the same field parameters … */
)
@Composable public fun <T> CamoSelectFormField(key: String, options: List<SelectOption<T>>, initialValue: T? = null,
rules: List<CamoRule<T?>> = emptyList(), label: String? = null /* … */)
- The field:
CamoFieldFrame(label, supportingText, error, prefixIcon, suffixIcon = chevron, focused = open || hasFocus, isEmpty = value == null)around aCamoTextof the selected label. The whole field isclickable(role = Role.DropdownList)withsemantics { stateDescription = if (open) "expanded" else "collapsed" }. - Auto:
LocalWindowInfo.current.containerSizeconverted withLocalDensity; a menu when the width is at leaststyle.autoMenuMinWidthandoptions.size <= style.autoMenuMaxOptions, otherwise a sheet. - Menu:
CamoMenuAnchor(items = options.map { CamoMenuItem(it.label, checked = it.value == value, …) })inside an exclusiveCamoMenuGroup, so the current option is announced as selected. - Sheet: a standalone
CamoSheetFrame(open state is internal to the select), title =label,searchableadds aCamoSearchFieldfiltering by label (case- and accent-insensitive viaNormalizer-free folding of the common Latin accents). - Async:
LaunchedEffect(open) { if (open) onOpen() }; the search text is debounced withsnapshotFlow { query }.debounce(style.searchDebounce).collect(onQueryChange); the sheet's list is aCamoPagedListoveroptions. - Keyboard: Enter, Space or Down on the field opens; the menu or sheet handles its own keys; closing returns focus to the field.
4. Build steps
- The field on
CamoFieldFrame, open state, andSelectTheme/SelectStyle. - Menu and sheet presentations,
Auto. CamoAsyncSelectwith debounce andCamoPagedList;CamoSelectFormField.commonTest: picking sets the value and closes;Autochooses by width and count (a fakeWindowInfo); search filters; async callsonOpenonce per open and debouncesonQueryChange; Esc keeps the old value; focus returns to the field.
Done when
- Country (searchable sheet), sort order (menu on desktop), and a city from a fake paged API (async) work on every target by touch, keyboard and screen reader.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Window resized while open | The current presentation stays until it closes; the next open re-evaluates Auto. |
| Configuration change on Android | open and the search text use rememberSaveable; the sheet reopens after rotation. |
Async selectedLabel missing while options load | The field shows value.toString() and logs once in debug. |
- The field is the date field's read-only
PickerFieldFrame, which gainsprefixIconand amodifierfor the select's semantics (stateDescription"Expanded"/"Collapsed") and Down to open. SelectTheme.searchDebounceMillis: Int, like the tooltip delays.AutoreadsLocalWindowInfo.current.containerSize, so tests fake a narrow window by providing aWindowInfo.CamoSelectFormField(options, modifier, key, …)follows the other form fields' parameter order.