@fluentui/react-menu-grid-preview 0.0.0-nightly-20250924-0412.1 → 0.0.0-nightly-20250926-0406.1

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/CHANGELOG.md CHANGED
@@ -1,26 +1,27 @@
1
1
  # Change Log - @fluentui/react-menu-grid-preview
2
2
 
3
- This log was last generated on Wed, 24 Sep 2025 04:27:15 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 26 Sep 2025 04:21:24 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## [0.0.0-nightly-20250924-0412.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-menu-grid-preview_v0.0.0-nightly-20250924-0412.1)
7
+ ## [0.0.0-nightly-20250926-0406.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-menu-grid-preview_v0.0.0-nightly-20250926-0406.1)
8
8
 
9
- Wed, 24 Sep 2025 04:27:15 GMT
10
- [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-menu-grid-preview_v0.1.1..@fluentui/react-menu-grid-preview_v0.0.0-nightly-20250924-0412.1)
9
+ Fri, 26 Sep 2025 04:21:24 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-menu-grid-preview_v0.1.1..@fluentui/react-menu-grid-preview_v0.0.0-nightly-20250926-0406.1)
11
11
 
12
12
  ### Changes
13
13
 
14
14
  - Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/not available) by fluentui-internal@service.microsoft.com)
15
- - Bump @fluentui/react-menu to v0.0.0-nightly-20250924-0412.1 ([commit](https://github.com/microsoft/fluentui/commit/cd1c2676b39bf3ac849359ad772ade50d50adff6) by beachball)
16
- - Bump @fluentui/react-table to v0.0.0-nightly-20250924-0412.1 ([commit](https://github.com/microsoft/fluentui/commit/cd1c2676b39bf3ac849359ad772ade50d50adff6) by beachball)
17
- - Bump @fluentui/react-tabster to v0.0.0-nightly-20250924-0412.1 ([commit](https://github.com/microsoft/fluentui/commit/cd1c2676b39bf3ac849359ad772ade50d50adff6) by beachball)
18
- - Bump @fluentui/react-jsx-runtime to v0.0.0-nightly-20250924-0412.1 ([commit](https://github.com/microsoft/fluentui/commit/cd1c2676b39bf3ac849359ad772ade50d50adff6) by beachball)
19
- - Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20250924-0412.1 ([commit](https://github.com/microsoft/fluentui/commit/cd1c2676b39bf3ac849359ad772ade50d50adff6) by beachball)
20
- - Bump @fluentui/react-theme to v0.0.0-nightly-20250924-0412.1 ([commit](https://github.com/microsoft/fluentui/commit/cd1c2676b39bf3ac849359ad772ade50d50adff6) by beachball)
21
- - Bump @fluentui/react-utilities to v0.0.0-nightly-20250924-0412.1 ([commit](https://github.com/microsoft/fluentui/commit/cd1c2676b39bf3ac849359ad772ade50d50adff6) by beachball)
22
- - Bump @fluentui/react-conformance to v0.0.0-nightly-20250924-0412.1 ([commit](https://github.com/microsoft/fluentui/commit/cd1c2676b39bf3ac849359ad772ade50d50adff6) by beachball)
23
- - Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-20250924-0412.1 ([commit](https://github.com/microsoft/fluentui/commit/cd1c2676b39bf3ac849359ad772ade50d50adff6) by beachball)
15
+ - Bump @fluentui/keyboard-keys to v0.0.0-nightly-20250926-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/e96bd2bc13e0c107fb06cdfdf1c9837abc5d6565) by beachball)
16
+ - Bump @fluentui/react-menu to v0.0.0-nightly-20250926-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/e96bd2bc13e0c107fb06cdfdf1c9837abc5d6565) by beachball)
17
+ - Bump @fluentui/react-table to v0.0.0-nightly-20250926-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/e96bd2bc13e0c107fb06cdfdf1c9837abc5d6565) by beachball)
18
+ - Bump @fluentui/react-tabster to v0.0.0-nightly-20250926-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/e96bd2bc13e0c107fb06cdfdf1c9837abc5d6565) by beachball)
19
+ - Bump @fluentui/react-jsx-runtime to v0.0.0-nightly-20250926-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/e96bd2bc13e0c107fb06cdfdf1c9837abc5d6565) by beachball)
20
+ - Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20250926-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/e96bd2bc13e0c107fb06cdfdf1c9837abc5d6565) by beachball)
21
+ - Bump @fluentui/react-theme to v0.0.0-nightly-20250926-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/e96bd2bc13e0c107fb06cdfdf1c9837abc5d6565) by beachball)
22
+ - Bump @fluentui/react-utilities to v0.0.0-nightly-20250926-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/e96bd2bc13e0c107fb06cdfdf1c9837abc5d6565) by beachball)
23
+ - Bump @fluentui/react-conformance to v0.0.0-nightly-20250926-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/e96bd2bc13e0c107fb06cdfdf1c9837abc5d6565) by beachball)
24
+ - Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-20250926-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/e96bd2bc13e0c107fb06cdfdf1c9837abc5d6565) by beachball)
24
25
 
25
26
  ## [0.1.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-menu-grid-preview_v0.1.1)
26
27
 
@@ -1,11 +1,21 @@
1
1
  import * as React from 'react';
