File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
packages/core/useMagicKeys Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -155,13 +155,30 @@ describe('useMagicKeys', () => {
155155 expect ( alt_tab . value ) . toBe ( false )
156156 } )
157157
158- it ( 'should handle empty key events without errors' , async ( ) => {
158+ it ( 'should handle empty or undefined key events without errors' , async ( ) => {
159159 const { a } = useMagicKeys ( { target } )
160160
161+ // Test empty key
161162 expect ( ( ) => {
162163 target . dispatchEvent ( new KeyboardEvent ( 'keyup' , { } ) )
163164 } ) . not . toThrow ( )
164165
166+ // Test empty string key
167+ expect ( ( ) => {
168+ target . dispatchEvent ( new KeyboardEvent ( 'keyup' , { key : '' } ) )
169+ } ) . not . toThrow ( )
170+
165171 expect ( a . value ) . toBe ( false )
166172 } )
173+
174+ it ( 'should be robust when key is explicitly undefined' , ( ) => {
175+ useMagicKeys ( { target } )
176+
177+ const event = new KeyboardEvent ( 'keyup' , { } )
178+ Object . defineProperty ( event , 'key' , { value : undefined } )
179+
180+ expect ( ( ) => {
181+ target . dispatchEvent ( event )
182+ } ) . not . toThrow ( )
183+ } )
167184} )
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ export function useMagicKeys<T extends boolean = false>(options: UseMagicKeysOpt
140140 const code = e . code ?. toLowerCase ( )
141141 const values = [ code , key ] . filter ( Boolean )
142142
143- if ( key === '' )
143+ if ( ! key )
144144 return
145145
146146 // current set
You can’t perform that action at this time.
0 commit comments