@sanity/ui 3.0.14 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -2840,9 +2840,16 @@ export declare function useForwardedRef<T>(
2840
2840
  ): React.MutableRefObject<T | null>
2841
2841
 
2842
2842
  /**
2843
+ * Adds global keydown event listener to the window.
2844
+ *
2845
+ * @param onKeyDown - The function to call when a keydown event is triggered.
2846
+ * @param options - The options to pass to the addEventListener function (example, capture: true)
2843
2847
  * @beta
2844
2848
  */
2845
- export declare function useGlobalKeyDown(onKeyDown: (event: KeyboardEvent) => void): void
2849
+ export declare function useGlobalKeyDown(
2850
+ onKeyDown: (event: KeyboardEvent) => void,
2851
+ options?: AddEventListenerOptions,
2852
+ ): void
2846
2853
 
2847
2854
  /**
2848
2855
  * @public
package/dist/index.d.ts CHANGED
@@ -2840,9 +2840,16 @@ export declare function useForwardedRef<T>(
2840
2840
  ): React.MutableRefObject<T | null>
2841
2841
 
2842
2842
  /**
2843
+ * Adds global keydown event listener to the window.
2844
+ *
2845
+ * @param onKeyDown - The function to call when a keydown event is triggered.
2846
+ * @param options - The options to pass to the addEventListener function (example, capture: true)
2843
2847
  * @beta
2844
2848
  */
2845
- export declare function useGlobalKeyDown(onKeyDown: (event: KeyboardEvent) => void): void
2849
+ export declare function useGlobalKeyDown(
2850
+ onKeyDown: (event: KeyboardEvent) => void,
2851
+ options?: AddEventListenerOptions,
2852
+ ): void
2846
2853
 
2847
2854
  /**
2848
2855
  * @public
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "3.0.14",
3
+ "version": "3.1.0",
4
4
  "keywords": [
5
5
  "sanity",
6
6
  "ui",
@@ -195,7 +195,7 @@
195
195
  "refractor": "^5.0.0",
196
196
  "rimraf": "^5.0.5",
197
197
  "semantic-release": "^24.2.7",
198
- "start-server-and-test": "^2.0.13",
198
+ "start-server-and-test": "^2.1.0",
199
199
  "storybook": "^8.6.14",
200
200
  "styled-components": "npm:@sanity/styled-components@^6.1.22",
201
201
  "tsconfig-paths": "^4.2.0",
@@ -2,16 +2,23 @@ import {useEffect} from 'react'
2
2
  import {useEffectEvent} from 'use-effect-event'
3
3
 
4
4
  /**
5
+ * Adds global keydown event listener to the window.
6
+ *
7
+ * @param onKeyDown - The function to call when a keydown event is triggered.
8
+ * @param options - The options to pass to the addEventListener function (example, capture: true)
5
9
  * @beta
6
10
  */
7
- export function useGlobalKeyDown(onKeyDown: (event: KeyboardEvent) => void): void {
11
+ export function useGlobalKeyDown(
12
+ onKeyDown: (event: KeyboardEvent) => void,
13
+ options?: AddEventListenerOptions,
14
+ ): void {
8
15
  const handleKeyDown = useEffectEvent((event: KeyboardEvent) => onKeyDown(event))
9
16
 
10
17
  useEffect(() => {
11
18
  const handler = (event: KeyboardEvent) => handleKeyDown(event)
12
19
 
13
- window.addEventListener('keydown', handler)
20
+ window.addEventListener('keydown', handler, options)
14
21
 
15
- return () => window.removeEventListener('keydown', handler)
16
- }, [])
22
+ return () => window.removeEventListener('keydown', handler, options)
23
+ }, [options])
17
24
  }