File tree Expand file tree Collapse file tree 5 files changed +86
-0
lines changed
@headlessui-react/src/components/dialog
@headlessui-vue/src/components/dialog Expand file tree Collapse file tree 5 files changed +86
-0
lines changed Original file line number Diff line number Diff line change @@ -10,12 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
### Fixes
11
11
12
12
- Stop the event from propagating in the ` Popover ` component ([ #798 ] ( https://github.com/tailwindlabs/headlessui/pull/798 ) )
13
+ - Allow to click on elements inside a ` Dialog.Overlay ` ([ #816 ] ( https://github.com/tailwindlabs/headlessui/pull/816 ) )
13
14
14
15
## [ Unreleased - Vue]
15
16
16
17
### Fixes
17
18
18
19
- Stop the event from propagating in the ` Popover ` component ([ #798 ] ( https://github.com/tailwindlabs/headlessui/pull/798 ) )
20
+ - Allow to click on elements inside a ` DialogOverlay ` ([ #816 ] ( https://github.com/tailwindlabs/headlessui/pull/816 ) )
19
21
20
22
## [ @headlessui/react @v1.4.1] - 2021-08-30
21
23
Original file line number Diff line number Diff line change @@ -552,6 +552,42 @@ describe('Mouse interactions', () => {
552
552
} )
553
553
)
554
554
555
+ it (
556
+ 'should not close the Dialog when clicking on contents of the Dialog.Overlay' ,
557
+ suppressConsoleLogs ( async ( ) => {
558
+ function Example ( ) {
559
+ let [ isOpen , setIsOpen ] = useState ( false )
560
+ return (
561
+ < >
562
+ < button id = "trigger" onClick = { ( ) => setIsOpen ( v => ! v ) } >
563
+ Trigger
564
+ </ button >
565
+ < Dialog open = { isOpen } onClose = { setIsOpen } >
566
+ < Dialog . Overlay >
567
+ < button > hi</ button >
568
+ </ Dialog . Overlay >
569
+ Contents
570
+ < TabSentinel />
571
+ </ Dialog >
572
+ </ >
573
+ )
574
+ }
575
+ render ( < Example /> )
576
+
577
+ // Open dialog
578
+ await click ( document . getElementById ( 'trigger' ) )
579
+
580
+ // Verify it is open
581
+ assertDialog ( { state : DialogState . Visible } )
582
+
583
+ // Click on an element inside the overlay
584
+ await click ( getByText ( 'hi' ) )
585
+
586
+ // Verify it is still open
587
+ assertDialog ( { state : DialogState . Visible } )
588
+ } )
589
+ )
590
+
555
591
it (
556
592
'should be possible to close the dialog, and re-focus the button when we click outside on the body element' ,
557
593
suppressConsoleLogs ( async ( ) => {
Original file line number Diff line number Diff line change @@ -355,6 +355,7 @@ let Overlay = forwardRefWithAs(function Overlay<
355
355
356
356
let handleClick = useCallback (
357
357
( event : ReactMouseEvent ) => {
358
+ if ( event . target !== event . currentTarget ) return
358
359
if ( isDisabledReactIssue7711 ( event . currentTarget ) ) return event . preventDefault ( )
359
360
event . preventDefault ( )
360
361
event . stopPropagation ( )
Original file line number Diff line number Diff line change @@ -679,6 +679,52 @@ describe('Mouse interactions', () => {
679
679
} )
680
680
)
681
681
682
+ it (
683
+ 'should not close the Dialog when clicking on contents of the Dialog.Overlay' ,
684
+ suppressConsoleLogs ( async ( ) => {
685
+ renderTemplate ( {
686
+ template : `
687
+ <div>
688
+ <button id="trigger" @click="toggleOpen">
689
+ Trigger
690
+ </button>
691
+ <Dialog :open="isOpen" @close="setIsOpen">
692
+ <DialogOverlay>
693
+ <button>hi</button>
694
+ </DialogOverlay>
695
+ Contents
696
+ <TabSentinel />
697
+ </Dialog>
698
+ </div>
699
+ ` ,
700
+ setup ( ) {
701
+ let isOpen = ref ( false )
702
+ return {
703
+ isOpen,
704
+ setIsOpen ( value : boolean ) {
705
+ isOpen . value = value
706
+ } ,
707
+ toggleOpen ( ) {
708
+ isOpen . value = ! isOpen . value
709
+ } ,
710
+ }
711
+ } ,
712
+ } )
713
+
714
+ // Open dialog
715
+ await click ( document . getElementById ( 'trigger' ) )
716
+
717
+ // Verify it is open
718
+ assertDialog ( { state : DialogState . Visible } )
719
+
720
+ // Click on an element inside the overlay
721
+ await click ( getByText ( 'hi' ) )
722
+
723
+ // Verify it is still open
724
+ assertDialog ( { state : DialogState . Visible } )
725
+ } )
726
+ )
727
+
682
728
it (
683
729
'should be possible to close the dialog, and re-focus the button when we click outside on the body element' ,
684
730
suppressConsoleLogs ( async ( ) => {
Original file line number Diff line number Diff line change @@ -305,6 +305,7 @@ export let DialogOverlay = defineComponent({
305
305
return {
306
306
id,
307
307
handleClick ( event : MouseEvent ) {
308
+ if ( event . target !== event . currentTarget ) return
308
309
event . preventDefault ( )
309
310
event . stopPropagation ( )
310
311
api . close ( )
You can’t perform that action at this time.
0 commit comments