@workday/canvas-kit-react 8.0.0-alpha.230-next.1 → 8.0.0-alpha.232-next.3

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.
@@ -4,6 +4,7 @@ export * from './useBringToTopOnClick';
4
4
  export * from './useCloseOnEscape';
5
5
  export * from './useCloseOnFullscreenExit';
6
6
  export * from './useCloseOnOutsideClick';
7
+ export * from './useCloseOnTargetHidden';
7
8
  export * from './useDisableBodyScroll';
8
9
  export * from './useFocusRedirect';
9
10
  export * from './useFocusTrap';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC"}
@@ -16,6 +16,7 @@ __exportStar(require("./useBringToTopOnClick"), exports);
16
16
  __exportStar(require("./useCloseOnEscape"), exports);
17
17
  __exportStar(require("./useCloseOnFullscreenExit"), exports);
18
18
  __exportStar(require("./useCloseOnOutsideClick"), exports);
19
+ __exportStar(require("./useCloseOnTargetHidden"), exports);
19
20
  __exportStar(require("./useDisableBodyScroll"), exports);
20
21
  __exportStar(require("./useFocusRedirect"), exports);
21
22
  __exportStar(require("./useFocusTrap"), exports);
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ /**
3
+ * Sets up an
4
+ * [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)
5
+ * for the target element. When the target is detected as being less than 50% visible, the popup
6
+ * will close. Most likely, this will happen if the user scrolls an overflowed content area of the
7
+ * page and the target is no longer visible.
8
+ *
9
+ * This should be used with popup elements that are transitory like Tooltips and dropdown menus.
10
+ */
11
+ export declare const useCloseOnTargetHidden: <P extends {}, R>(model: {
12
+ state: {
13
+ stackRef: React.RefObject<HTMLDivElement>;
14
+ targetRef: React.RefObject<HTMLButtonElement>;
15
+ initialFocusRef: React.RefObject<any> | undefined;
16
+ returnFocusRef: React.RefObject<any> | undefined;
17
+ placement: import("@popperjs/core").Placement;
18
+ id: string;
19
+ visibility: import("../../..").Visibility;
20
+ };
21
+ events: {
22
+ updatePlacement(data: {
23
+ placement: import("@popperjs/core").Placement;
24
+ }): void;
25
+ show(event?: Event | React.SyntheticEvent<Element, Event> | undefined): void;
26
+ hide(event?: Event | React.SyntheticEvent<Element, Event> | undefined): void;
27
+ };
28
+ }, elemProps?: P | undefined, ref?: ((instance: R | null) => void) | React.RefObject<R> | null | undefined) => {} & P & (R extends HTMLOrSVGElement ? {
29
+ ref: React.Ref<R>;
30
+ } : {});
31
+ //# sourceMappingURL=useCloseOnTargetHidden.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCloseOnTargetHidden.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/useCloseOnTargetHidden.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAuB1B;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;OAiCjC,CAAC"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useCloseOnTargetHidden = void 0;
7
+ var react_1 = __importDefault(require("react"));
8
+ var common_1 = require("@workday/canvas-kit-react/common");
9
+ var popup_1 = require("@workday/canvas-kit-react/popup");
10
+ function getScrollParent(element) {
11
+ if (element === document.body || !element.parentElement) {
12
+ return element;
13
+ }
14
+ var styles = getComputedStyle(element);
15
+ if (styles.overflowY === 'scroll' ||
16
+ styles.overflowY === 'auto' ||
17
+ styles.overflowX === 'scroll' ||
18
+ styles.overflowX === 'auto') {
19
+ return element;
20
+ }
21
+ return getScrollParent(element.parentElement);
22
+ }
23
+ /**
24
+ * Sets up an
25
+ * [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)
26
+ * for the target element. When the target is detected as being less than 50% visible, the popup
27
+ * will close. Most likely, this will happen if the user scrolls an overflowed content area of the
28
+ * page and the target is no longer visible.
29
+ *
30
+ * This should be used with popup elements that are transitory like Tooltips and dropdown menus.
31
+ */
32
+ exports.useCloseOnTargetHidden = common_1.createElemPropsHook(popup_1.usePopupModel)(function (model) {
33
+ var visible = model.state.visibility !== 'hidden';
34
+ var callback = react_1.default.useCallback(function (entries) {
35
+ if (entries[0].intersectionRatio < 0.5) {
36
+ model.events.hide();
37
+ }
38
+ }, [model.events]);
39
+ react_1.default.useLayoutEffect(function () {
40
+ if (!visible || !model.state.targetRef.current) {
41
+ return;
42
+ }
43
+ var target = model.state.targetRef.current;
44
+ var scrollParent = getScrollParent(target);
45
+ // eslint-disable-next-line compat/compat
46
+ var observer = new IntersectionObserver(callback, {
47
+ root: scrollParent,
48
+ threshold: 0.5,
49
+ });
50
+ observer.observe(model.state.targetRef.current);
51
+ return function () {
52
+ observer.disconnect();
53
+ };
54
+ }, [callback, model.state.targetRef, visible]);
55
+ return {};
56
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"TooltipContainer.d.ts","sourceRoot":"","sources":["../../../../tooltip/lib/TooltipContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,OAAO,EAAC,eAAe,EAAyB,MAAM,kCAAkC,CAAC;AAiBzF,MAAM,WAAW,qBAAsB,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IACjF;;;OAGG;IACH,eAAe,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IACzC;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,WAAW,CAAC,EAAE;QACZ,IAAI,EAAE,OAAO,CAAC;QACd,aAAa,EAAE,WAAW,GAAG,IAAI,CAAC;KACnC,CAAC;CACH;AAOD,eAAO,MAAM,gBAAgB;;;6GA4D5B,CAAC"}
1
+ {"version":3,"file":"TooltipContainer.d.ts","sourceRoot":"","sources":["../../../../tooltip/lib/TooltipContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,OAAO,EAAC,eAAe,EAAyB,MAAM,kCAAkC,CAAC;AAiBzF,MAAM,WAAW,qBAAsB,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IACjF;;;OAGG;IACH,eAAe,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IACzC;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,WAAW,CAAC,EAAE;QACZ,IAAI,EAAE,OAAO,CAAC;QACd,aAAa,EAAE,WAAW,GAAG,IAAI,CAAC;KACnC,CAAC;CACH;AAOD,eAAO,MAAM,gBAAgB;;;6GAkE5B,CAAC"}
@@ -55,6 +55,11 @@ exports.TooltipContainer = styled_1.default('div')(__assign(__assign({}, tokens_
55
55
  margin: tokens_1.spaceNumbers.xxxs + 2,
56
56
  },
57
57
  },
58
+ // Hide tooltip when the reference element is either clipped or fully hidden
59
+ '[data-popper-reference-hidden] &': {
60
+ visibility: 'hidden',
61
+ pointerEvents: 'none',
62
+ },
58
63
  // Fix offsets based on placement
59
64
  '[data-popper-placement="top-start"] &, [data-popper-placement="bottom-start"] &': {
60
65
  left: -tokens_1.spaceNumbers.xxxs,
@@ -1 +1 @@
1
- {"version":3,"file":"useTooltip.d.ts","sourceRoot":"","sources":["../../../../tooltip/lib/useTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAkD/B;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,EACtD,IAAc,EACd,SAAc,EACd,SAAe,EACf,SAAe,GAChB,GAAE;IACD;;;;;;;;;;;;;;;OAeG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,OAAO,CAAC;IACtC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACf;IA6CF,2EAA2E;;;;8BA3B5C,MAAM,cAAc;;6BAazB,gBAAgB;yBARpB,gBAAgB;;;IAkCtC,uDAAuD;;;;;;IAMvD,iEAAiE;;;;;;;EAQpE"}
1
+ {"version":3,"file":"useTooltip.d.ts","sourceRoot":"","sources":["../../../../tooltip/lib/useTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAmD/B;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,EACtD,IAAc,EACd,SAAc,EACd,SAAe,EACf,SAAe,GAChB,GAAE;IACD;;;;;;;;;;;;;;;OAeG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,OAAO,CAAC;IACtC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACf;IA8CF,2EAA2E;;;;8BA5B5C,MAAM,cAAc;;6BAazB,gBAAgB;yBARpB,gBAAgB;;;IAmCtC,uDAAuD;;;;;;IAMvD,iEAAiE;;;;;;;EAQpE"}
@@ -97,6 +97,7 @@ function useTooltip(_a) {
97
97
  popup_1.useCloseOnEscape(popupModel);
98
98
  popup_1.useAlwaysCloseOnOutsideClick(popupModel);
99
99
  popup_1.useCloseOnFullscreenExit(popupModel);
100
+ popup_1.useCloseOnTargetHidden(popupModel);
100
101
  var visible = popupModel.state.visibility !== 'hidden';
101
102
  return {
102
103
  /** Mix these properties into the target element. **Must be an Element** */
@@ -4,6 +4,7 @@ export * from './useBringToTopOnClick';
4
4
  export * from './useCloseOnEscape';
5
5
  export * from './useCloseOnFullscreenExit';
6
6
  export * from './useCloseOnOutsideClick';
7
+ export * from './useCloseOnTargetHidden';
7
8
  export * from './useDisableBodyScroll';
8
9
  export * from './useFocusRedirect';
9
10
  export * from './useFocusTrap';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC"}
@@ -4,6 +4,7 @@ export * from './useBringToTopOnClick';
4
4
  export * from './useCloseOnEscape';
5
5
  export * from './useCloseOnFullscreenExit';
6
6
  export * from './useCloseOnOutsideClick';
7
+ export * from './useCloseOnTargetHidden';
7
8
  export * from './useDisableBodyScroll';
8
9
  export * from './useFocusRedirect';
9
10
  export * from './useFocusTrap';
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ /**
3
+ * Sets up an
4
+ * [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)
5
+ * for the target element. When the target is detected as being less than 50% visible, the popup
6
+ * will close. Most likely, this will happen if the user scrolls an overflowed content area of the
7
+ * page and the target is no longer visible.
8
+ *
9
+ * This should be used with popup elements that are transitory like Tooltips and dropdown menus.
10
+ */
11
+ export declare const useCloseOnTargetHidden: <P extends {}, R>(model: {
12
+ state: {
13
+ stackRef: React.RefObject<HTMLDivElement>;
14
+ targetRef: React.RefObject<HTMLButtonElement>;
15
+ initialFocusRef: React.RefObject<any> | undefined;
16
+ returnFocusRef: React.RefObject<any> | undefined;
17
+ placement: import("@popperjs/core").Placement;
18
+ id: string;
19
+ visibility: import("../../..").Visibility;
20
+ };
21
+ events: {
22
+ updatePlacement(data: {
23
+ placement: import("@popperjs/core").Placement;
24
+ }): void;
25
+ show(event?: Event | React.SyntheticEvent<Element, Event> | undefined): void;
26
+ hide(event?: Event | React.SyntheticEvent<Element, Event> | undefined): void;
27
+ };
28
+ }, elemProps?: P | undefined, ref?: ((instance: R | null) => void) | React.RefObject<R> | null | undefined) => {} & P & (R extends HTMLOrSVGElement ? {
29
+ ref: React.Ref<R>;
30
+ } : {});
31
+ //# sourceMappingURL=useCloseOnTargetHidden.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCloseOnTargetHidden.d.ts","sourceRoot":"","sources":["../../../../../popup/lib/hooks/useCloseOnTargetHidden.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAuB1B;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;OAiCjC,CAAC"}
@@ -0,0 +1,50 @@
1
+ import React from 'react';
2
+ import { createElemPropsHook } from '@workday/canvas-kit-react/common';
3
+ import { usePopupModel } from '@workday/canvas-kit-react/popup';
4
+ function getScrollParent(element) {
5
+ if (element === document.body || !element.parentElement) {
6
+ return element;
7
+ }
8
+ var styles = getComputedStyle(element);
9
+ if (styles.overflowY === 'scroll' ||
10
+ styles.overflowY === 'auto' ||
11
+ styles.overflowX === 'scroll' ||
12
+ styles.overflowX === 'auto') {
13
+ return element;
14
+ }
15
+ return getScrollParent(element.parentElement);
16
+ }
17
+ /**
18
+ * Sets up an
19
+ * [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)
20
+ * for the target element. When the target is detected as being less than 50% visible, the popup
21
+ * will close. Most likely, this will happen if the user scrolls an overflowed content area of the
22
+ * page and the target is no longer visible.
23
+ *
24
+ * This should be used with popup elements that are transitory like Tooltips and dropdown menus.
25
+ */
26
+ export var useCloseOnTargetHidden = createElemPropsHook(usePopupModel)(function (model) {
27
+ var visible = model.state.visibility !== 'hidden';
28
+ var callback = React.useCallback(function (entries) {
29
+ if (entries[0].intersectionRatio < 0.5) {
30
+ model.events.hide();
31
+ }
32
+ }, [model.events]);
33
+ React.useLayoutEffect(function () {
34
+ if (!visible || !model.state.targetRef.current) {
35
+ return;
36
+ }
37
+ var target = model.state.targetRef.current;
38
+ var scrollParent = getScrollParent(target);
39
+ // eslint-disable-next-line compat/compat
40
+ var observer = new IntersectionObserver(callback, {
41
+ root: scrollParent,
42
+ threshold: 0.5,
43
+ });
44
+ observer.observe(model.state.targetRef.current);
45
+ return function () {
46
+ observer.disconnect();
47
+ };
48
+ }, [callback, model.state.targetRef, visible]);
49
+ return {};
50
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"TooltipContainer.d.ts","sourceRoot":"","sources":["../../../../tooltip/lib/TooltipContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,OAAO,EAAC,eAAe,EAAyB,MAAM,kCAAkC,CAAC;AAiBzF,MAAM,WAAW,qBAAsB,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IACjF;;;OAGG;IACH,eAAe,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IACzC;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,WAAW,CAAC,EAAE;QACZ,IAAI,EAAE,OAAO,CAAC;QACd,aAAa,EAAE,WAAW,GAAG,IAAI,CAAC;KACnC,CAAC;CACH;AAOD,eAAO,MAAM,gBAAgB;;;6GA4D5B,CAAC"}
1
+ {"version":3,"file":"TooltipContainer.d.ts","sourceRoot":"","sources":["../../../../tooltip/lib/TooltipContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,OAAO,EAAC,eAAe,EAAyB,MAAM,kCAAkC,CAAC;AAiBzF,MAAM,WAAW,qBAAsB,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IACjF;;;OAGG;IACH,eAAe,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IACzC;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,WAAW,CAAC,EAAE;QACZ,IAAI,EAAE,OAAO,CAAC;QACd,aAAa,EAAE,WAAW,GAAG,IAAI,CAAC;KACnC,CAAC;CACH;AAOD,eAAO,MAAM,gBAAgB;;;6GAkE5B,CAAC"}
@@ -49,6 +49,11 @@ export var TooltipContainer = styled('div')(__assign(__assign({}, type.levels.su
49
49
  margin: spaceNumbers.xxxs + 2,
50
50
  },
51
51
  },
52
+ // Hide tooltip when the reference element is either clipped or fully hidden
53
+ '[data-popper-reference-hidden] &': {
54
+ visibility: 'hidden',
55
+ pointerEvents: 'none',
56
+ },
52
57
  // Fix offsets based on placement
53
58
  '[data-popper-placement="top-start"] &, [data-popper-placement="bottom-start"] &': {
54
59
  left: -spaceNumbers.xxxs,
@@ -1 +1 @@
1
- {"version":3,"file":"useTooltip.d.ts","sourceRoot":"","sources":["../../../../tooltip/lib/useTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAkD/B;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,EACtD,IAAc,EACd,SAAc,EACd,SAAe,EACf,SAAe,GAChB,GAAE;IACD;;;;;;;;;;;;;;;OAeG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,OAAO,CAAC;IACtC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACf;IA6CF,2EAA2E;;;;8BA3B5C,MAAM,cAAc;;6BAazB,gBAAgB;yBARpB,gBAAgB;;;IAkCtC,uDAAuD;;;;;;IAMvD,iEAAiE;;;;;;;EAQpE"}
1
+ {"version":3,"file":"useTooltip.d.ts","sourceRoot":"","sources":["../../../../tooltip/lib/useTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAmD/B;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,EACtD,IAAc,EACd,SAAc,EACd,SAAe,EACf,SAAe,GAChB,GAAE;IACD;;;;;;;;;;;;;;;OAeG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,OAAO,CAAC;IACtC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACf;IA8CF,2EAA2E;;;;8BA5B5C,MAAM,cAAc;;6BAazB,gBAAgB;yBARpB,gBAAgB;;;IAmCtC,uDAAuD;;;;;;IAMvD,iEAAiE;;;;;;;EAQpE"}
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { useCloseOnEscape, useAlwaysCloseOnOutsideClick, usePopupModel, useCloseOnFullscreenExit, } from '@workday/canvas-kit-react/popup';
2
+ import { useCloseOnEscape, useAlwaysCloseOnOutsideClick, usePopupModel, useCloseOnFullscreenExit, useCloseOnTargetHidden, } from '@workday/canvas-kit-react/popup';
3
3
  import { useUniqueId } from '@workday/canvas-kit-react/common';
4
4
  var useIntentTimer = function (fn, waitMs) {
5
5
  if (waitMs === void 0) { waitMs = 0; }
@@ -75,6 +75,7 @@ export function useTooltip(_a) {
75
75
  useCloseOnEscape(popupModel);
76
76
  useAlwaysCloseOnOutsideClick(popupModel);
77
77
  useCloseOnFullscreenExit(popupModel);
78
+ useCloseOnTargetHidden(popupModel);
78
79
  var visible = popupModel.state.visibility !== 'hidden';
79
80
  return {
80
81
  /** Mix these properties into the target element. **Must be an Element** */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workday/canvas-kit-react",
3
- "version": "8.0.0-alpha.230-next.1+e0da0524",
3
+ "version": "8.0.0-alpha.232-next.3+d847ebea",
4
4
  "description": "The parent module that contains all Workday Canvas Kit React components",
5
5
  "author": "Workday, Inc. (https://www.workday.com)",
6
6
  "license": "Apache-2.0",
@@ -49,7 +49,7 @@
49
49
  "@emotion/styled": "^11.6.0",
50
50
  "@popperjs/core": "^2.5.4",
51
51
  "@workday/canvas-colors-web": "^2.0.0",
52
- "@workday/canvas-kit-popup-stack": "^8.0.0-alpha.230-next.1+e0da0524",
52
+ "@workday/canvas-kit-popup-stack": "^8.0.0-alpha.232-next.3+d847ebea",
53
53
  "@workday/canvas-system-icons-web": "^3.0.0",
54
54
  "@workday/design-assets-types": "^0.2.8",
55
55
  "chroma-js": "^2.1.0",
@@ -67,5 +67,5 @@
67
67
  "@workday/canvas-accent-icons-web": "^3.0.0",
68
68
  "@workday/canvas-applet-icons-web": "^2.0.0"
69
69
  },
70
- "gitHead": "e0da05248437dc3b372d1e4f819676580775237e"
70
+ "gitHead": "d847ebea604bcd0a3983526c03ce86a74f7adc93"
71
71
  }
@@ -4,6 +4,7 @@ export * from './useBringToTopOnClick';
4
4
  export * from './useCloseOnEscape';
5
5
  export * from './useCloseOnFullscreenExit';
6
6
  export * from './useCloseOnOutsideClick';
7
+ export * from './useCloseOnTargetHidden';
7
8
  export * from './useDisableBodyScroll';
8
9
  export * from './useFocusRedirect';
9
10
  export * from './useFocusTrap';
@@ -0,0 +1,66 @@
1
+ import React from 'react';
2
+
3
+ import {createElemPropsHook} from '@workday/canvas-kit-react/common';
4
+ import {usePopupModel} from '@workday/canvas-kit-react/popup';
5
+
6
+ function getScrollParent(element: HTMLElement): HTMLElement {
7
+ if (element === document.body || !element.parentElement) {
8
+ return element;
9
+ }
10
+ const styles = getComputedStyle(element);
11
+
12
+ if (
13
+ styles.overflowY === 'scroll' ||
14
+ styles.overflowY === 'auto' ||
15
+ styles.overflowX === 'scroll' ||
16
+ styles.overflowX === 'auto'
17
+ ) {
18
+ return element;
19
+ }
20
+
21
+ return getScrollParent(element.parentElement);
22
+ }
23
+
24
+ /**
25
+ * Sets up an
26
+ * [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)
27
+ * for the target element. When the target is detected as being less than 50% visible, the popup
28
+ * will close. Most likely, this will happen if the user scrolls an overflowed content area of the
29
+ * page and the target is no longer visible.
30
+ *
31
+ * This should be used with popup elements that are transitory like Tooltips and dropdown menus.
32
+ */
33
+ export const useCloseOnTargetHidden = createElemPropsHook(usePopupModel)(model => {
34
+ const visible = model.state.visibility !== 'hidden';
35
+
36
+ const callback: IntersectionObserverCallback = React.useCallback(
37
+ entries => {
38
+ if (entries[0].intersectionRatio < 0.5) {
39
+ model.events.hide();
40
+ }
41
+ },
42
+ [model.events]
43
+ );
44
+
45
+ React.useLayoutEffect(() => {
46
+ if (!visible || !model.state.targetRef.current) {
47
+ return;
48
+ }
49
+
50
+ const target = model.state.targetRef.current;
51
+ const scrollParent = getScrollParent(target);
52
+
53
+ // eslint-disable-next-line compat/compat
54
+ const observer = new IntersectionObserver(callback, {
55
+ root: scrollParent,
56
+ threshold: 0.5,
57
+ });
58
+
59
+ observer.observe(model.state.targetRef.current);
60
+ return () => {
61
+ observer.disconnect();
62
+ };
63
+ }, [callback, model.state.targetRef, visible]);
64
+
65
+ return {};
66
+ });
@@ -78,6 +78,12 @@ export const TooltipContainer = styled('div')<TooltipContainerProps>(
78
78
  },
79
79
  },
80
80
 
81
+ // Hide tooltip when the reference element is either clipped or fully hidden
82
+ '[data-popper-reference-hidden] &': {
83
+ visibility: 'hidden',
84
+ pointerEvents: 'none',
85
+ },
86
+
81
87
  // Fix offsets based on placement
82
88
  '[data-popper-placement="top-start"] &, [data-popper-placement="bottom-start"] &': {
83
89
  left: -spaceNumbers.xxxs,
@@ -4,6 +4,7 @@ import {
4
4
  useAlwaysCloseOnOutsideClick,
5
5
  usePopupModel,
6
6
  useCloseOnFullscreenExit,
7
+ useCloseOnTargetHidden,
7
8
  } from '@workday/canvas-kit-react/popup';
8
9
  import {useUniqueId} from '@workday/canvas-kit-react/common';
9
10
 
@@ -128,6 +129,7 @@ export function useTooltip<T extends Element = Element>({
128
129
  useCloseOnEscape(popupModel);
129
130
  useAlwaysCloseOnOutsideClick(popupModel);
130
131
  useCloseOnFullscreenExit(popupModel);
132
+ useCloseOnTargetHidden(popupModel);
131
133
 
132
134
  const visible = popupModel.state.visibility !== 'hidden';
133
135