@@ -6,9 +6,21 @@ import { render } from './render'
6
6
let Dummy = defineComponent ( {
7
7
props : {
8
8
as : { type : [ Object , String ] , default : 'div' } ,
9
+ slot : { type : Object , default : ( ) => ( { } ) } ,
9
10
} ,
10
11
setup ( props , { attrs, slots } ) {
11
- return ( ) => render ( { theirProps : props , ourProps : { } , slots, attrs, slot : { } , name : 'Dummy' } )
12
+ return ( ) => {
13
+ let { slot, ...rest } = props
14
+
15
+ return render ( {
16
+ theirProps : rest ,
17
+ ourProps : { } ,
18
+ slots,
19
+ attrs,
20
+ slot,
21
+ name : 'Dummy' ,
22
+ } )
23
+ }
12
24
} ,
13
25
} )
14
26
@@ -120,3 +132,38 @@ describe('Validation', () => {
120
132
expect ( document . getElementById ( 'result' ) ) . toHaveAttribute ( 'data-test' , '123' )
121
133
} )
122
134
} )
135
+
136
+ describe ( 'State Data Attributes' , ( ) => {
137
+ it ( 'as=element' , ( ) => {
138
+ renderTemplate ( {
139
+ template : html `
140
+ < Dummy id ="result " as ="div " :slot ="{active: true, selected: true} ">
141
+ < div > test</ div >
142
+ </ Dummy >
143
+ ` ,
144
+ } )
145
+
146
+ expect ( document . getElementById ( 'result' ) ) . toHaveAttribute (
147
+ 'data-headlessui-state' ,
148
+ 'active selected'
149
+ )
150
+ } )
151
+
152
+ it ( 'as=template' , ( ) => {
153
+ renderTemplate ( {
154
+ template : html `
155
+ < Dummy as ="template " class ="abc " :slot ="{active: true, selected: true} ">
156
+ < div id ="result "> test</ div >
157
+ </ Dummy >
158
+ ` ,
159
+ } )
160
+
161
+ expect ( document . getElementById ( 'result' ) ) . toHaveClass ( 'abc' )
162
+
163
+ // NOTE: Removing class="abc" causes this assertion to fail
164
+ expect ( document . getElementById ( 'result' ) ) . toHaveAttribute (
165
+ 'data-headlessui-state' ,
166
+ 'active selected'
167
+ )
168
+ } )
169
+ } )
0 commit comments