Skip to content

fix: translate dropdown_m2 events and keys onto the canonical Dropdown - #28

Merged
AdamMusa merged 2 commits into
mainfrom
fix/dropdown-m2-wire
Oct 29, 2026
Merged

AdamMusa merged 2 commits into
mainfrom
fix/dropdown-m2-wire

Conversation

@AdamMusa

Copy link
Copy Markdown
Owner

Fixes QA finding #6. Companion engine PR: AdamMusa/ruflet-engine#10 (same branch, fix/dropdown-m2-wire).

The bug

Since b9e52ff, dropdown, dropdown_m2 and dropdownm2 all build PlatformControlContracts::Components::DropdownControl and send "_c": "Dropdown". That contract accepts the union of the Dropdown and Material 2 keywords. So dropdownm2(on_change: h) was accepted, but it registered a "change" handler and sent on_change: true. Both Dropdown renderers fire "select" (Material material_dropdown.dart:315, Cupertino cupertino_input_controls.dart:118), so the handler never ran on any platform. Material 2 spellings such as max_menu_height and select_icon were also sent under keys the Dropdown renderers don't read.

Decision: (b), keep the canonical Dropdown wire type and translate

The owner deliberately routed DropdownM2 onto the canonical Dropdown, so restoring a DropdownM2 wire type (option a) would undo his design:

  • b9e52ff rewrote the DSL as def dropdown_m2(options = nil, **props) = dropdown(options, **props). It also mapped %w[dropdown dropdown_m2 dropdownm2] => Components::DropdownControl in platform_control_contracts.rb, whose header says the schemas "deliberately accept the union of the Material and Cupertino properties: Ruby describes intent and the platform renderer decides how that intent looks".
  • b9e52ff added test_legacy_design_names_are_protocol_aliases_not_renderer_choices, asserting Ruflet.dropdown_m2([]) emits "Dropdown". Nearby comments say so too: "Compatibility aliases only. They emit the same canonical wire types … and never select the visual renderer" (control_methods.rb) and "There is no design-system choice in this API" (platform_control_methods.rb).
  • In the engine, "DropdownM2": "Dropdown" sits in control_type.dart under "Legacy and transitional protocol names … new SDKs emit only the canonical names".
  • Dropdown2Control (WIRE = "Dropdown") can't be reached from the DSL at all. Option (a) would have meant reverting the class map, the DSL method and the owner's test.

The fix follows the owner's later contract fix 34f95e7 ("fix: preserve typed dates in canonical picker DSL"): it normalizes inside the platform contract.

Change

Components::DropdownControl (used by dropdown, dropdown_m2, dropdownm2):

  • MATERIAL2_RENAMES: on_change → on_select, max_menu_height → menu_height, prefix_icon → leading_icon, select_icon → trailing_icon. These are exact equivalents read by the Dropdown renderers. Passing a Material 2 key together with its Dropdown spelling raises ArgumentError.
  • normalized_event_name maps change to select, so on(:change) { }, has_handler?(:change) and emit("change") work too. The handler receives the select event (event.name == "select", event.value is the chosen key).
  • MATERIAL2_UNSUPPORTED_KEYWORDS explicitly documents the other 35 Material 2 keywords. They are still accepted and sent, so existing dropdown_m2 code keeps loading, but neither Dropdown renderer draws them (and on_click never fires): align_label_with_hint alignment collapsed counter counter_style disabled_hint_content enable_feedback error error_max_lines fit_parent_size focus_color focused_bgcolor focused_color helper helper_max_lines hint_content hint_fade_duration hint_max_lines icon item_height options_fill_horizontally padding prefix prefix_icon_size_constraints prefix_style select_icon_disabled_color select_icon_enabled_color select_icon_size size_constraints suffix suffix_icon suffix_icon_size_constraints suffix_style text_vertical_align on_click. A test keeps this list plus the renames equal to Dropdown2Control::KEYWORDS - DropdownControl::KEYWORDS.

KEYWORDS are unchanged.

dropdownm2(
  [dropdown_option("red", text: "Red"), dropdown_option("blue", text: "Blue")],
  value: "red",
  hint_text: "Color",
  max_menu_height: 240,             # sent as menu_height
  select_icon: "arrow_drop_down",   # sent as trailing_icon
  on_change: ->(e) { puts e.value } # sent as on_select; runs on "select"
)

Tests

  • dropdown_compatibility_test.rb, 5 new tests:
    • on_change fires on a dispatched select, updates value, and sends on_select (not on_change).
    • A later on(:change) fires on select.
    • The renames match the canonical spellings.
    • Passing both spellings is rejected.
    • The documented list is exhaustive, and unsupported keys still serialize.
  • control_coverage_test.rb test_dropdown_m2_serializes_options_and_value now also asserts the on_change handler is registered, on_select is on the wire, and hint_content / max_menu_height serialize.
  • platform_control_contract_test.rb is unchanged and still passes (dropdown_m2 emits Dropdown).
  • No embedded-runtime regeneration, as with 34f95e7.

Verification

verify_pr.sh <engine> <ruby> (Flutter 3.41.2, Ruby 4.0.5): RESULT: PASS

  • ruflet_core: 145/145 files, 623 runs (baseline 618)
  • engine packages/ruflet flutter test: +702, all passed (baseline 695)
  • flutter analyze lib test: no issues
  • wire-key audit: 0 new findings vs baseline. not-read 147 → 141, near-miss 43 → 36 (hint_content, disabled_hint_content and both *_icon_size_constraints now read)

dropdown_m2 has emitted the canonical Dropdown since b9e52ff, but its
`on_change` handler was registered for a "change" event that the Dropdown
renderers never fire (they fire "select"), so it never ran on any platform.

Rename the Material 2 spellings that have a Dropdown equivalent (on_change,
max_menu_height, prefix_icon, select_icon) to the keys both renderers read,
map later `on(:change)` handlers to "select", and list the Material 2
keywords the Dropdown renderers do not draw.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant