@fluentui/react-portal 9.1.0 → 9.1.2

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.json CHANGED
@@ -2,7 +2,57 @@
2
2
  "name": "@fluentui/react-portal",
3
3
  "entries": [
4
4
  {
5
- "date": "Mon, 09 Jan 2023 14:31:46 GMT",
5
+ "date": "Wed, 18 Jan 2023 16:30:57 GMT",
6
+ "tag": "@fluentui/react-portal_v9.1.2",
7
+ "version": "9.1.2",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "lingfangao@hotmail.com",
12
+ "package": "@fluentui/react-portal",
13
+ "commit": "13cf1d07a6df4617106c731ba0379b6102a08104",
14
+ "comment": "fix: Insert css variables class at render time"
15
+ },
16
+ {
17
+ "author": "beachball",
18
+ "package": "@fluentui/react-portal",
19
+ "comment": "Bump @fluentui/react-tabster to v9.4.0",
20
+ "commit": "13cf1d07a6df4617106c731ba0379b6102a08104"
21
+ }
22
+ ]
23
+ }
24
+ },
25
+ {
26
+ "date": "Mon, 16 Jan 2023 08:39:07 GMT",
27
+ "tag": "@fluentui/react-portal_v9.1.1",
28
+ "version": "9.1.1",
29
+ "comments": {
30
+ "none": [
31
+ {
32
+ "author": "martinhochel@microsoft.com",
33
+ "package": "@fluentui/react-portal",
34
+ "commit": "64bb45980d68de1219c6b36a7db5363f0a9cff9f",
35
+ "comment": "chore: migrate to packaged scripts"
36
+ }
37
+ ],
38
+ "patch": [
39
+ {
40
+ "author": "beachball",
41
+ "package": "@fluentui/react-portal",
42
+ "comment": "Bump @fluentui/react-shared-contexts to v9.1.5",
43
+ "commit": "a870d8360e47f3ea03358c4e75e89e08a74845d7"
44
+ },
45
+ {
46
+ "author": "beachball",
47
+ "package": "@fluentui/react-portal",
48
+ "comment": "Bump @fluentui/react-tabster to v9.3.7",
49
+ "commit": "a870d8360e47f3ea03358c4e75e89e08a74845d7"
50
+ }
51
+ ]
52
+ }
53
+ },
54
+ {
55
+ "date": "Mon, 09 Jan 2023 14:34:59 GMT",
6
56
  "tag": "@fluentui/react-portal_v9.1.0",
7
57
  "version": "9.1.0",
8
58
  "comments": {
@@ -17,13 +67,13 @@
17
67
  "author": "beachball",
18
68
  "package": "@fluentui/react-portal",
19
69
  "comment": "Bump @fluentui/react-tabster to v9.3.6",
20
- "commit": "26f0364b3837056ee8e0df42a7932c298c68290e"
70
+ "commit": "d246e70eba59a37ec311dbf933b0745d34cb700d"
21
71
  },
22
72
  {
23
73
  "author": "beachball",
24
74
  "package": "@fluentui/react-portal",
25
75
  "comment": "Bump @fluentui/react-utilities to v9.4.0",
26
- "commit": "26f0364b3837056ee8e0df42a7932c298c68290e"
76
+ "commit": "d246e70eba59a37ec311dbf933b0745d34cb700d"
27
77
  }
28
78
  ]
29
79
  }
package/CHANGELOG.md CHANGED
@@ -1,19 +1,39 @@
1
1
  # Change Log - @fluentui/react-portal
2
2
 
