File tree Expand file tree Collapse file tree 5 files changed +30
-35
lines changed Expand file tree Collapse file tree 5 files changed +30
-35
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
11
11
12
12
- Only add ` type=button ` to real buttons ([ #709 ] ( https://github.com/tailwindlabs/headlessui/pull/709 ) )
13
13
- Fix ` escape ` bug not closing Dialog after clicking in Dialog ([ #754 ] ( https://github.com/tailwindlabs/headlessui/pull/754 ) )
14
+ - Use ` console.warn ` instead of throwing an error when there are no focusable elements ([ #775 ] ( https://github.com/tailwindlabs/headlessui/pull/775 ) )
14
15
15
16
## [ Unreleased - Vue]
16
17
@@ -19,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
20
- Only add ` type=button ` to real buttons ([ #709 ] ( https://github.com/tailwindlabs/headlessui/pull/709 ) )
20
21
- Add Vue emit types ([ #679 ] ( https://github.com/tailwindlabs/headlessui/pull/679 ) , [ #712 ] ( https://github.com/tailwindlabs/headlessui/pull/712 ) )
21
22
- Fix ` escape ` bug not closing Dialog after clicking in Dialog ([ #754 ] ( https://github.com/tailwindlabs/headlessui/pull/754 ) )
23
+ - Use ` console.warn ` instead of throwing an error when there are no focusable elements ([ #775 ] ( https://github.com/tailwindlabs/headlessui/pull/775 ) )
22
24
23
25
## [ @headlessui/react @v1.4.0] - 2021-07-29
24
26
Original file line number Diff line number Diff line change @@ -62,20 +62,19 @@ it('should focus the initialFocus element inside the FocusTrap even if another e
62
62
assertActiveElement ( document . getElementById ( 'c' ) )
63
63
} )
64
64
65
- it (
66
- 'should error when there is no focusable element inside the FocusTrap' ,
67
- suppressConsoleLogs ( ( ) => {
68
- expect ( ( ) => {
69
- render (
70
- < FocusTrap >
71
- < span > Nothing to see here...</ span >
72
- </ FocusTrap >
73
- )
74
- } ) . toThrowErrorMatchingInlineSnapshot (
75
- `"There are no focusable elements inside the <FocusTrap />"`
65
+ it ( 'should warn when there is no focusable element inside the FocusTrap' , ( ) => {
66
+ let spy = jest . spyOn ( console , 'warn' ) . mockImplementation ( jest . fn ( ) )
67
+
68
+ function Example ( ) {
69
+ return (
70
+ < FocusTrap >
71
+ < span > Nothing to see here...</ span >
72
+ </ FocusTrap >
76
73
)
77
- } )
78
- )
74
+ }
75
+ render ( < Example /> )
76
+ expect ( spy . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'There are no focusable elements inside the <FocusTrap />' )
77
+ } )
79
78
80
79
it (
81
80
'should not be possible to programmatically escape the focus trap' ,
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ export function useFocusTrap(
89
89
focusElement ( initialFocus . current )
90
90
} else {
91
91
if ( focusIn ( container . current , Focus . First ) === FocusResult . Error ) {
92
- throw new Error ( 'There are no focusable elements inside the <FocusTrap />' )
92
+ console . warn ( 'There are no focusable elements inside the <FocusTrap />' )
93
93
}
94
94
}
95
95
Original file line number Diff line number Diff line change @@ -109,28 +109,22 @@ it('should focus the initialFocus element inside the FocusTrap even if another e
109
109
assertActiveElement ( document . getElementById ( 'c' ) )
110
110
} )
111
111
112
- it (
113
- 'should error when there is no focusable element inside the FocusTrap' ,
114
- suppressConsoleLogs ( async ( ) => {
115
- expect . assertions ( 1 )
112
+ it ( 'should warn when there is no focusable element inside the FocusTrap' , async ( ) => {
113
+ expect . assertions ( 1 )
114
+ let spy = jest . spyOn ( console , 'warn' ) . mockImplementation ( jest . fn ( ) )
116
115
117
- renderTemplate ( {
118
- template : html `
119
- < FocusTrap >
120
- < span > Nothing to see here...</ span >
121
- </ FocusTrap >
122
- ` ,
123
- errorCaptured ( err : unknown ) {
124
- expect ( ( err as Error ) . message ) . toMatchInlineSnapshot (
125
- `"There are no focusable elements inside the <FocusTrap />"`
126
- )
127
- return false
128
- } ,
129
- } )
116
+ renderTemplate (
117
+ html `
118
+ < FocusTrap >
119
+ < span > Nothing to see here...</ span >
120
+ </ FocusTrap >
121
+ `
122
+ )
130
123
131
- await new Promise ( nextTick )
132
- } )
133
- )
124
+ await new Promise ( nextTick )
125
+
126
+ expect ( spy . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'There are no focusable elements inside the <FocusTrap />' )
127
+ } )
134
128
135
129
it (
136
130
'should not be possible to programmatically escape the focus trap' ,
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ export function useFocusTrap(
53
53
}
54
54
}
55
55
56
- if ( ! couldFocus ) throw new Error ( 'There are no focusable elements inside the <FocusTrap />' )
56
+ if ( ! couldFocus ) console . warn ( 'There are no focusable elements inside the <FocusTrap />' )
57
57
}
58
58
59
59
previousActiveElement . value = document . activeElement as HTMLElement
You can’t perform that action at this time.
0 commit comments