Skip to content

[Feature] Add Sheet initial open state#402

Open
pierry01 wants to merge 1 commit into
ruby-ui:mainfrom
pierry01:jean/sheet-initial-open
Open

[Feature] Add Sheet initial open state#402
pierry01 wants to merge 1 commit into
ruby-ui:mainfrom
pierry01:jean/sheet-initial-open

Conversation

@pierry01
Copy link
Copy Markdown
Contributor

@pierry01 pierry01 commented May 25, 2026

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.

Written for commit 3aad267. Summary will update on new commits. Review in cubic

@pierry01 pierry01 marked this pull request as ready for review May 25, 2026 15:44
@pierry01 pierry01 requested a review from cirdes as a code owner May 25, 2026 15:44
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

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.

2 participants