@trackunit/react-components 0.1.364 → 0.1.365

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/index.cjs.js CHANGED
@@ -1365,9 +1365,8 @@ const hasFocus = () => typeof document !== "undefined" && document.hasFocus();
1365
1365
  * Use this hook to disable functionality while the tab is hidden within the browser or to react to focus or blur events
1366
1366
  */
1367
1367
  const useWindowActivity = ({ onFocus, onBlur } = {}) => {
1368
- const [focused, setFocused] = React.useState(hasFocus); // Focus for first render
1368
+ const [focused, setFocused] = React.useState(hasFocus());
1369
1369
  React.useEffect(() => {
1370
- setFocused(hasFocus()); // Focus for additional renders
1371
1370
  const onFocusInternal = () => {
1372
1371
  setFocused(true);
1373
1372
  onFocus === null || onFocus === void 0 ? void 0 : onFocus();
@@ -1376,11 +1375,21 @@ const useWindowActivity = ({ onFocus, onBlur } = {}) => {
1376
1375
  setFocused(false);
1377
1376
  onBlur === null || onBlur === void 0 ? void 0 : onBlur();
1378
1377
  };
1379
- window.addEventListener("focus", () => onFocusInternal);
1380
- window.addEventListener("blur", () => onBlurInternal);
1378
+ const handleVisibilityChange = () => {
1379
+ if (!document.hasFocus()) {
1380
+ onBlurInternal();
1381
+ }
1382
+ else {
1383
+ onFocusInternal();
1384
+ }
1385
+ };
1386
+ window.addEventListener("visibilitychange", handleVisibilityChange);
1387
+ window.addEventListener("focus", handleVisibilityChange);
1388
+ window.addEventListener("blur", handleVisibilityChange);
1381
1389
  return () => {
1382
- window.removeEventListener("focus", onFocusInternal);
1383
- window.removeEventListener("blur", onBlurInternal);
1390
+ window.removeEventListener("visibilitychange", handleVisibilityChange);
1391
+ window.removeEventListener("focus", handleVisibilityChange);
1392
+ window.removeEventListener("blur", handleVisibilityChange);
1384
1393
  };
1385
1394
  }, [onBlur, onFocus]);
1386
1395
  return { focused };
package/index.esm.js CHANGED
@@ -1334,9 +1334,8 @@ const hasFocus = () => typeof document !== "undefined" && document.hasFocus();
1334
1334
  * Use this hook to disable functionality while the tab is hidden within the browser or to react to focus or blur events
1335
1335
  */
1336
1336
  const useWindowActivity = ({ onFocus, onBlur } = {}) => {
1337
- const [focused, setFocused] = useState(hasFocus); // Focus for first render
1337
+ const [focused, setFocused] = useState(hasFocus());
1338
1338
  useEffect(() => {
1339
- setFocused(hasFocus()); // Focus for additional renders
1340
1339
  const onFocusInternal = () => {
1341
1340
  setFocused(true);
1342
1341
  onFocus === null || onFocus === void 0 ? void 0 : onFocus();
@@ -1345,11 +1344,21 @@ const useWindowActivity = ({ onFocus, onBlur } = {}) => {
1345
1344
  setFocused(false);
1346
1345
  onBlur === null || onBlur === void 0 ? void 0 : onBlur();
1347
1346
  };
1348
- window.addEventListener("focus", () => onFocusInternal);
1349
- window.addEventListener("blur", () => onBlurInternal);
1347
+ const handleVisibilityChange = () => {
1348
+ if (!document.hasFocus()) {
1349
+ onBlurInternal();
1350
+ }
1351
+ else {
1352
+ onFocusInternal();
1353
+ }
1354
+ };
1355
+ window.addEventListener("visibilitychange", handleVisibilityChange);
1356
+ window.addEventListener("focus", handleVisibilityChange);
1357
+ window.addEventListener("blur", handleVisibilityChange);
1350
1358
  return () => {
1351
- window.removeEventListener("focus", onFocusInternal);
1352
- window.removeEventListener("blur", onBlurInternal);
1359
+ window.removeEventListener("visibilitychange", handleVisibilityChange);
1360
+ window.removeEventListener("focus", handleVisibilityChange);
1361
+ window.removeEventListener("blur", handleVisibilityChange);
1353
1362
  };
1354
1363
  }, [onBlur, onFocus]);
1355
1364
  return { focused };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.1.364",
3
+ "version": "0.1.365",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {