Skip to content

feat: add Stepper control - #41

Merged
AdamMusa merged 2 commits into
mainfrom
feat/stepper
Nov 2, 2026
Merged

AdamMusa merged 2 commits into
mainfrom
feat/stepper

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Adds the Ruby side of Stepper and its Step child type (Work Package F, item F1).

Engine counterpart (renderer): AdamMusa/ruflet-engine#25

Usage

wizard = stepper(
  steps: [stepper_step(title: "Account", content: text_field(label: "Email")),
          stepper_step(title: "Address", content: text_field(label: "Street")),
          stepper_step(title: "Confirm", content: text("Review and submit"))],
  on_step_tap: ->(e) { page.update(wizard, current_step: e.value) },
  on_step_continue: ->(e) { page.update(wizard, current_step: [e.value + 1, 2].min) },
  on_step_cancel: ->(e) { page.update(wizard, current_step: [e.value - 1, 0].max) })

# block children work too (they are sent as `controls`)
stepper(type: "horizontal", height: 400) do
  stepper_step(title: "One", state: "complete", is_active: true)
  stepper_step(title: "Two", subtitle: "Optional", label: "2")
end

API

  • controls/materials/stepper_control.rb: StepperControl, TYPE stepper, WIRE Stepper.
    • KEYWORDS: cancel_text clip_behavior connector_color connector_thickness continue_text controls current_step elevation show_controls steps type plus the common layout keywords.
    • Events: on_step_cancel on_step_continue on_step_tap (plus on_animation_end on_size_change).
    • Defaults: current_step = 0 and type = "vertical".
  • controls/materials/step_control.rb: StepControl, TYPE stepper_step, WIRE Step.
    • KEYWORDS: content data is_active key label state subtitle title visible.
    • Raises ArgumentError when title is missing.
  • CLASS_MAP has stepper, stepper_step and stepperstep in the materials and top-level registries. There is no step key (see the D-6 section below).
  • DSL helpers stepper(steps = nil, **props, &block), stepper_step(**props) and stepperstep are in material_control_methods.rb, shared_control_forwarders.rb and dsl.rb. There is no step helper.
  • Events are not named change, so Page never writes them back into props. The stepper is controlled by your handlers.

Deviation: type collides with Ruflet::Control#initialize(type:)

The spec's type keyword (vertical or horizontal) has the same name as the base class's control-type keyword. Passing it through super(type: TYPE, **props) would silently replace TYPE, and the control would serialize as _c: "Horizontal". StepperControl therefore stores @props["type"] after super. The wire key stays type, as the spec and the Dart renderer expect, and control.type stays "stepper". A test covers this through Ruflet.stepper, Ruflet.control(:stepper, type: ...) and page.update.

D-6: no public step name (second commit)

An earlier version of this PR registered a "step" CLASS_MAP key, as the SPEC suggested, so that Ruflet.control(:step) would work. That key leaked a public step name in two places:

  • Rails views. Ruflet::Rails::HtmlDsl::ViewHelpers.define_registry_helpers! defines a view helper for every ControlFactory::CLASS_MAP key. Every Rails view got step, which clashes with wicked and similar gems.
  • Kernel#method_missing. It builds a control for any name ControlFactory.known_control? accepts. So step(title: ...) on any object returned a Step control instead of raising NoMethodError.

The second commit (fix: keep the Stepper child off the public step name):

  • removes the "step" key from both registries;
  • builds stepper_step through build_widget(:stepper_step);
  • changes StepControl::TYPE from "step" to "stepper_step". The TYPE is the control's registry type, and lookups that go through it, such as Control#schema_class_for_validation, CLASS_MAP[type] and the Rails transformer's registry_props, must resolve to a real key.

to_patch takes the wire name from WIRE, so it is still "Step". The Dart renderer needed no change.

New tests:

  • ruflet_core:
    • neither registry has a "step" key, and known_control?(:step) is false while known_control?(:stepper_step) is true;
    • Object.new.respond_to?(:step) is false, including private methods;
    • Object.new.instance_eval { step(title: "x") } raises NoMethodError; before the fix it returned a StepControl;
    • stepper(steps: [stepper_step(title: ...)]) serializes _c: "Step" children, and stepper_step(...).type == "stepper_step".
  • ruflet_rails (test/html_dsl_helpers_test.rb):
    • checked against the real list ControlFactory::CLASS_MAP.keys that define_registry_helpers! iterates: there is no "step", ViewHelpers defines no public or private step, and a view does not respond to step;
    • stepper, stepper_step and stepperstep helpers exist;
    • <%= stepper do stepper_step(title: ...) end %> markup round-trips through the transformer to a Stepper with Step children.

Notes for review

  • In top-level Ruflet::DSL app scripts, a stepper_step(...) passed in the steps: list is also attached as a page root. This is the existing behaviour for every typed child list (segment, data_column, ...), because DSL::App#control always attaches. The block form avoids it. It is not changed here.
  • Rails views get stepper, stepper_step and stepperstep helpers from define_registry_helpers!. They do not get step.

Tests

  • test/stepper_compatibility_test.rb (12 runs, 76 assertions). It covers:
    • _c and the serialized props for Stepper and Step (string and Control titles, state, label);
    • the defaults;
    • the type collision, including page.update(type:);
    • block children sent as controls;
    • keyword steps: serializing Step children;
    • aliases and the Ruflet::DSL helpers;
    • the D-6 checks above;
    • has_handler? for all three events;
    • Step without a title raises;
    • unknown keywords and events raise;
    • page.dispatch_event for step_tap, step_continue and step_cancel reaches the handlers with e.value and does not move current_step.
  • ruflet_rails test/html_dsl_helpers_test.rb: 2 new tests (20 runs in that file).
  • verify_pr.sh with RUBY_PKGS="ruflet_core ruflet_rails" after rebasing onto origin/main:
    • ruflet_core 146/146 files, 630 runs;
    • ruflet_rails 15/15 files, 280 runs, run per file, including test_every_registry_control_is_reachable_from_markup;
    • the engine pair gives +731 tests, all passing, with analyze clean;
    • the wire-key audit shows 0 new findings under the current key-based comparison.

Add stepper and stepper_step (alias stepperstep) helpers with the Stepper and Step wire types. CLASS_MAP also registers step, but no public step helper is defined (D-6). current_step defaults to 0 and type to vertical; the type prop is stored after super because it collides with Ruflet::Control's own type keyword.
D-6 means no public `step` name at all. A "step" CLASS_MAP key became a Rails view helper (define_registry_helpers!) and made Kernel#method_missing build a Step control for any object calling step(...). Drop the key and register the child only as stepper_step/stepperstep, with TYPE "stepper_step" so registry lookups by type still resolve. The wire type stays "Step".
@AdamMusa
AdamMusa merged commit 7c64c8f into main Nov 2, 2026
12 checks passed
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