@linzjs/lui 23.6.2 → 23.7.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/lui.esm.js CHANGED
@@ -15068,14 +15068,23 @@ var motif = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0id
15068
15068
  * A hook which allows you to register a handler when the escape key is pressed
15069
15069
  *
15070
15070
  * @param onEscape the handler function
15071
+ * @param elRef a react ref to the element that should listen to the key event. If this argument is `undefined` it means the consumer wants to attach the listener to `document`. If this argument is a ref to `null` no event listener will be added.
15071
15072
  */
15072
- var useEscapeFunction = function (onEscape, trigger) {
15073
+ var useEscapeFunction = function (onEscape, trigger, elRef) {
15073
15074
  if (trigger === void 0) { trigger = 'keydown'; }
15074
- var escFunction = useCallback(function (event) { return event.key === 'Escape' && onEscape(event); }, [onEscape]);
15075
+ var escFunction = useCallback(function (event) {
15076
+ if (event.keyCode === 27) {
15077
+ onEscape(event);
15078
+ }
15079
+ }, [onEscape]);
15075
15080
  useEffect(function () {
15076
- document.addEventListener(trigger, escFunction);
15077
- return function () { return document.removeEventListener(trigger, escFunction); };
15078
- }, [escFunction]);
15081
+ var _a;
15082
+ if ((elRef === null || elRef === void 0 ? void 0 : elRef.current) === null)
15083
+ return;
15084
+ var el = (_a = elRef === null || elRef === void 0 ? void 0 : elRef.current) !== null && _a !== void 0 ? _a : document;
15085
+ el.addEventListener(trigger, escFunction, false);
15086
+ return function () { return el.removeEventListener(trigger, escFunction, false); };
15087
+ }, [escFunction, elRef === null || elRef === void 0 ? void 0 : elRef.current]);
15079
15088
  };
15080
15089
  /**
15081
15090
  * A hook which allows handling of click event anywhere on the page.