3
- This log was last generated on Mon, 09 Jan 2023 14:31:46 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 18 Jan 2023 16:30:57 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.1.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-portal_v9.1.2)
8
+
9
+ Wed, 18 Jan 2023 16:30:57 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-portal_v9.1.1..@fluentui/react-portal_v9.1.2)
11
+
12
+ ### Patches
13
+
14
+ - fix: Insert css variables class at render time ([PR #26377](https://github.com/microsoft/fluentui/pull/26377) by lingfangao@hotmail.com)
15
+ - Bump @fluentui/react-tabster to v9.4.0 ([PR #26377](https://github.com/microsoft/fluentui/pull/26377) by beachball)
16
+
17
+ ## [9.1.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-portal_v9.1.1)
18
+
19
+ Mon, 16 Jan 2023 08:39:07 GMT
20
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-portal_v9.1.0..@fluentui/react-portal_v9.1.1)
21
+
22
+ ### Patches
23
+
24
+ - Bump @fluentui/react-shared-contexts to v9.1.5 ([commit](https://github.com/microsoft/fluentui/commit/a870d8360e47f3ea03358c4e75e89e08a74845d7) by beachball)
25
+ - Bump @fluentui/react-tabster to v9.3.7 ([commit](https://github.com/microsoft/fluentui/commit/a870d8360e47f3ea03358c4e75e89e08a74845d7) by beachball)
26
+
7
27
  ## [9.1.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-portal_v9.1.0)
8
28
 
9
- Mon, 09 Jan 2023 14:31:46 GMT
29
+ Mon, 09 Jan 2023 14:34:59 GMT
10
30
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-portal_v9.0.15..@fluentui/react-portal_v9.1.0)
11
31
 
12
32
  ### Minor changes
13
33
 
14
34
  - feat: elementContains supports Node types ([PR #26158](https://github.com/microsoft/fluentui/pull/26158) by email not defined)
15
- - Bump @fluentui/react-tabster to v9.3.6 ([PR #26257](https://github.com/microsoft/fluentui/pull/26257) by beachball)
16
- - Bump @fluentui/react-utilities to v9.4.0 ([PR #26257](https://github.com/microsoft/fluentui/pull/26257) by beachball)
35
+ - Bump @fluentui/react-tabster to v9.3.6 ([PR #26255](https://github.com/microsoft/fluentui/pull/26255) by beachball)
36
+ - Bump @fluentui/react-utilities to v9.4.0 ([PR #26255](https://github.com/microsoft/fluentui/pull/26255) by beachball)
17
37
 
18
38
  ## [9.0.15](https://github.com/microsoft/fluentui/tree/@fluentui/react-portal_v9.0.15)
19
39
 
@@ -3,9 +3,7 @@ import { useThemeClassName_unstable as useThemeClassName, useFluent_unstable as
3
3
  import { __styles, mergeClasses } from '@griffel/react';
4
4
  import { useFocusVisible } from '@fluentui/react-tabster';
5
5
  import { useDisposable } from 'use-disposable';
6
- import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
7
- // String concatenation is used to prevent bundlers to complain with older versions of React
8
- const useInsertionEffect = React['useInsertion' + 'Effect'] ? React['useInsertion' + 'Effect'] : useIsomorphicLayoutEffect;
6
+ const useInsertionEffect = React['useInsertion' + 'Effect'];
9
7
  const useStyles = /*#__PURE__*/__styles({
10
8
  root: {
11
9
  qhf8xq: "f10pi13n",
@@ -14,6 +12,7 @@ const useStyles = /*#__PURE__*/__styles({
14
12
  }, {
15
13
  d: [".f10pi13n{position:relative;}", ".f494woh{z-index:1000000;}"]
16
14
  });
15
+ const reactMajorVersion = /*#__PURE__*/Number( /*#__PURE__*/React.version.split('.')[0]);
17
16
  /**
18
17
  * Creates a new element on a document.body to mount portals
19
18
  */
@@ -34,23 +33,37 @@ export const usePortalMountNode = options => {
34
33
  targetDocument.body.appendChild(newElement);
35
34
  return [newElement, () => newElement.remove()];
36
35
  }, [targetDocument]);
37
- // This useEffect call is intentional
38
- // We don't want to re-create the portal element when its attributes change.
39
- // This also should not be done in an effect because, changing the value of css variables
40
- // after initial mount can trigger interesting CSS side effects like transitions.
41
- useInsertionEffect(() => {
42
- if (!element) {
43
- return;
44
- }
45
- const classesToApply = className.split(' ').filter(Boolean);
46
- element.classList.add(...classesToApply);
47
- element.setAttribute('dir', dir);
48
- focusVisibleRef.current = element;
49
- return () => {
50
- element.classList.remove(...classesToApply);
51
- element.removeAttribute('dir');
52
- };
53
- }, [className, dir, element, focusVisibleRef]);
36
+ if (reactMajorVersion >= 18) {
37
+ // eslint-disable-next-line react-hooks/rules-of-hooks
38
+ useInsertionEffect(() => {
39
+ if (!element) {
40
+ return;
41
+ }
42
+ const classesToApply = className.split(' ').filter(Boolean);
43
+ element.classList.add(...classesToApply);
44
+ element.setAttribute('dir', dir);
45
+ focusVisibleRef.current = element;
46
+ return () => {
47
+ element.classList.remove(...classesToApply);
48
+ element.removeAttribute('dir');
49
+ };
50
+ }, [className, dir, element, focusVisibleRef]);
51
+ } else {
52
+ // This useMemo call is intentional for React 17
53
+ // We don't want to re-create the portal element when its attributes change.
54
+ // This also should not be done in an effect because, changing the value of css variables
55
+ // after initial mount can trigger interesting CSS side effects like transitions.
56
+ // eslint-disable-next-line react-hooks/rules-of-hooks
57
+ React.useMemo(() => {
58
+ if (!element) {
59
+ return;
60
+ }
61
+ // Force replace all classes
62
+ element.className = className;
63
+ element.setAttribute('dir', dir);
64
+ focusVisibleRef.current = element;
65
+ }, [className, dir, element, focusVisibleRef]);
66
+ }
54
67
  return element;
55
68
  };
56
69
  //# sourceMappingURL=usePortalMountNode.js.map
@@ -1 +1 @@
1
- {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SACEC,0BAA0B,IAAIC,iBAAiB,EAC/CC,kBAAkB,IAAIC,SAAS,QAC1B,iCAAiC;AACxC,mBAAqBC,YAAY,QAAQ,gBAAgB;AACzD,SAASC,eAAe,QAAQ,yBAAyB;AACzD,SAASC,aAAa,QAAQ,gBAAgB;AAC9C,SAASC,yBAAyB,QAAQ,2BAA2B;AAErE;AACA,MAAMC,kBAAkB,GAAIT,KAAe,CAAC,cAAc,GAAG,QAAQ,CAAC,GACjEA,KAAe,CAAC,cAAc,GAAG,QAAQ,CAAC,GAC3CQ,yBAAyB;AAS7B,MAAME,SAAS,gBAAG;EAAA;IAAA;IAAA;EAAA;AAAA;EAAA;AAAA,EAKhB;AAEF;;;AAGA,OAAO,MAAMC,kBAAkB,GAAIC,OAAkC,IAAwB;EAC3F,MAAM;IAAEC,cAAc;IAAEC;EAAG,CAAE,GAAGV,SAAS,EAAE;EAC3C,MAAMW,eAAe,GAAGT,eAAe,EAAgE;EACvG,MAAMU,OAAO,GAAGN,SAAS,EAAE;EAC3B,MAAMO,cAAc,GAAGf,iBAAiB,EAAE;EAE1C,MAAMgB,SAAS,GAAGb,YAAY,CAACY,cAAc,EAAED,OAAO,CAACG,IAAI,CAAC;EAE5D,MAAMC,OAAO,GAAGb,aAAa,CAAC,MAAK;IACjC,IAAIM,cAAc,KAAKQ,SAAS,IAAIT,OAAO,CAACU,QAAQ,EAAE;MACpD,OAAO,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC;;IAG3B,MAAMC,UAAU,GAAGV,cAAc,CAACW,aAAa,CAAC,KAAK,CAAC;IACtDX,cAAc,CAACY,IAAI,CAACC,WAAW,CAACH,UAAU,CAAC;IAC3C,OAAO,CAACA,UAAU,EAAE,MAAMA,UAAU,CAACI,MAAM,EAAE,CAAC;EAChD,CAAC,EAAE,CAACd,cAAc,CAAC,CAAC;EAEpB;EACA;EACA;EACA;EACAJ,kBAAkB,CAAC,MAAK;IACtB,IAAI,CAACW,OAAO,EAAE;MACZ;;IAGF,MAAMQ,cAAc,GAAGV,SAAS,CAACW,KAAK,CAAC,GAAG,CAAC,CAACC,MAAM,CAACC,OAAO,CAAC;IAE3DX,OAAO,CAACY,SAAS,CAACC,GAAG,CAAC,GAAGL,cAAc,CAAC;IACxCR,OAAO,CAACc,YAAY,CAAC,KAAK,EAAEpB,GAAG,CAAC;IAChCC,eAAe,CAACoB,OAAO,GAAGf,OAAO;IAEjC,OAAO,MAAK;MACVA,OAAO,CAACY,SAAS,CAACL,MAAM,CAAC,GAAGC,cAAc,CAAC;MAC3CR,OAAO,CAACgB,eAAe,CAAC,KAAK,CAAC;IAChC,CAAC;EACH,CAAC,EAAE,CAAClB,SAAS,EAAEJ,GAAG,EAAEM,OAAO,EAAEL,eAAe,CAAC,CAAC;EAE9C,OAAOK,OAAO;AAChB,CAAC","names":["React","useThemeClassName_unstable","useThemeClassName","useFluent_unstable","useFluent","mergeClasses","useFocusVisible","useDisposable","useIsomorphicLayoutEffect","useInsertionEffect","useStyles","usePortalMountNode","options","targetDocument","dir","focusVisibleRef","classes","themeClassName","className","root","element","undefined","disabled","newElement","createElement","body","appendChild","remove","classesToApply","split","filter","Boolean","classList","add","setAttribute","current","removeAttribute"],"sourceRoot":"../src/","sources":["packages/react-components/react-portal/src/components/Portal/usePortalMountNode.ts"],"sourcesContent":["import * as React from 'react';\nimport {\n useThemeClassName_unstable as useThemeClassName,\n useFluent_unstable as useFluent,\n} from '@fluentui/react-shared-contexts';\nimport { makeStyles, mergeClasses } from '@griffel/react';\nimport { useFocusVisible } from '@fluentui/react-tabster';\nimport { useDisposable } from 'use-disposable';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\n\n// String concatenation is used to prevent bundlers to complain with older versions of React\nconst useInsertionEffect = (React as never)['useInsertion' + 'Effect']\n ? (React as never)['useInsertion' + 'Effect']\n : useIsomorphicLayoutEffect;\n\nexport type UsePortalMountNodeOptions = {\n /**\n * Since hooks cannot be called conditionally use this flag to disable creating the node\n */\n disabled?: boolean;\n};\n\nconst useStyles = makeStyles({\n root: {\n position: 'relative',\n zIndex: 1000000,\n },\n});\n\n/**\n * Creates a new element on a document.body to mount portals\n */\nexport const usePortalMountNode = (options: UsePortalMountNodeOptions): HTMLElement | null => {\n const { targetDocument, dir } = useFluent();\n const focusVisibleRef = useFocusVisible<HTMLDivElement>() as React.MutableRefObject<HTMLElement | null>;\n const classes = useStyles();\n const themeClassName = useThemeClassName();\n\n const className = mergeClasses(themeClassName, classes.root);\n\n const element = useDisposable(() => {\n if (targetDocument === undefined || options.disabled) {\n return [null, () => null];\n }\n\n const newElement = targetDocument.createElement('div');\n targetDocument.body.appendChild(newElement);\n return [newElement, () => newElement.remove()];\n }, [targetDocument]);\n\n // This useEffect call is intentional\n // We don't want to re-create the portal element when its attributes change.\n // This also should not be done in an effect because, changing the value of css variables\n // after initial mount can trigger interesting CSS side effects like transitions.\n useInsertionEffect(() => {\n if (!element) {\n return;\n }\n\n const classesToApply = className.split(' ').filter(Boolean);\n\n element.classList.add(...classesToApply);\n element.setAttribute('dir', dir);\n focusVisibleRef.current = element;\n\n return () => {\n element.classList.remove(...classesToApply);\n element.removeAttribute('dir');\n };\n }, [className, dir, element, focusVisibleRef]);\n\n return element;\n};\n"]}
1
+ {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SACEC,0BAA0B,IAAIC,iBAAiB,EAC/CC,kBAAkB,IAAIC,SAAS,QAC1B,iCAAiC;AACxC,mBAAqBC,YAAY,QAAQ,gBAAgB;AACzD,SAASC,eAAe,QAAQ,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DV,OAAO,CAACW,SAAS,CAACC,GAAG,CAAC,GAAGJ,cAAc,CAAC;MACxCR,OAAO,CAACa,YAAY,CAAC,KAAK,EAAEnB,GAAG,CAAC;MAChCC,eAAe,CAACmB,OAAO,GAAGd,OAAO;MAEjC,OAAO,MAAK;QACVA,OAAO,CAACW,SAAS,CAACJ,MAAM,CAAC,GAAGC,cAAc,CAAC;QAC3CR,OAAO,CAACe,eAAe,CAAC,KAAK,CAAC;MAChC,CAAC;IACH,CAAC,EAAE,CAACjB,SAAS,EAAEJ,GAAG,EAAEM,OAAO,EAAEL,eAAe,CAAC,CAAC;GAC/C,MAAM;IACL;IACA;IACA;IACA;IACA;IACAlB,KAAK,CAACuC,OAAO,CAAC,MAAK;MACjB,IAAI,CAAChB,OAAO,EAAE;QACZ;;MAGF;MACAA,OAAO,CAACF,SAAS,GAAGA,SAAS;MAC7BE,OAAO,CAACa,YAAY,CAAC,KAAK,EAAEnB,GAAG,CAAC;MAChCC,eAAe,CAACmB,OAAO,GAAGd,OAAO;IACnC,CAAC,EAAE,CAACF,SAAS,EAAEJ,GAAG,EAAEM,OAAO,EAAEL,eAAe,CAAC,CAAC;;EAGhD,OAAOK,OAAO;AAChB,CAAC","names":["React","useThemeClassName_unstable","useThemeClassName","useFluent_unstable","useFluent","mergeClasses","useFocusVisible","useDisposable","useInsertionEffect","useStyles","reactMajorVersion","Number","version","split","usePortalMountNode","options","targetDocument","dir","focusVisibleRef","classes","themeClassName","className","root","element","undefined","disabled","newElement","createElement","body","appendChild","remove","classesToApply","filter","Boolean","classList","add","setAttribute","current","removeAttribute","useMemo"],"sourceRoot":"../src/","sources":["packages/react-components/react-portal/src/components/Portal/usePortalMountNode.ts"],"sourcesContent":["import * as React from 'react';\nimport {\n useThemeClassName_unstable as useThemeClassName,\n useFluent_unstable as useFluent,\n} from '@fluentui/react-shared-contexts';\nimport { makeStyles, mergeClasses } from '@griffel/react';\nimport { useFocusVisible } from '@fluentui/react-tabster';\nimport { useDisposable } from 'use-disposable';\n\nconst useInsertionEffect = (React as never)['useInsertion' + 'Effect'] as typeof React.useLayoutEffect;\n\nexport type UsePortalMountNodeOptions = {\n /**\n * Since hooks cannot be called conditionally use this flag to disable creating the node\n */\n disabled?: boolean;\n};\n\nconst useStyles = makeStyles({\n root: {\n position: 'relative',\n zIndex: 1000000,\n },\n});\n\nconst reactMajorVersion = Number(React.version.split('.')[0]);\n\n/**\n * Creates a new element on a document.body to mount portals\n */\nexport const usePortalMountNode = (options: UsePortalMountNodeOptions): HTMLElement | null => {\n const { targetDocument, dir } = useFluent();\n const focusVisibleRef = useFocusVisible<HTMLDivElement>() as React.MutableRefObject<HTMLElement | null>;\n const classes = useStyles();\n const themeClassName = useThemeClassName();\n\n const className = mergeClasses(themeClassName, classes.root);\n\n const element = useDisposable(() => {\n if (targetDocument === undefined || options.disabled) {\n return [null, () => null];\n }\n\n const newElement = targetDocument.createElement('div');\n targetDocument.body.appendChild(newElement);\n return [newElement, () => newElement.remove()];\n }, [targetDocument]);\n\n if (reactMajorVersion >= 18) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useInsertionEffect(() => {\n if (!element) {\n return;\n }\n\n const classesToApply = className.split(' ').filter(Boolean);\n\n element.classList.add(...classesToApply);\n element.setAttribute('dir', dir);\n focusVisibleRef.current = element;\n\n return () => {\n element.classList.remove(...classesToApply);\n element.removeAttribute('dir');\n };\n }, [className, dir, element, focusVisibleRef]);\n } else {\n // This useMemo call is intentional for React 17\n // We don't want to re-create the portal element when its attributes change.\n // This also should not be done in an effect because, changing the value of css variables\n // after initial mount can trigger interesting CSS side effects like transitions.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useMemo(() => {\n if (!element) {\n return;\n }\n\n // Force replace all classes\n element.className = className;\n element.setAttribute('dir', dir);\n focusVisibleRef.current = element;\n }, [className, dir, element, focusVisibleRef]);\n }\n\n return element;\n};\n"]}
@@ -1,17 +1,15 @@
1
- define(["require", "exports", "react", "@fluentui/react-shared-contexts", "@griffel/react", "@fluentui/react-tabster", "use-disposable", "@fluentui/react-utilities"], function (require, exports, React, react_shared_contexts_1, react_1, react_tabster_1, use_disposable_1, react_utilities_1) {
1
+ define(["require", "exports", "react", "@fluentui/react-shared-contexts", "@griffel/react", "@fluentui/react-tabster", "use-disposable"], function (require, exports, React, react_shared_contexts_1, react_1, react_tabster_1, use_disposable_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.usePortalMountNode = void 0;
5
- // String concatenation is used to prevent bundlers to complain with older versions of React
6
- var useInsertionEffect = React['useInsertion' + 'Effect']
7
- ? React['useInsertion' + 'Effect']
8
- : react_utilities_1.useIsomorphicLayoutEffect;
5
+ var useInsertionEffect = React['useInsertion' + 'Effect'];
9
6
  var useStyles = react_1.makeStyles({
10
7
  root: {
11
8
  position: 'relative',
12
9
  zIndex: 1000000,
13
10
  },
14
11
  });
12
+ var reactMajorVersion = Number(React.version.split('.')[0]);
15
13
  /**
16
14
  * Creates a new element on a document.body to mount portals
17
15
  */
@@ -29,25 +27,40 @@ define(["require", "exports", "react", "@fluentui/react-shared-contexts", "@grif
29
27
  targetDocument.body.appendChild(newElement);
30
28
  return [newElement, function () { return newElement.remove(); }];
31
29
  }, [targetDocument]);
32
- // This useEffect call is intentional
33
- // We don't want to re-create the portal element when its attributes change.
34
- // This also should not be done in an effect because, changing the value of css variables
35
- // after initial mount can trigger interesting CSS side effects like transitions.
36
- useInsertionEffect(function () {
37
- var _a;
38
- if (!element) {
39
- return;
40
- }
41
- var classesToApply = className.split(' ').filter(Boolean);
42
- (_a = element.classList).add.apply(_a, classesToApply);
43
- element.setAttribute('dir', dir);
44
- focusVisibleRef.current = element;
45
- return function () {
30
+ if (reactMajorVersion >= 18) {
31
+ // eslint-disable-next-line react-hooks/rules-of-hooks
32
+ useInsertionEffect(function () {
46
33
  var _a;
47
- (_a = element.classList).remove.apply(_a, classesToApply);
48
- element.removeAttribute('dir');
49
- };
50
- }, [className, dir, element, focusVisibleRef]);
34
+ if (!element) {
35
+ return;
36
+ }
37
+ var classesToApply = className.split(' ').filter(Boolean);
38
+ (_a = element.classList).add.apply(_a, classesToApply);
39
+ element.setAttribute('dir', dir);
40
+ focusVisibleRef.current = element;
41
+ return function () {
42
+ var _a;
43
+ (_a = element.classList).remove.apply(_a, classesToApply);
44
+ element.removeAttribute('dir');
45
+ };
46
+ }, [className, dir, element, focusVisibleRef]);
47
+ }
48
+ else {
49
+ // This useMemo call is intentional for React 17
50
+ // We don't want to re-create the portal element when its attributes change.
51
+ // This also should not be done in an effect because, changing the value of css variables
52
+ // after initial mount can trigger interesting CSS side effects like transitions.
53
+ // eslint-disable-next-line react-hooks/rules-of-hooks
54
+ React.useMemo(function () {
55
+ if (!element) {
56
+ return;
57
+ }
58
+ // Force replace all classes
59
+ element.className = className;
60
+ element.setAttribute('dir', dir);
61
+ focusVisibleRef.current = element;
62
+ }, [className, dir, element, focusVisibleRef]);
63
+ }
51
64
  return element;
52
65
  };
53
66
  exports.usePortalMountNode = usePortalMountNode;
@@ -1 +1 @@
1
- {"version":3,"file":"usePortalMountNode.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-portal/src/components/Portal/usePortalMountNode.ts"],"names":[],"mappings":";;;;IAUA,4FAA4F;IAC5F,IAAM,kBAAkB,GAAI,KAAe,CAAC,cAAc,GAAG,QAAQ,CAAC;QACpE,CAAC,CAAE,KAAe,CAAC,cAAc,GAAG,QAAQ,CAAC;QAC7C,CAAC,CAAC,2CAAyB,CAAC;IAS9B,IAAM,SAAS,GAAG,kBAAU,CAAC;QAC3B,IAAI,EAAE;YACJ,QAAQ,EAAE,UAAU;YACpB,MAAM,EAAE,OAAO;SAChB;KACF,CAAC,CAAC;IAEH;;OAEG;IACI,IAAM,kBAAkB,GAAG,UAAC,OAAkC;QAC7D,IAAA,KAA0B,0CAAS,EAAE,EAAnC,cAAc,oBAAA,EAAE,GAAG,SAAgB,CAAC;QAC5C,IAAM,eAAe,GAAG,+BAAe,E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OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;QAE/C,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;IAxCW,QAAA,kBAAkB,sBAwC7B","sourcesContent":["import * as React from 'react';\nimport {\n useThemeClassName_unstable as useThemeClassName,\n useFluent_unstable as useFluent,\n} from '@fluentui/react-shared-contexts';\nimport { makeStyles, mergeClasses } from '@griffel/react';\nimport { useFocusVisible } from '@fluentui/react-tabster';\nimport { useDisposable } from 'use-disposable';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\n\n// String concatenation is used to prevent bundlers to complain with older versions of React\nconst useInsertionEffect = (React as never)['useInsertion' + 'Effect']\n ? (React as never)['useInsertion' + 'Effect']\n : useIsomorphicLayoutEffect;\n\nexport type UsePortalMountNodeOptions = {\n /**\n * Since hooks cannot be called conditionally use this flag to disable creating the node\n */\n disabled?: boolean;\n};\n\nconst useStyles = makeStyles({\n root: {\n position: 'relative',\n zIndex: 1000000,\n },\n});\n\n/**\n * Creates a new element on a document.body to mount portals\n */\nexport const usePortalMountNode = (options: UsePortalMountNodeOptions): HTMLElement | null => {\n const { targetDocument, dir } = useFluent();\n const focusVisibleRef = useFocusVisible<HTMLDivElement>() as React.MutableRefObject<HTMLElement | null>;\n const classes = useStyles();\n const themeClassName = useThemeClassName();\n\n const className = mergeClasses(themeClassName, classes.root);\n\n const element = useDisposable(() => {\n if (targetDocument === undefined || options.disabled) {\n return [null, () => null];\n }\n\n const newElement = targetDocument.createElement('div');\n targetDocument.body.appendChild(newElement);\n return [newElement, () => newElement.remove()];\n }, [targetDocument]);\n\n // This useEffect call is intentional\n // We don't want to re-create the portal element when its attributes change.\n // This also should not be done in an effect because, changing the value of css variables\n // after initial mount can trigger interesting CSS side effects like transitions.\n useInsertionEffect(() => {\n if (!element) {\n return;\n }\n\n const classesToApply = className.split(' ').filter(Boolean);\n\n element.classList.add(...classesToApply);\n element.setAttribute('dir', dir);\n focusVisibleRef.current = element;\n\n return () => {\n element.classList.remove(...classesToApply);\n element.removeAttribute('dir');\n };\n }, [className, dir, element, focusVisibleRef]);\n\n return element;\n};\n"]}
1
+ {"version":3,"file":"usePortalMountNode.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-portal/src/components/Portal/usePortalMountNode.ts"],"names":[],"mappings":";;;;IASA,IAAM,kBAAkB,GAAI,KAAe,CAAC,cAAc,GAAG,QAAQ,CAAiC,CAAC;IASvG,IAAM,SAAS,GAAG,kBAAU,CAAC;QAC3B,IAAI,EAAE;YACJ,QAAQ,EAAE,UAAU;YACpB,MAAM,EAAE,OAAO;SAChB;KACF,CAAC,CAAC;IAEH,IAAM,iBAAiB,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9D;;OAEG;IACI,IAAM,kBAAkB,GAAG,UAAC,OAAkC;QAC7D,IAAA,KAA0B,0CAAS,EAAE,EAAnC,cAAc,oBAAA,EAAE,GAAG,SAAgB,CAAC;QAC5C,IAAM,eAAe,GAAG,+BAAe,EAAgE,CAAC;QACxG,IAAM,OAAO,GAAG,SAAS,EAAE,CAAC;QAC5B,IAAM,cAAc,GAAG,kDAAiB,EAAE,CAAC;QAE3C,IAAM,SAAS,GAAG,oBAAY,CAAC,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QAE7D,IAAM,OAAO,GAAG,8BAAa,CAAC;YAC5B,IAAI,cAAc,KAAK,SAAS,IAAI,OAAO,CAAC,QAAQ,EAAE;gBACpD,OAAO,CAAC,IAAI,EAAE,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC,CAAC;aAC3B;YAED,IAAM,UAAU,GAAG,cAAc,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YACvD,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;YAC5C,OAAO,CAAC,UAAU,EAAE,cAAM,OAAA,UAAU,CAAC,MAAM,EAAE,EAAnB,CA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eClassName_unstable as useThemeClassName,\n useFluent_unstable as useFluent,\n} from '@fluentui/react-shared-contexts';\nimport { makeStyles, mergeClasses } from '@griffel/react';\nimport { useFocusVisible } from '@fluentui/react-tabster';\nimport { useDisposable } from 'use-disposable';\n\nconst useInsertionEffect = (React as never)['useInsertion' + 'Effect'] as typeof React.useLayoutEffect;\n\nexport type UsePortalMountNodeOptions = {\n /**\n * Since hooks cannot be called conditionally use this flag to disable creating the node\n */\n disabled?: boolean;\n};\n\nconst useStyles = makeStyles({\n root: {\n position: 'relative',\n zIndex: 1000000,\n },\n});\n\nconst reactMajorVersion = Number(React.version.split('.')[0]);\n\n/**\n * Creates a new element on a document.body to mount portals\n */\nexport const usePortalMountNode = (options: UsePortalMountNodeOptions): HTMLElement | null => {\n const { targetDocument, dir } = useFluent();\n const focusVisibleRef = useFocusVisible<HTMLDivElement>() as React.MutableRefObject<HTMLElement | null>;\n const classes = useStyles();\n const themeClassName = useThemeClassName();\n\n const className = mergeClasses(themeClassName, classes.root);\n\n const element = useDisposable(() => {\n if (targetDocument === undefined || options.disabled) {\n return [null, () => null];\n }\n\n const newElement = targetDocument.createElement('div');\n targetDocument.body.appendChild(newElement);\n return [newElement, () => newElement.remove()];\n }, [targetDocument]);\n\n if (reactMajorVersion >= 18) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useInsertionEffect(() => {\n if (!element) {\n return;\n }\n\n const classesToApply = className.split(' ').filter(Boolean);\n\n element.classList.add(...classesToApply);\n element.setAttribute('dir', dir);\n focusVisibleRef.current = element;\n\n return () => {\n element.classList.remove(...classesToApply);\n element.removeAttribute('dir');\n };\n }, [className, dir, element, focusVisibleRef]);\n } else {\n // This useMemo call is intentional for React 17\n // We don't want to re-create the portal element when its attributes change.\n // This also should not be done in an effect because, changing the value of css variables\n // after initial mount can trigger interesting CSS side effects like transitions.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useMemo(() => {\n if (!element) {\n return;\n }\n\n // Force replace all classes\n element.className = className;\n element.setAttribute('dir', dir);\n focusVisibleRef.current = element;\n }, [className, dir, element, focusVisibleRef]);\n }\n\n return element;\n};\n"]}
@@ -9,9 +9,7 @@ const react_shared_contexts_1 = /*#__PURE__*/require("@fluentui/react-shared-con
9
9
  const react_1 = /*#__PURE__*/require("@griffel/react");
10
10
  const react_tabster_1 = /*#__PURE__*/require("@fluentui/react-tabster");
11
11
  const use_disposable_1 = /*#__PURE__*/require("use-disposable");
12
- const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
13
- // String concatenation is used to prevent bundlers to complain with older versions of React
14
- const useInsertionEffect = React['useInsertion' + 'Effect'] ? React['useInsertion' + 'Effect'] : react_utilities_1.useIsomorphicLayoutEffect;
12
+ const useInsertionEffect = React['useInsertion' + 'Effect'];
15
13
  const useStyles = /*#__PURE__*/react_1.__styles({
16
14
  root: {
17
15
  qhf8xq: "f10pi13n",
@@ -20,6 +18,7 @@ const useStyles = /*#__PURE__*/react_1.__styles({
20
18
  }, {
21
19
  d: [".f10pi13n{position:relative;}", ".f494woh{z-index:1000000;}"]
22
20
  });
21
+ const reactMajorVersion = /*#__PURE__*/Number( /*#__PURE__*/React.version.split('.')[0]);
23
22
  /**
24
23
  * Creates a new element on a document.body to mount portals
25
24
  */
@@ -40,23 +39,37 @@ const usePortalMountNode = options => {
40
39
  targetDocument.body.appendChild(newElement);
41
40
  return [newElement, () => newElement.remove()];
42
41
  }, [targetDocument]);
43
- // This useEffect call is intentional
44
- // We don't want to re-create the portal element when its attributes change.
45
- // This also should not be done in an effect because, changing the value of css variables
46
- // after initial mount can trigger interesting CSS side effects like transitions.
47
- useInsertionEffect(() => {
48
- if (!element) {
49
- return;
50
- }
51
- const classesToApply = className.split(' ').filter(Boolean);
52
- element.classList.add(...classesToApply);
53
- element.setAttribute('dir', dir);
54
- focusVisibleRef.current = element;
55
- return () => {
56
- element.classList.remove(...classesToApply);
57
- element.removeAttribute('dir');
58
- };
59
- }, [className, dir, element, focusVisibleRef]);
42
+ if (reactMajorVersion >= 18) {
43
+ // eslint-disable-next-line react-hooks/rules-of-hooks
44
+ useInsertionEffect(() => {
45
+ if (!element) {
46
+ return;
47
+ }
48
+ const classesToApply = className.split(' ').filter(Boolean);
49
+ element.classList.add(...classesToApply);
50
+ element.setAttribute('dir', dir);
51
+ focusVisibleRef.current = element;
52
+ return () => {
53
+ element.classList.remove(...classesToApply);
54
+ element.removeAttribute('dir');
55
+ };
56
+ }, [className, dir, element, focusVisibleRef]);
57
+ } else {
58
+ // This useMemo call is intentional for React 17
59
+ // We don't want to re-create the portal element when its attributes change.
60
+ // This also should not be done in an effect because, changing the value of css variables
61
+ // after initial mount can trigger interesting CSS side effects like transitions.
62
+ // eslint-disable-next-line react-hooks/rules-of-hooks
63
+ React.useMemo(() => {
64
+ if (!element) {
65
+ return;
66
+ }
67
+ // Force replace all classes
68
+ element.className = className;
69
+ element.setAttribute('dir', dir);
70
+ focusVisibleRef.current = element;
71
+ }, [className, dir, element, focusVisibleRef]);
72
+ }
60
73
  return element;
61
74
  };
62
75
  exports.usePortalMountNode = usePortalMountNode;
@@ -1 +1 @@
1
- {"version":3,"mappings":";;;;;;AAAA;AACA;AAIA;AACA;AACA;AACA;AAEA;AACA,MAAMA,kBAAkB,GAAIC,KAAe,CAAC,cAAc,GAAG,QAAQ,CAAC,GACjEA,KAAe,CAAC,cAAc,GAAG,QAAQ,CAAC,GAC3CC,2CAAyB;AAS7B,MAAMC,SAAS,gBAAGC,gBAAU;EAAA;IAAA;IAAA;EAAA;AAAA;EAAA;AAAA,EAK1B;AAEF;;;AAGO,MAAMC,kBAAkB,GAAIC,OAAkC,IAAwB;EAC3F,MAAM;IAAEC,cAAc;IAAEC;EAAG,CAAE,GAAGC,0CAAS,EAAE;EAC3C,MAAMC,eAAe,GAAGC,+BAAe,EAAgE;EACvG,MAAMC,OAAO,GAAGT,SAAS,EAAE;EAC3B,MAAMU,cAAc,GAAGJ,kDAAiB,EAAE;EAE1C,MAAMK,SAAS,GAAGV,oBAAY,CAACS,cAAc,EAAED,OAAO,CAACG,IAAI,CAAC;EAE5D,MAAMC,OAAO,GAAGC,8BAAa,CAAC,MAAK;IACjC,IAAIV,cAAc,KAAKW,SAAS,IAAIZ,OAAO,CAACa,QAAQ,EAAE;MACpD,OAAO,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC;;IAG3B,MAAMC,UAAU,GAAGb,cAAc,CAACc,aAAa,CAAC,KAAK,CAAC;IACtDd,cAAc,CAACe,IAAI,CAACC,WAAW,CAACH,UAAU,CAAC;IAC3C,OAAO,CAACA,UAAU,EAAE,MAAMA,UAAU,CAACI,MAAM,EAAE,CAAC;EAChD,CAAC,EAAE,CAACjB,cAAc,CAAC,CAAC;EAEpB;EACA;EACA;EACA;EACAP,kBAAkB,CAAC,MAAK;IACtB,IAAI,CAACgB,OAAO,EAAE;MACZ;;IAGF,MAAMS,cAAc,GAAGX,SAAS,CAACY,KAAK,CAAC,GAAG,CAAC,CAACC,MAAM,CAACC,OAAO,CAAC;IAE3DZ,OAAO,CAACa,SAAS,CAACC,GAAG,CAAC,GAAGL,cAAc,CAAC;IACxCT,OAAO,CAACe,YAAY,CAAC,KAAK,EAAEvB,GAAG,CAAC;IAChCE,eAAe,CAACsB,OAAO,GAAGhB,OAAO;IAEjC,OAAO,MAAK;MACVA,OAAO,CAACa,SAAS,CAACL,MAAM,CAAC,GAAGC,cAAc,CAAC;MAC3CT,OAAO,CAACiB,eAAe,CAAC,KAAK,CAAC;IAChC,CAAC;EACH,CAAC,EAAE,CAACnB,SAAS,EAAEN,GAAG,EAAEQ,OAAO,EAAEN,eAAe,CAAC,CAAC;EAE9C,OAAOM,OAAO;AAChB,CAAC;AAxCYkB,0BAAkB","names":["useInsertionEffect","React","react_utilities_1","useStyles","react_1","usePortalMountNode","options","targetDocument","dir","react_shared_contexts_1","focusVisibleRef","react_tabster_1","classes","themeClassName","className","root","element","use_disposable_1","undefined","disabled","newElement","createElement","body","appendChild","remove","classesToApply","split","filter","Boolean","classList","add","setAttribute","current","removeAttribute","exports"],"sourceRoot":"../src/","sources":["packages/react-components/react-portal/src/components/Portal/usePortalMountNode.ts"],"sourcesContent":["import * as React from 'react';\nimport {\n useThemeClassName_unstable as useThemeClassName,\n useFluent_unstable as useFluent,\n} from '@fluentui/react-shared-contexts';\nimport { makeStyles, mergeClasses } from '@griffel/react';\nimport { useFocusVisible } from '@fluentui/react-tabster';\nimport { useDisposable } from 'use-disposable';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\n\n// String concatenation is used to prevent bundlers to complain with older versions of React\nconst useInsertionEffect = (React as never)['useInsertion' + 'Effect']\n ? (React as never)['useInsertion' + 'Effect']\n : useIsomorphicLayoutEffect;\n\nexport type UsePortalMountNodeOptions = {\n /**\n * Since hooks cannot be called conditionally use this flag to disable creating the node\n */\n disabled?: boolean;\n};\n\nconst useStyles = makeStyles({\n root: {\n position: 'relative',\n zIndex: 1000000,\n },\n});\n\n/**\n * Creates a new element on a document.body to mount portals\n */\nexport const usePortalMountNode = (options: UsePortalMountNodeOptions): HTMLElement | null => {\n const { targetDocument, dir } = useFluent();\n const focusVisibleRef = useFocusVisible<HTMLDivElement>() as React.MutableRefObject<HTMLElement | null>;\n const classes = useStyles();\n const themeClassName = useThemeClassName();\n\n const className = mergeClasses(themeClassName, classes.root);\n\n const element = useDisposable(() => {\n if (targetDocument === undefined || options.disabled) {\n return [null, () => null];\n }\n\n const newElement = targetDocument.createElement('div');\n targetDocument.body.appendChild(newElement);\n return [newElement, () => newElement.remove()];\n }, [targetDocument]);\n\n // This useEffect call is intentional\n // We don't want to re-create the portal element when its attributes change.\n // This also should not be done in an effect because, changing the value of css variables\n // after initial mount can trigger interesting CSS side effects like transitions.\n useInsertionEffect(() => {\n if (!element) {\n return;\n }\n\n const classesToApply = className.split(' ').filter(Boolean);\n\n element.classList.add(...classesToApply);\n element.setAttribute('dir', dir);\n focusVisibleRef.current = element;\n\n return () => {\n element.classList.remove(...classesToApply);\n element.removeAttribute('dir');\n };\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AK,CAAC,GAAG,CAAC,CAACsB,MAAM,CAACC,OAAO,CAAC;MAE3DX,OAAO,CAACY,SAAS,CAACC,GAAG,CAAC,GAAGJ,cAAc,CAAC;MACxCT,OAAO,CAACc,YAAY,CAAC,KAAK,EAAEtB,GAAG,CAAC;MAChCE,eAAe,CAACqB,OAAO,GAAGf,OAAO;MAEjC,OAAO,MAAK;QACVA,OAAO,CAACY,SAAS,CAACJ,MAAM,CAAC,GAAGC,cAAc,CAAC;QAC3CT,OAAO,CAACgB,eAAe,CAAC,KAAK,CAAC;MAChC,CAAC;IACH,CAAC,EAAE,CAAClB,SAAS,EAAEN,GAAG,EAAEQ,OAAO,EAAEN,eAAe,CAAC,CAAC;GAC/C,MAAM;IACL;IACA;IACA;IACA;IACA;IACAZ,KAAK,CAACmC,OAAO,CAAC,MAAK;MACjB,IAAI,CAACjB,OAAO,EAAE;QACZ;;MAGF;MACAA,OAAO,CAACF,SAAS,GAAGA,SAAS;MAC7BE,OAAO,CAACc,YAAY,CAAC,KAAK,EAAEtB,GAAG,CAAC;MAChCE,eAAe,CAACqB,OAAO,GAAGf,OAAO;IACnC,CAAC,EAAE,CAACF,SAAS,EAAEN,GAAG,EAAEQ,OAAO,EAAEN,eAAe,CAAC,CAAC;;EAGhD,OAAOM,OAAO;AAChB,CAAC;AAvDYkB,0BAAkB","names":["useInsertionEffect","React","useStyles","react_1","reactMajorVersion","Number","version","split","usePortalMountNode","options","targetDocument","dir","react_shared_contexts_1","focusVisibleRef","react_tabster_1","classes","themeClassName","className","root","element","use_disposable_1","undefined","disabled","newElement","createElement","body","appendChild","remove","classesToApply","filter","Boolean","classList","add","setAttribute","current","removeAttribute","useMemo","exports"],"sourceRoot":"../src/","sources":["packages/react-components/react-portal/src/components/Portal/usePortalMountNode.ts"],"sourcesContent":["import * as React from 'react';\nimport {\n useThemeClassName_unstable as useThemeClassName,\n useFluent_unstable as useFluent,\n} from '@fluentui/react-shared-contexts';\nimport { makeStyles, mergeClasses } from '@griffel/react';\nimport { useFocusVisible } from '@fluentui/react-tabster';\nimport { useDisposable } from 'use-disposable';\n\nconst useInsertionEffect = (React as never)['useInsertion' + 'Effect'] as typeof React.useLayoutEffect;\n\nexport type UsePortalMountNodeOptions = {\n /**\n * Since hooks cannot be called conditionally use this flag to disable creating the node\n */\n disabled?: boolean;\n};\n\nconst useStyles = makeStyles({\n root: {\n position: 'relative',\n zIndex: 1000000,\n },\n});\n\nconst reactMajorVersion = Number(React.version.split('.')[0]);\n\n/**\n * Creates a new element on a document.body to mount portals\n */\nexport const usePortalMountNode = (options: UsePortalMountNodeOptions): HTMLElement | null => {\n const { targetDocument, dir } = useFluent();\n const focusVisibleRef = useFocusVisible<HTMLDivElement>() as React.MutableRefObject<HTMLElement | null>;\n const classes = useStyles();\n const themeClassName = useThemeClassName();\n\n const className = mergeClasses(themeClassName, classes.root);\n\n const element = useDisposable(() => {\n if (targetDocument === undefined || options.disabled) {\n return [null, () => null];\n }\n\n const newElement = targetDocument.createElement('div');\n targetDocument.body.appendChild(newElement);\n return [newElement, () => newElement.remove()];\n }, [targetDocument]);\n\n if (reactMajorVersion >= 18) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useInsertionEffect(() => {\n if (!element) {\n return;\n }\n\n const classesToApply = className.split(' ').filter(Boolean);\n\n element.classList.add(...classesToApply);\n element.setAttribute('dir', dir);\n focusVisibleRef.current = element;\n\n return () => {\n element.classList.remove(...classesToApply);\n element.removeAttribute('dir');\n };\n }, [className, dir, element, focusVisibleRef]);\n } else {\n // This useMemo call is intentional for React 17\n // We don't want to re-create the portal element when its attributes change.\n // This also should not be done in an effect because, changing the value of css variables\n // after initial mount can trigger interesting CSS side effects like transitions.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useMemo(() => {\n if (!element) {\n return;\n }\n\n // Force replace all classes\n element.className = className;\n element.setAttribute('dir', dir);\n focusVisibleRef.current = element;\n }, [className, dir, element, focusVisibleRef]);\n }\n\n return element;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-portal",
3
- "version": "9.1.0",
3
+ "version": "9.1.2",
4
4
  "description": "A utility component that creates portals compatible with Fluent UI",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -27,11 +27,12 @@
27
27
  "devDependencies": {
28
28
  "@fluentui/eslint-plugin": "*",
29
29
  "@fluentui/react-conformance": "*",
30
- "@fluentui/scripts": "*"
30
+ "@fluentui/scripts-api-extractor": "*",
31
+ "@fluentui/scripts-tasks": "*"
31
32
  },
32
33
  "dependencies": {
33
- "@fluentui/react-shared-contexts": "^9.1.4",
34
- "@fluentui/react-tabster": "^9.3.6",
34
+ "@fluentui/react-shared-contexts": "^9.1.5",
35
+ "@fluentui/react-tabster": "^9.4.0",
35
36
  "@fluentui/react-utilities": "^9.4.0",
36
37
  "@griffel/react": "^1.5.2",
37
38
  "tslib": "^2.1.0",