File tree Expand file tree Collapse file tree 3 files changed +50
-2
lines changed
packages/@headlessui-vue/src/components/dialog Expand file tree Collapse file tree 3 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
8
8
## [ Unreleased - @headlessui/vue ]
9
9
10
- - Nothing yet!
10
+ ### Fixed
11
+
12
+ - Ensure ` DialogPanel ` exposes its ref ([ #1404 ] ( https://github.com/tailwindlabs/headlessui/pull/1404 ) )
11
13
12
14
## [ Unreleased - @headlessui/react ]
13
15
Original file line number Diff line number Diff line change 5
5
h ,
6
6
ComponentOptionsWithoutProps ,
7
7
ConcreteComponent ,
8
+ onMounted ,
8
9
} from 'vue'
9
10
import { render } from '../../test-utils/vue-testing-library'
10
11
@@ -120,6 +121,49 @@ describe('Safe guards', () => {
120
121
)
121
122
} )
122
123
124
+ describe ( 'refs' , ( ) => {
125
+ it ( 'should be possible to access the ref on the DialogBackdrop' , async ( ) => {
126
+ renderTemplate ( {
127
+ template : `
128
+ <Dialog :open="true">
129
+ <DialogBackdrop ref="backdrop" />
130
+ <DialogPanel>
131
+ <button>element</button>
132
+ </DialogPanel>
133
+ </Dialog>
134
+ ` ,
135
+ setup ( ) {
136
+ let backdrop = ref < { el : Element ; $el : Element } | null > ( null )
137
+ onMounted ( ( ) => {
138
+ expect ( backdrop . value ?. el ) . toBeInstanceOf ( HTMLDivElement )
139
+ expect ( backdrop . value ?. $el ) . toBeInstanceOf ( HTMLDivElement )
140
+ } )
141
+ return { backdrop }
142
+ } ,
143
+ } )
144
+ } )
145
+
146
+ it ( 'should be possible to access the ref on the DialogPanel' , async ( ) => {
147
+ renderTemplate ( {
148
+ template : `
149
+ <Dialog :open="true">
150
+ <DialogPanel ref="panel">
151
+ <button>element</button>
152
+ </DialogPanel>
153
+ </Dialog>
154
+ ` ,
155
+ setup ( ) {
156
+ let panel = ref < { el : Element ; $el : Element } | null > ( null )
157
+ onMounted ( ( ) => {
158
+ expect ( panel . value ?. el ) . toBeInstanceOf ( HTMLDivElement )
159
+ expect ( panel . value ?. $el ) . toBeInstanceOf ( HTMLDivElement )
160
+ } )
161
+ return { panel }
162
+ } ,
163
+ } )
164
+ } )
165
+ } )
166
+
123
167
describe ( 'Rendering' , ( ) => {
124
168
describe ( 'Dialog' , ( ) => {
125
169
it (
Original file line number Diff line number Diff line change @@ -401,10 +401,12 @@ export let DialogPanel = defineComponent({
401
401
props : {
402
402
as : { type : [ Object , String ] , default : 'div' } ,
403
403
} ,
404
- setup ( props , { attrs, slots } ) {
404
+ setup ( props , { attrs, slots, expose } ) {
405
405
let api = useDialogContext ( 'DialogPanel' )
406
406
let id = `headlessui-dialog-panel-${ useId ( ) } `
407
407
408
+ expose ( { el : api . panelRef , $el : api . panelRef } )
409
+
408
410
return ( ) => {
409
411
let ourProps = {
410
412
id,
You can’t perform that action at this time.
0 commit comments