Skip to main content

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.

FieldTypeMaterial defaultWhat it's for
autoMenuMaxOptionsInt7the largest list shown as a menu in Auto
autoMenuMinWidthDp600the window width from which Auto may use a menu
showCheckOnSelectedBooleantruea check mark on the current option in the picker
searchDebounceDuration500 msthe 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.
  • error is linked and announced as on the text field.

4. Build steps​

  1. CamoSelect field (read-only text-field frame + chevron, open/close, semantics).
  2. Menu presentation (the CamoMenu popup) and sheet presentation (the sheet frame + list + optional CamoSearchField).
  3. Auto rules from SelectTheme.
  4. CamoAsyncSelect: the sheet's list is a CamoPagedList fed by options; the component only debounces the query and forwards callbacks. It never fetches (the author's CoreAsyncSelectDelegate pattern).
  5. CamoSelectFormField.
  6. Sample: country (searchable sheet), sort order (menu), a city from an API (async).
  7. Tests:
    • picking sets the value;
    • Auto chooses menu vs sheet by width and count;
    • search filters;
    • async: onOpen fires on open, the query is debounced, and loading, next-page and error states come from options;
    • 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​

CaseDecided behavior
value not in optionsThe field shows value.toString() (or selectedLabel for async). A debug warning is logged.
Multi-selectNot in v1. It would be a later CamoMultiSelect, with chips in the field.
Async errorsRendered by the picker's CamoPagedList (first-page error with Retry, or a retry row). The field keeps its value.
Very long option labelsThey wrap in the sheet, and ellipsize in the field (the full value is in semantics).
Changed in the M6 build (2026-10-28)
  • There's no select renderer, so SelectStyle's defaults are core's (7 options, 600 wide, check on, 500 ms) and SelectTheme overrides them; it also gains strings (search placeholder, "No results").
  • The chevron is TextFieldTheme.dropdownIcon, so a brand's field theme styles it; the sheet's check is MenuTheme.checkIcon.
  • Auto decides by window width and option count only, and a searchable select is always a sheet.
  • The menu always marks the current option, since a radio item needs its check to be announced; showCheckOnSelected applies 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 onOpen fires 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 a CamoText of the selected label. The whole field is clickable(role = Role.DropdownList) with semantics { stateDescription = if (open) "expanded" else "collapsed" }.
  • Auto: LocalWindowInfo.current.containerSize converted with LocalDensity; a menu when the width is at least style.autoMenuMinWidth and options.size <= style.autoMenuMaxOptions, otherwise a sheet.
  • Menu: CamoMenuAnchor(items = options.map { CamoMenuItem(it.label, checked = it.value == value, …) }) inside an exclusive CamoMenuGroup, so the current option is announced as selected.
  • Sheet: a standalone CamoSheetFrame (open state is internal to the select), title = label, searchable adds a CamoSearchField filtering by label (case- and accent-insensitive via Normalizer-free folding of the common Latin accents).
  • Async: LaunchedEffect(open) { if (open) onOpen() }; the search text is debounced with snapshotFlow { query }.debounce(style.searchDebounce).collect(onQueryChange); the sheet's list is a CamoPagedList over options.
  • 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​

  1. The field on CamoFieldFrame, open state, and SelectTheme / SelectStyle.
  2. Menu and sheet presentations, Auto.
  3. CamoAsyncSelect with debounce and CamoPagedList; CamoSelectFormField.
  4. commonTest: picking sets the value and closes; Auto chooses by width and count (a fake WindowInfo); search filters; async calls onOpen once per open and debounces onQueryChange; 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​

CaseDecided behavior
Window resized while openThe current presentation stays until it closes; the next open re-evaluates Auto.
Configuration change on Androidopen and the search text use rememberSaveable; the sheet reopens after rotation.
Async selectedLabel missing while options loadThe field shows value.toString() and logs once in debug.
Changed in the M6 build (2026-10-28)
  • The field is the date field's read-only PickerFieldFrame, which gains prefixIcon and a modifier for the select's semantics (stateDescription "Expanded"/"Collapsed") and Down to open.
  • SelectTheme.searchDebounceMillis: Int, like the tooltip delays.
  • Auto reads LocalWindowInfo.current.containerSize, so tests fake a narrow window by providing a WindowInfo.
  • CamoSelectFormField(options, modifier, key, …) follows the other form fields' parameter order.