[Feature] Add Sheet initial open state

Merged
PI
4mo ago
+27-1

Summary

Adds an open: keyword to RubyUI::Sheet so a Sheet can render already open on the initial response — no SheetTrigger click required.

Sheet(open: true) do
  SheetContent(class: "sm:max-w-sm") do
    # ...
  end
end

Why

When a Sheet is rendered as the result of a Turbo Stream (or any server-driven render where the user did not click a trigger), there is no SheetTrigger in scope to open it. Today the only way to surface the Sheet is to dispatch the controller's open action manually from JS.

Use case: clicking a table row dispatches a GET accepting text/vnd.turbo-stream.html; the response targets a turbo_frame_tag in the layout with turbo_stream.update("FRAME_ID", Sheet(open: true) { ... }). The Sheet appears as soon as the stream lands.

Implementation

  • RubyUI::Sheet#initialize now accepts open: false and forwards remaining **attrs to super.
  • default_attrs exposes the value to Stimulus via data-ruby-ui--sheet-open-value.
  • sheet_controller.js declares static values = { open: false } and calls this.open() on connect() when openValue is true.
  • Defaults to false, so existing usage is unchanged.

Tests

  • test_render_closed_by_default — confirms the data attribute defaults to "false".
  • test_render_open_when_open_is_true — confirms Sheet(open: true) emits data-ruby-ui--sheet-open-value="true".

Existing test (test_render_with_all_items) still passes — additive change only.


Summary by cubic

Adds an open: option to RubyUI::Sheet to render a Sheet already open on the initial response. Enables Turbo Stream/server-driven renders to show the Sheet without a SheetTrigger; defaults to closed for backward compatibility.

  • New Features
    • Add open: to RubyUI::Sheet, exposing data-ruby-ui--sheet-open-value for Stimulus.
    • Controller reads openValue and calls open() on connect when true.
    • Works with Turbo Stream updates; no manual JS dispatch needed.