File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33module RubyUI
44 class Sheet < Base
5+ def initialize ( open : false , **attrs )
6+ @open = open
7+ super ( **attrs )
8+ end
9+
510 def view_template ( &)
611 div ( **attrs , &)
712 end
@@ -10,7 +15,10 @@ def view_template(&)
1015
1116 def default_attrs
1217 {
13- data : { controller : "ruby-ui--sheet" }
18+ data : {
19+ controller : "ruby-ui--sheet" ,
20+ ruby_ui__sheet_open_value : @open . to_s
21+ }
1422 }
1523 end
1624 end
Original file line number Diff line number Diff line change @@ -3,6 +3,12 @@ import { Controller } from "@hotwired/stimulus"
33export default class extends Controller {
44 static targets = [ "content" ]
55
6+ static values = { open : false }
7+
8+ connect ( ) {
9+ if ( this . openValue ) this . open ( )
10+ }
11+
612 open ( ) {
713 document . body . insertAdjacentHTML ( "beforeend" , this . contentTarget . innerHTML )
814 }
Original file line number Diff line number Diff line change @@ -30,4 +30,16 @@ def test_render_with_all_items
3030
3131 assert_match ( /Open Sheet/ , output )
3232 end
33+
34+ def test_render_closed_by_default
35+ output = phlex { RubyUI . Sheet { "content" } }
36+
37+ assert_match ( /data-ruby-ui--sheet-open-value="false"/ , output )
38+ end
39+
40+ def test_render_open_when_open_is_true
41+ output = phlex { RubyUI . Sheet ( open : true ) { "content" } }
42+
43+ assert_match ( /data-ruby-ui--sheet-open-value="true"/ , output )
44+ end
3345end
You can’t perform that action at this time.
0 commit comments