2
- import { useMergedRefs, getIntrinsicElementProps, slot } from '@fluentui/react-utilities';
2
+ import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
3
+ import { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';
4
+ import { useMergedRefs, useEventCallback, mergeCallbacks, getIntrinsicElementProps, slot } from '@fluentui/react-utilities';
3
5
  import { useValidateNesting } from '../../utils/useValidateNesting';
4
6
  /**
5
7
  * Given user props, returns state and render function for a MenuGridCell.
6
8
  */ export function useMenuGridCell_unstable(props, ref) {
7
- const validateNestingRef = useValidateNesting('MenuGridCell');
8
9
  const { visuallyHidden } = props;
10
+ const validateNestingRef = useValidateNesting('MenuGridCell');
11
+ const { dir } = useFluent();
12
+ const CloseArrowKey = dir === 'ltr' ? ArrowLeft : ArrowRight;
13
+ const onKeyDownWithPrevent = useEventCallback((event)=>{
14
+ if (event.key === CloseArrowKey) {
15
+ event.preventDefault();
16
+ }
17
+ });
18
+ const onKeyDown = useEventCallback(mergeCallbacks(props.onKeyDown, onKeyDownWithPrevent));
9
19
  return {
10
20
  visuallyHidden,
11
21
  components: {
@@ -14,7 +24,8 @@ import { useValidateNesting } from '../../utils/useValidateNesting';
14
24
  root: slot.always(getIntrinsicElementProps('div', {
15
25
  ref: useMergedRefs(ref, validateNestingRef),
16
26
  role: 'gridcell',
17
- ...props
27
+ ...props,
28
+ onKeyDown
18
29
  }), {
19
30
  elementType: 'div'
20
31
  })
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/MenuGridCell/useMenuGridCell.ts"],"sourcesContent":["import * as React from 'react';\nimport { useMergedRefs, getIntrinsicElementProps, slot } from '@fluentui/react-utilities';\nimport { MenuGridCellProps, MenuGridCellState } from './MenuGridCell.types';\nimport { useValidateNesting } from '../../utils/useValidateNesting';\n\n/**\n * Given user props, returns state and render function for a MenuGridCell.\n */\nexport function useMenuGridCell_unstable(props: MenuGridCellProps, ref: React.Ref<HTMLDivElement>): MenuGridCellState {\n const validateNestingRef = useValidateNesting('MenuGridCell');\n const { visuallyHidden } = props;\n\n return {\n visuallyHidden,\n components: {\n root: 'div',\n },\n root: slot.always(\n getIntrinsicElementProps('div', {\n ref: useMergedRefs(ref, validateNestingRef),\n role: 'gridcell',\n ...props,\n }),\n { elementType: 'div' },\n ),\n };\n}\n"],"names":["React","useMergedRefs","getIntrinsicElementProps","slot","useValidateNesting","useMenuGridCell_unstable","props","ref","validateNestingRef","visuallyHidden","components","root","always","role","elementType"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,aAAa,EAAEC,wBAAwB,EAAEC,IAAI,QAAQ,4BAA4B;AAE1F,SAASC,kBAAkB,QAAQ,iCAAiC;AAEpE;;CAEC,GACD,OAAO,SAASC,yBAAyBC,KAAwB,EAAEC,GAA8B;IAC/F,MAAMC,qBAAqBJ,mBAAmB;IAC9C,MAAM,EAAEK,cAAc,EAAE,GAAGH;IAE3B,OAAO;QACLG;QACAC,YAAY;YACVC,MAAM;QACR;QACAA,MAAMR,KAAKS,MAAM,CACfV,yBAAyB,OAAO;YAC9BK,KAAKN,cAAcM,KAAKC;YACxBK,MAAM;YACN,GAAGP,KAAK;QACV,IACA;YAAEQ,aAAa;QAAM;IAEzB;AACF"}
1
+ {"version":3,"sources":["../src/components/MenuGridCell/useMenuGridCell.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';\nimport {\n useMergedRefs,\n useEventCallback,\n mergeCallbacks,\n getIntrinsicElementProps,\n slot,\n} from '@fluentui/react-utilities';\nimport { MenuGridCellProps, MenuGridCellState } from './MenuGridCell.types';\nimport { useValidateNesting } from '../../utils/useValidateNesting';\n\n/**\n * Given user props, returns state and render function for a MenuGridCell.\n */\nexport function useMenuGridCell_unstable(props: MenuGridCellProps, ref: React.Ref<HTMLDivElement>): MenuGridCellState {\n const { visuallyHidden } = props;\n const validateNestingRef = useValidateNesting('MenuGridCell');\n const { dir } = useFluent();\n\n const CloseArrowKey = dir === 'ltr' ? ArrowLeft : ArrowRight;\n const onKeyDownWithPrevent = useEventCallback((event: React.KeyboardEvent<HTMLElement>) => {\n if (event.key === CloseArrowKey) {\n event.preventDefault();\n }\n });\n const onKeyDown = useEventCallback(mergeCallbacks(props.onKeyDown, onKeyDownWithPrevent));\n\n return {\n visuallyHidden,\n components: {\n root: 'div',\n },\n root: slot.always(\n getIntrinsicElementProps('div', {\n ref: useMergedRefs(ref, validateNestingRef),\n role: 'gridcell',\n ...props,\n onKeyDown,\n }),\n { elementType: 'div' },\n ),\n };\n}\n"],"names":["React","useFluent_unstable","useFluent","ArrowLeft","ArrowRight","useMergedRefs","useEventCallback","mergeCallbacks","getIntrinsicElementProps","slot","useValidateNesting","useMenuGridCell_unstable","props","ref","visuallyHidden","validateNestingRef","dir","CloseArrowKey","onKeyDownWithPrevent","event","key","preventDefault","onKeyDown","components","root","always","role","elementType"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,SAAS,EAAEC,UAAU,QAAQ,0BAA0B;AAChE,SACEC,aAAa,EACbC,gBAAgB,EAChBC,cAAc,EACdC,wBAAwB,EACxBC,IAAI,QACC,4BAA4B;AAEnC,SAASC,kBAAkB,QAAQ,iCAAiC;AAEpE;;CAEC,GACD,OAAO,SAASC,yBAAyBC,KAAwB,EAAEC,GAA8B;IAC/F,MAAM,EAAEC,cAAc,EAAE,GAAGF;IAC3B,MAAMG,qBAAqBL,mBAAmB;IAC9C,MAAM,EAAEM,GAAG,EAAE,GAAGd;IAEhB,MAAMe,gBAAgBD,QAAQ,QAAQb,YAAYC;IAClD,MAAMc,uBAAuBZ,iBAAiB,CAACa;QAC7C,IAAIA,MAAMC,GAAG,KAAKH,eAAe;YAC/BE,MAAME,cAAc;QACtB;IACF;IACA,MAAMC,YAAYhB,iBAAiBC,eAAeK,MAAMU,SAAS,EAAEJ;IAEnE,OAAO;QACLJ;QACAS,YAAY;YACVC,MAAM;QACR;QACAA,MAAMf,KAAKgB,MAAM,CACfjB,yBAAyB,OAAO;YAC9BK,KAAKR,cAAcQ,KAAKE;YACxBW,MAAM;YACN,GAAGd,KAAK;YACRU;QACF,IACA;YAAEK,aAAa;QAAM;IAEzB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/useValidateNesting.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nimport type { MenuContextValue } from '@fluentui/react-menu';\nimport { useMenuContext_unstable } from '@fluentui/react-menu';\n\ntype NestingComponentName = 'MenuGrid' | 'MenuGridCell' | 'MenuGridItem' | 'MenuGridRow';\ntype MenuItemRoles = 'menuitem' | 'menuitemcheckbox' | 'menuitemradio';\n\nconst menuItemRoleToNameMapping = {\n menuitem: 'MenuItem',\n menuitemcheckbox: 'MenuItemCheckbox',\n menuitemradio: 'MenuItemRadio',\n};\n\nexport const useValidateNesting = (componentName: NestingComponentName): React.RefObject<HTMLElement> => {\n 'use no memo';\n\n const { targetDocument } = useFluent();\n const triggerRef = useMenuContext_unstable((context: MenuContextValue) => context.triggerRef);\n const inline = useMenuContext_unstable((context: MenuContextValue) => context.inline);\n const ref = React.useRef<HTMLElement>(null);\n\n if (process.env.NODE_ENV !== 'production') {\n // This check should run only in development mode\n // It's okay to disable the ESLint rule because we ar checking env variable statically (not at runtime)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n let ancestor = ref.current;\n let ancestorRole;\n\n do {\n ancestor = ancestor?.parentElement ?? null;\n ancestorRole = ancestor?.getAttribute('role');\n if (ancestor?.classList.contains('fui-MenuGrid')) {\n if (componentName === 'MenuGridCell') {\n throw new Error(\n 'MenuGridCell is incorrectly nested within MenuGrid. You probably want to wrap it in a MenuGridRow.',\n );\n }\n break;\n }\n if (ancestor?.classList.contains('fui-MenuGridRow') && componentName === 'MenuGridCell') {\n break;\n }\n if (['menuitem', 'menuitemcheckbox', 'menuitemradio'].includes(ancestorRole ?? '')) {\n throw new Error(\n `${componentName} is incorrectly nested within ${\n menuItemRoleToNameMapping[ancestorRole as MenuItemRoles]\n } or within an element with the \"${ancestorRole}\" role.`,\n );\n }\n if (ancestorRole === 'menu') {\n let message = '';\n let breakAncestorTraversal = false;\n switch (componentName) {\n case 'MenuGrid':\n if (inline && getMenuOfTrigger(triggerRef.current, targetDocument) === ancestor) {\n // Handle the case when MenuGrid is inline next to its menu trigger which is a submenu item of the parent menu\n breakAncestorTraversal = true;\n break;\n }\n message = 'MenuGrid is incorrectly nested within MenuList or within an element with the \"menu\" role.';\n break;\n case 'MenuGridCell':\n message =\n 'MenuGridCell is incorrectly nested within MenuList or within an element with the \"menu\" role. You probably want to wrap it in a MenuGridRow.';\n break;\n case 'MenuGridItem':\n message =\n 'MenuGridItem is incorrectly nested within MenuList or within an element with the \"menu\" role. You probably want to wrap it in a MenuGrid instead.';\n break;\n case 'MenuGridRow':\n message =\n 'MenuGridRow is incorrectly nested within MenuList or within an element with the \"menu\" role. You probably want to wrap it in a MenuGrid instead.';\n break;\n }\n if (breakAncestorTraversal) {\n break;\n }\n throw new Error(message);\n }\n } while (ancestor && ancestor !== targetDocument?.body);\n }, [componentName, ref, triggerRef, inline, targetDocument]);\n }\n return ref;\n};\n\nconst getMenuOfTrigger = (trigger: HTMLElement | null, targetDocument?: Document): HTMLElement | null => {\n let ancestor = trigger?.parentElement;\n while (ancestor && ancestor !== targetDocument?.body) {\n if (ancestor?.getAttribute('role') === 'menu') {\n return ancestor;\n }\n ancestor = ancestor?.parentElement ?? null;\n }\n return null;\n};\n"],"names":["React","useFluent_unstable","useFluent","useMenuContext_unstable","menuItemRoleToNameMapping","menuitem","menuitemcheckbox","menuitemradio","useValidateNesting","componentName","targetDocument","triggerRef","context","inline","ref","useRef","process","env","NODE_ENV","useEffect","ancestor","current","ancestorRole","parentElement","getAttribute","classList","contains","Error","includes","message","breakAncestorTraversal","getMenuOfTrigger","body","trigger"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAGlF,SAASC,uBAAuB,QAAQ,uBAAuB;AAK/D,MAAMC,4BAA4B;IAChCC,UAAU;IACVC,kBAAkB;IAClBC,eAAe;AACjB;AAEA,OAAO,MAAMC,qBAAqB,CAACC;IACjC;IAEA,MAAM,EAAEC,cAAc,EAAE,GAAGR;IAC3B,MAAMS,aAAaR,wBAAwB,CAACS,UAA8BA,QAA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HA,UACE;4BACF;oBACJ;oBACA,IAAIC,wBAAwB;wBAC1B;oBACF;oBACA,MAAM,IAAIH,MAAME;gBAClB;YACF,QAAST,YAAYA,cAAaV,2BAAAA,qCAAAA,eAAgBsB,IAAI,EAAE;QAC1D,GAAG;YAACvB;YAAeK;YAAKH;YAAYE;YAAQH;SAAe;IAC7D;IACA,OAAOI;AACT,EAAE;AAEF,MAAMiB,mBAAmB,CAACE,SAA6BvB;IACrD,IAAIU,WAAWa,oBAAAA,8BAAAA,QAASV,aAAa;IACrC,MAAOH,YAAYA,cAAaV,2BAAAA,qCAAAA,eAAgBsB,IAAI,EAAE;QACpD,IAAIZ,CAAAA,qBAAAA,+BAAAA,SAAUI,YAAY,CAAC,aAAY,QAAQ;YAC7C,OAAOJ;QACT;YACWA;QAAXA,WAAWA,CAAAA,0BAAAA,qBAAAA,+BAAAA,SAAUG,aAAa,cAAvBH,qCAAAA,0BAA2B;IACxC;IACA,OAAO;AACT"}
1
+ {"version":3,"sources":["../src/utils/useValidateNesting.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nimport type { MenuContextValue } from '@fluentui/react-menu';\nimport { useMenuContext_unstable } from '@fluentui/react-menu';\n\ntype NestingComponentName = 'MenuGrid' | 'MenuGridCell' | 'MenuGridItem' | 'MenuGridRow';\ntype MenuItemRoles = 'menuitem' | 'menuitemcheckbox' | 'menuitemradio';\n\nconst menuItemRoleToNameMapping = {\n menuitem: 'MenuItem',\n menuitemcheckbox: 'MenuItemCheckbox',\n menuitemradio: 'MenuItemRadio',\n};\n\nexport const useValidateNesting = (componentName: NestingComponentName): React.RefObject<HTMLElement | null> => {\n 'use no memo';\n\n const { targetDocument } = useFluent();\n const triggerRef = useMenuContext_unstable((context: MenuContextValue) => context.triggerRef);\n const inline = useMenuContext_unstable((context: MenuContextValue) => context.inline);\n const ref = React.useRef<HTMLElement | null>(null);\n\n if (process.env.NODE_ENV !== 'production') {\n // This check should run only in development mode\n // It's okay to disable the ESLint rule because we ar checking env variable statically (not at runtime)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n let ancestor = ref.current;\n let ancestorRole;\n\n do {\n ancestor = ancestor?.parentElement ?? null;\n ancestorRole = ancestor?.getAttribute('role');\n if (ancestor?.classList.contains('fui-MenuGrid')) {\n if (componentName === 'MenuGridCell') {\n throw new Error(\n 'MenuGridCell is incorrectly nested within MenuGrid. You probably want to wrap it in a MenuGridRow.',\n );\n }\n break;\n }\n if (ancestor?.classList.contains('fui-MenuGridRow') && componentName === 'MenuGridCell') {\n break;\n }\n if (['menuitem', 'menuitemcheckbox', 'menuitemradio'].includes(ancestorRole ?? '')) {\n throw new Error(\n `${componentName} is incorrectly nested within ${\n menuItemRoleToNameMapping[ancestorRole as MenuItemRoles]\n } or within an element with the \"${ancestorRole}\" role.`,\n );\n }\n if (ancestorRole === 'menu') {\n let message = '';\n let breakAncestorTraversal = false;\n switch (componentName) {\n case 'MenuGrid':\n if (inline && getMenuOfTrigger(triggerRef.current, targetDocument) === ancestor) {\n // Handle the case when MenuGrid is inline next to its menu trigger which is a submenu item of the parent menu\n breakAncestorTraversal = true;\n break;\n }\n message = 'MenuGrid is incorrectly nested within MenuList or within an element with the \"menu\" role.';\n break;\n case 'MenuGridCell':\n message =\n 'MenuGridCell is incorrectly nested within MenuList or within an element with the \"menu\" role. You probably want to wrap it in a MenuGridRow.';\n break;\n case 'MenuGridItem':\n message =\n 'MenuGridItem is incorrectly nested within MenuList or within an element with the \"menu\" role. You probably want to wrap it in a MenuGrid instead.';\n break;\n case 'MenuGridRow':\n message =\n 'MenuGridRow is incorrectly nested within MenuList or within an element with the \"menu\" role. You probably want to wrap it in a MenuGrid instead.';\n break;\n }\n if (breakAncestorTraversal) {\n break;\n }\n throw new Error(message);\n }\n } while (ancestor && ancestor !== targetDocument?.body);\n }, [componentName, ref, triggerRef, inline, targetDocument]);\n }\n return ref;\n};\n\nconst getMenuOfTrigger = (trigger: HTMLElement | null, targetDocument?: Document): HTMLElement | null => {\n let ancestor = trigger?.parentElement;\n while (ancestor && ancestor !== targetDocument?.body) {\n if (ancestor?.getAttribute('role') === 'menu') {\n return ancestor;\n }\n ancestor = ancestor?.parentElement ?? null;\n }\n return null;\n};\n"],"names":["React","useFluent_unstable","useFluent","useMenuContext_unstable","menuItemRoleToNameMapping","menuitem","menuitemcheckbox","menuitemradio","useValidateNesting","componentName","targetDocument","triggerRef","context","inline","ref","useRef","process","env","NODE_ENV","useEffect","ancestor","current","ancestorRole","parentElement","getAttribute","classList","contains","Error","includes","message","breakAncestorTraversal","getMenuOfTrigger","body","trigger"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAGlF,SAASC,uBAAuB,QAAQ,uBAAuB;AAK/D,MAAMC,4BAA4B;IAChCC,UAAU;IACVC,kBAAkB;IAClBC,eAAe;AACjB;AAEA,OAAO,MAAMC,qBAAqB,CAACC;IACjC;IAEA,MAAM,EAAEC,cAAc,EAAE,GAAGR;IAC3B,MAAMS,aAAaR,wBAAwB,CAACS,UAA8BA,QAAQD,UAAU;IAC5F,MAAME,SAASV,wBAAwB,CAACS,UAA8BA,QAAQC,MAAM;IACpF,MAAMC,MAAMd,MAAMe,MAAM,CAAqB;IAE7C,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,iDAAiD;QACjD,uGAAuG;QACvG,sDAAsD;QACtDlB,MAAMmB,SAAS,CAAC;YACd,IAAIC,WAAWN,IAAIO,OAAO;YAC1B,IAAIC;YAEJ,GAAG;oBACUF;gBAAXA,WAAWA,CAAAA,0BAAAA,qBAAAA,+BAAAA,SAAUG,aAAa,cAAvBH,qCAAAA,0BAA2B;gBACtCE,eAAeF,qBAAAA,+BAAAA,SAAUI,YAAY,CAAC;gBACtC,IAAIJ,qBAAAA,+BAAAA,SAAUK,SAAS,CAACC,QAAQ,CAAC,iBAAiB;oB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,0BAAAA,qBAAAA,+BAAAA,SAAUG,aAAa,cAAvBH,qCAAAA,0BAA2B;IACxC;IACA,OAAO;AACT"}
@@ -10,11 +10,21 @@ Object.defineProperty(exports, "useMenuGridCell_unstable", {
10
10
  });
11
11
  const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
12
  const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
13
+ const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
14
+ const _keyboardkeys = require("@fluentui/keyboard-keys");
13
15
  const _reactutilities = require("@fluentui/react-utilities");
14
16
  const _useValidateNesting = require("../../utils/useValidateNesting");
15
17
  function useMenuGridCell_unstable(props, ref) {
16
- const validateNestingRef = (0, _useValidateNesting.useValidateNesting)('MenuGridCell');
17
18
  const { visuallyHidden } = props;
19
+ const validateNestingRef = (0, _useValidateNesting.useValidateNesting)('MenuGridCell');
20
+ const { dir } = (0, _reactsharedcontexts.useFluent_unstable)();
21
+ const CloseArrowKey = dir === 'ltr' ? _keyboardkeys.ArrowLeft : _keyboardkeys.ArrowRight;
22
+ const onKeyDownWithPrevent = (0, _reactutilities.useEventCallback)((event)=>{
23
+ if (event.key === CloseArrowKey) {
24
+ event.preventDefault();
25
+ }
26
+ });
27
+ const onKeyDown = (0, _reactutilities.useEventCallback)((0, _reactutilities.mergeCallbacks)(props.onKeyDown, onKeyDownWithPrevent));
18
28
  return {
19
29
  visuallyHidden,
20
30
  components: {
@@ -23,7 +33,8 @@ function useMenuGridCell_unstable(props, ref) {
23
33
  root: _reactutilities.slot.always((0, _reactutilities.getIntrinsicElementProps)('div', {
24
34
  ref: (0, _reactutilities.useMergedRefs)(ref, validateNestingRef),
25
35
  role: 'gridcell',
26
- ...props
36
+ ...props,
37
+ onKeyDown
27
38
  }), {
28
39
  elementType: 'div'
29
40
  })
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/MenuGridCell/useMenuGridCell.ts"],"sourcesContent":["import * as React from 'react';\nimport { useMergedRefs, getIntrinsicElementProps, slot } from '@fluentui/react-utilities';\nimport { MenuGridCellProps, MenuGridCellState } from './MenuGridCell.types';\nimport { useValidateNesting } from '../../utils/useValidateNesting';\n\n/**\n * Given user props, returns state and render function for a MenuGridCell.\n */\nexport function useMenuGridCell_unstable(props: MenuGridCellProps, ref: React.Ref<HTMLDivElement>): MenuGridCellState {\n const validateNestingRef = useValidateNesting('MenuGridCell');\n const { visuallyHidden } = props;\n\n return {\n visuallyHidden,\n components: {\n root: 'div',\n },\n root: slot.always(\n getIntrinsicElementProps('div', {\n ref: useMergedRefs(ref, validateNestingRef),\n role: 'gridcell',\n ...props,\n }),\n { elementType: 'div' },\n ),\n };\n}\n"],"names":["React","useMergedRefs","getIntrinsicElementProps","slot","useValidateNesting","useMenuGridCell_unstable","props","ref","validateNestingRef","visuallyHidden","components","root","always","role","elementType"],"mappings":";;;;+BAQgBK;;;;;;;iEARO,QAAQ;gCAC+B,4BAA4B;oCAEvD,iCAAiC;AAK7D,kCAAkCC,KAAwB,EAAEC,GAA8B;IAC/F,MAAMC,yBAAqBJ,sCAAAA,EAAmB;IAC9C,MAAM,EAAEK,cAAc,EAAE,GAAGH;IAE3B,OAAO;QACLG;QACAC,YAAY;YACVC,MAAM;QACR;QACAA,MAAMR,oBAAAA,CAAKS,MAAM,KACfV,wCAAAA,EAAyB,OAAO;YAC9BK,SAAKN,6BAAAA,EAAcM,KAAKC;YACxBK,MAAM;YACN,GAAGP,KAAK;QACV,IACA;YAAEQ,aAAa;QAAM;IAEzB;AACF"}
1
+ {"version":3,"sources":["../src/components/MenuGridCell/useMenuGridCell.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';\nimport {\n useMergedRefs,\n useEventCallback,\n mergeCallbacks,\n getIntrinsicElementProps,\n slot,\n} from '@fluentui/react-utilities';\nimport { MenuGridCellProps, MenuGridCellState } from './MenuGridCell.types';\nimport { useValidateNesting } from '../../utils/useValidateNesting';\n\n/**\n * Given user props, returns state and render function for a MenuGridCell.\n */\nexport function useMenuGridCell_unstable(props: MenuGridCellProps, ref: React.Ref<HTMLDivElement>): MenuGridCellState {\n const { visuallyHidden } = props;\n const validateNestingRef = useValidateNesting('MenuGridCell');\n const { dir } = useFluent();\n\n const CloseArrowKey = dir === 'ltr' ? ArrowLeft : ArrowRight;\n const onKeyDownWithPrevent = useEventCallback((event: React.KeyboardEvent<HTMLElement>) => {\n if (event.key === CloseArrowKey) {\n event.preventDefault();\n }\n });\n const onKeyDown = useEventCallback(mergeCallbacks(props.onKeyDown, onKeyDownWithPrevent));\n\n return {\n visuallyHidden,\n components: {\n root: 'div',\n },\n root: slot.always(\n getIntrinsicElementProps('div', {\n ref: useMergedRefs(ref, validateNestingRef),\n role: 'gridcell',\n ...props,\n onKeyDown,\n }),\n { elementType: 'div' },\n ),\n };\n}\n"],"names":["React","useFluent_unstable","useFluent","ArrowLeft","ArrowRight","useMergedRefs","useEventCallback","mergeCallbacks","getIntrinsicElementProps","slot","useValidateNesting","useMenuGridCell_unstable","props","ref","visuallyHidden","validateNestingRef","dir","CloseArrowKey","onKeyDownWithPrevent","event","key","preventDefault","onKeyDown","components","root","always","role","elementType"],"mappings":";;;;+BAgBgBW;;;;;;;iEAhBO,QAAQ;qCACiB,kCAAkC;8BAC5C,0BAA0B;gCAOzD,4BAA4B;oCAEA,iCAAiC;AAK7D,kCAAkCC,KAAwB,EAAEC,GAA8B;IAC/F,MAAM,EAAEC,cAAc,EAAE,GAAGF;IAC3B,MAAMG,yBAAqBL,sCAAAA,EAAmB;IAC9C,MAAM,EAAEM,GAAG,EAAE,GAAGd,2CAAAA;IAEhB,MAAMe,gBAAgBD,QAAQ,QAAQb,uBAAAA,GAAYC,wBAAAA;IAClD,MAAMc,2BAAuBZ,gCAAAA,EAAiB,CAACa;QAC7C,IAAIA,MAAMC,GAAG,KAAKH,eAAe;YAC/BE,MAAME,cAAc;QACtB;IACF;IACA,MAAMC,gBAAYhB,gCAAAA,MAAiBC,8BAAAA,EAAeK,MAAMU,SAAS,EAAEJ;IAEnE,OAAO;QACLJ;QACAS,YAAY;YACVC,MAAM;QACR;QACAA,MAAMf,oBAAAA,CAAKgB,MAAM,KACfjB,wCAAAA,EAAyB,OAAO;YAC9BK,SAAKR,6BAAAA,EAAcQ,KAAKE;YACxBW,MAAM;YACN,GAAGd,KAAK;YACRU;QACF,IACA;YAAEK,aAAa;QAAM;IAEzB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/useValidateNesting.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nimport type { MenuContextValue } from '@fluentui/react-menu';\nimport { useMenuContext_unstable } from '@fluentui/react-menu';\n\ntype NestingComponentName = 'MenuGrid' | 'MenuGridCell' | 'MenuGridItem' | 'MenuGridRow';\ntype MenuItemRoles = 'menuitem' | 'menuitemcheckbox' | 'menuitemradio';\n\nconst menuItemRoleToNameMapping = {\n menuitem: 'MenuItem',\n menuitemcheckbox: 'MenuItemCheckbox',\n menuitemradio: 'MenuItemRadio',\n};\n\nexport const useValidateNesting = (componentName: NestingComponentName): React.RefObject<HTMLElement> => {\n 'use no memo';\n\n const { targetDocument } = useFluent();\n const triggerRef = useMenuContext_unstable((context: MenuContextValue) => context.triggerRef);\n const inline = useMenuContext_unstable((context: MenuContextValue) => context.inline);\n const ref = React.useRef<HTMLElement>(null);\n\n if (process.env.NODE_ENV !== 'production') {\n // This check should run only in development mode\n // It's okay to disable the ESLint rule because we ar checking env variable statically (not at runtime)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n let ancestor = ref.current;\n let ancestorRole;\n\n do {\n ancestor = ancestor?.parentElement ?? null;\n ancestorRole = ancestor?.getAttribute('role');\n if (ancestor?.classList.contains('fui-MenuGrid')) {\n if (componentName === 'MenuGridCell') {\n throw new Error(\n 'MenuGridCell is incorrectly nested within MenuGrid. You probably want to wrap it in a MenuGridRow.',\n );\n }\n break;\n }\n if (ancestor?.classList.contains('fui-MenuGridRow') && componentName === 'MenuGridCell') {\n break;\n }\n if (['menuitem', 'menuitemcheckbox', 'menuitemradio'].includes(ancestorRole ?? '')) {\n throw new Error(\n `${componentName} is incorrectly nested within ${\n menuItemRoleToNameMapping[ancestorRole as MenuItemRoles]\n } or within an element with the \"${ancestorRole}\" role.`,\n );\n }\n if (ancestorRole === 'menu') {\n let message = '';\n let breakAncestorTraversal = false;\n switch (componentName) {\n case 'MenuGrid':\n if (inline && getMenuOfTrigger(triggerRef.current, targetDocument) === ancestor) {\n // Handle the case when MenuGrid is inline next to its menu trigger which is a submenu item of the parent menu\n breakAncestorTraversal = true;\n break;\n }\n message = 'MenuGrid is incorrectly nested within MenuList or within an element with the \"menu\" role.';\n break;\n case 'MenuGridCell':\n message =\n 'MenuGridCell is incorrectly nested within MenuList or within an element with the \"menu\" role. You probably want to wrap it in a MenuGridRow.';\n break;\n case 'MenuGridItem':\n message =\n 'MenuGridItem is incorrectly nested within MenuList or within an element with the \"menu\" role. You probably want to wrap it in a MenuGrid instead.';\n break;\n case 'MenuGridRow':\n message =\n 'MenuGridRow is incorrectly nested within MenuList or within an element with the \"menu\" role. You probably want to wrap it in a MenuGrid instead.';\n break;\n }\n if (breakAncestorTraversal) {\n break;\n }\n throw new Error(message);\n }\n } while (ancestor && ancestor !== targetDocument?.body);\n }, [componentName, ref, triggerRef, inline, targetDocument]);\n }\n return ref;\n};\n\nconst getMenuOfTrigger = (trigger: HTMLElement | null, targetDocument?: Document): HTMLElement | null => {\n let ancestor = trigger?.parentElement;\n while (ancestor && ancestor !== targetDocument?.body) {\n if (ancestor?.getAttribute('role') === 'menu') {\n return ancestor;\n }\n ancestor = ancestor?.parentElement ?? null;\n }\n return null;\n};\n"],"names":["React","useFluent_unstable","useFluent","useMenuContext_unstable","menuItemRoleToNameMapping","menuitem","menuitemcheckbox","menuitemradio","useValidateNesting","componentName","targetDocument","triggerRef","context","inline","ref","useRef","process","env","NODE_ENV","useEffect","ancestor","current","ancestorRole","parentElement","getAttribute","classList","contains","Error","includes","message","breakAncestorTraversal","getMenuOfTrigger","body","trigger"],"mappings":";;;;+BAeaQ;;;;;;;iEAfU,QAAQ;qCACiB,kCAAkC;2BAG1C,uBAAuB;AAK/D,MAAMJ,4BAA4B;IAChCC,UAAU;IACVC,kBAAkB;IAClBC,eAAe;AACjB;AAEO,2BAA2B,CAACE;IACjC;IAEA,MAAM,EAAEC,cAAc,EAAE,OAAGR,uCAAAA;IAC3B,MAAMS,aAAaR,sCAAAA,EAAwB,CAACS,UAA8BA,QAAQD,UAAU;IAC5F,MAAME,aAASV,kCAAAA,EAAwB,CAACS,UAA8BA,QAAQC,MAAM;IACpF,MAAMC,MAAMd,OAAMe,MAAM,CAAc;IAEtC,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,iDAAiD;QACjD,uGAAuG;QACvG,sDAAsD;QACtDlB,OAAMmB,SAAS,CAAC;YACd,IAAIC,WAAWN,IAAIO,OAAO;YAC1B,IAAIC;YAEJ,GAAG;oBACUF;gBAAXA,WAAWA,CAAAA,0BAAAA,aAAAA,QAAAA,aAAAA,KAAAA,IAAAA,KAAAA,IAAAA,SAAUG,aAAAA,AAAa,MAAA,QAAvBH,4BAAAA,KAAAA,IAAAA,0BAA2B;gBACtCE,eAAeF,aAAAA,QAAAA,aAAAA,KAAAA,IAAAA,KAAAA,IAAAA,SAAUI,YAAY,CAAC;gBACtC,IAAIJ,aAAAA,QAAAA,aAAAA,KAAAA,IAAAA,KAAAA,IAAAA,SAAUK,SAAS,CAACC,QAAQ,CAAC,iBAAiB;oBAChD,IAAIjB,kBAAkB,gBAAgB;wBACpC,MAAM,IAAIkB,MACR;oBAEJ;oBACA;gBACF;gBACA,IAAIP,CAAAA,aAAAA,QAAAA,aAAAA,KAAAA,IAAAA,KAAAA,IAAAA,SAAUK,SAAS,CAACC,QAAQ,CAAC,k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OAAOJ;QACT;YACWA;QAAXA,WAAWA,CAAAA,0BAAAA,aAAAA,QAAAA,aAAAA,KAAAA,IAAAA,KAAAA,IAAAA,SAAUG,aAAAA,AAAa,MAAA,QAAvBH,4BAAAA,KAAAA,IAAAA,0BAA2B;IACxC;IACA,OAAO;AACT"}
1
+ {"version":3,"sources":["../src/utils/useValidateNesting.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nimport type { MenuContextValue } from '@fluentui/react-menu';\nimport { useMenuContext_unstable } from '@fluentui/react-menu';\n\ntype NestingComponentName = 'MenuGrid' | 'MenuGridCell' | 'MenuGridItem' | 'MenuGridRow';\ntype MenuItemRoles = 'menuitem' | 'menuitemcheckbox' | 'menuitemradio';\n\nconst menuItemRoleToNameMapping = {\n menuitem: 'MenuItem',\n menuitemcheckbox: 'MenuItemCheckbox',\n menuitemradio: 'MenuItemRadio',\n};\n\nexport const useValidateNesting = (componentName: NestingComponentName): React.RefObject<HTMLElement | null> => {\n 'use no memo';\n\n const { targetDocument } = useFluent();\n const triggerRef = useMenuContext_unstable((context: MenuContextValue) => context.triggerRef);\n const inline = useMenuContext_unstable((context: MenuContextValue) => context.inline);\n const ref = React.useRef<HTMLElement | null>(null);\n\n if (process.env.NODE_ENV !== 'production') {\n // This check should run only in development mode\n // It's okay to disable the ESLint rule because we ar checking env variable statically (not at runtime)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n let ancestor = ref.current;\n let ancestorRole;\n\n do {\n ancestor = ancestor?.parentElement ?? null;\n ancestorRole = ancestor?.getAttribute('role');\n if (ancestor?.classList.contains('fui-MenuGrid')) {\n if (componentName === 'MenuGridCell') {\n throw new Error(\n 'MenuGridCell is incorrectly nested within MenuGrid. You probably want to wrap it in a MenuGridRow.',\n );\n }\n break;\n }\n if (ancestor?.classList.contains('fui-MenuGridRow') && componentName === 'MenuGridCell') {\n break;\n }\n if (['menuitem', 'menuitemcheckbox', 'menuitemradio'].includes(ancestorRole ?? '')) {\n throw new Error(\n `${componentName} is incorrectly nested within ${\n menuItemRoleToNameMapping[ancestorRole as MenuItemRoles]\n } or within an element with the \"${ancestorRole}\" role.`,\n );\n }\n if (ancestorRole === 'menu') {\n let message = '';\n let breakAncestorTraversal = false;\n switch (componentName) {\n case 'MenuGrid':\n if (inline && getMenuOfTrigger(triggerRef.current, targetDocument) === ancestor) {\n // Handle the case when MenuGrid is inline next to its menu trigger which is a submenu item of the parent menu\n breakAncestorTraversal = true;\n break;\n }\n message = 'MenuGrid is incorrectly nested within MenuList or within an element with the \"menu\" role.';\n break;\n case 'MenuGridCell':\n message =\n 'MenuGridCell is incorrectly nested within MenuList or within an element with the \"menu\" role. You probably want to wrap it in a MenuGridRow.';\n break;\n case 'MenuGridItem':\n message =\n 'MenuGridItem is incorrectly nested within MenuList or within an element with the \"menu\" role. You probably want to wrap it in a MenuGrid instead.';\n break;\n case 'MenuGridRow':\n message =\n 'MenuGridRow is incorrectly nested within MenuList or within an element with the \"menu\" role. You probably want to wrap it in a MenuGrid instead.';\n break;\n }\n if (breakAncestorTraversal) {\n break;\n }\n throw new Error(message);\n }\n } while (ancestor && ancestor !== targetDocument?.body);\n }, [componentName, ref, triggerRef, inline, targetDocument]);\n }\n return ref;\n};\n\nconst getMenuOfTrigger = (trigger: HTMLElement | null, targetDocument?: Document): HTMLElement | null => {\n let ancestor = trigger?.parentElement;\n while (ancestor && ancestor !== targetDocument?.body) {\n if (ancestor?.getAttribute('role') === 'menu') {\n return ancestor;\n }\n ancestor = ancestor?.parentElement ?? null;\n }\n return null;\n};\n"],"names":["React","useFluent_unstable","useFluent","useMenuContext_unstable","menuItemRoleToNameMapping","menuitem","menuitemcheckbox","menuitemradio","useValidateNesting","componentName","targetDocument","triggerRef","context","inline","ref","useRef","process","env","NODE_ENV","useEffect","ancestor","current","ancestorRole","parentElement","getAttribute","classList","contains","Error","includes","message","breakAncestorTraversal","getMenuOfTrigger","body","trigger"],"m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vBH,4BAAAA,KAAAA,IAAAA,0BAA2B;IACxC;IACA,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-menu-grid-preview",
3
- "version": "0.0.0-nightly-20250924-0412.1",
3
+ "version": "0.0.0-nightly-20250926-0406.1",
4
4
  "description": "New fluentui react package",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -19,18 +19,19 @@
19
19
  "license": "MIT",
20
20
  "devDependencies": {
21
21
  "@fluentui/eslint-plugin": "*",
22
- "@fluentui/react-conformance": "0.0.0-nightly-20250924-0412.1",
23
- "@fluentui/react-conformance-griffel": "0.0.0-nightly-20250924-0412.1",
22
+ "@fluentui/react-conformance": "0.0.0-nightly-20250926-0406.1",
23
+ "@fluentui/react-conformance-griffel": "0.0.0-nightly-20250926-0406.1",
24
24
  "@fluentui/scripts-api-extractor": "*"
25
25
  },
26
26
  "dependencies": {
27
- "@fluentui/react-menu": "0.0.0-nightly-20250924-0412.1",
28
- "@fluentui/react-table": "0.0.0-nightly-20250924-0412.1",
29
- "@fluentui/react-tabster": "0.0.0-nightly-20250924-0412.1",
30
- "@fluentui/react-jsx-runtime": "0.0.0-nightly-20250924-0412.1",
31
- "@fluentui/react-shared-contexts": "0.0.0-nightly-20250924-0412.1",
32
- "@fluentui/react-theme": "0.0.0-nightly-20250924-0412.1",
33
- "@fluentui/react-utilities": "0.0.0-nightly-20250924-0412.1",
27
+ "@fluentui/keyboard-keys": "0.0.0-nightly-20250926-0406.1",
28
+ "@fluentui/react-menu": "0.0.0-nightly-20250926-0406.1",
29
+ "@fluentui/react-table": "0.0.0-nightly-20250926-0406.1",
30
+ "@fluentui/react-tabster": "0.0.0-nightly-20250926-0406.1",
31
+ "@fluentui/react-jsx-runtime": "0.0.0-nightly-20250926-0406.1",
32
+ "@fluentui/react-shared-contexts": "0.0.0-nightly-20250926-0406.1",
33
+ "@fluentui/react-theme": "0.0.0-nightly-20250926-0406.1",
34
+ "@fluentui/react-utilities": "0.0.0-nightly-20250926-0406.1",
34
35
  "@griffel/react": "^1.5.22",
35
36
  "@swc/helpers": "^0.5.1"
36
37
  },