@fluentui/react-tags 9.9.0 → 9.9.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 +11 -2
- package/dist/index.d.ts +1 -7
- package/lib/components/TagGroup/useTagGroup.js +13 -15
- package/lib/components/TagGroup/useTagGroup.js.map +1 -1
- package/lib-commonjs/components/TagGroup/useTagGroup.js +13 -15
- package/lib-commonjs/components/TagGroup/useTagGroup.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-tags
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 27 May 2026 11:18:29 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [9.9.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-tags_v9.9.1)
|
|
8
|
+
|
|
9
|
+
Wed, 27 May 2026 11:18:29 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tags_v9.9.0..@fluentui/react-tags_v9.9.1)
|
|
11
|
+
|
|
12
|
+
### Patches
|
|
13
|
+
|
|
14
|
+
- fix: decouple useTagGroupBase_unstable from Tabster; export contexts. This is technically a breaking change, but the prior Tabster coupling was a programmatic mistake and not intended public behavior. If you run into issues, please bump to the next version. ([PR #36228](https://github.com/microsoft/fluentui/pull/36228) by vgenaev@gmail.com)
|
|
15
|
+
|
|
7
16
|
## [9.9.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-tags_v9.9.0)
|
|
8
17
|
|
|
9
|
-
Tue, 26 May 2026 09:
|
|
18
|
+
Tue, 26 May 2026 09:39:09 GMT
|
|
10
19
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tags_v9.8.1..@fluentui/react-tags_v9.9.0)
|
|
11
20
|
|
|
12
21
|
### Minor changes
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ import type { JSXElement } from '@fluentui/react-utilities';
|
|
|
10
10
|
import * as React_2 from 'react';
|
|
11
11
|
import type { Slot } from '@fluentui/react-utilities';
|
|
12
12
|
import type { SlotClassNames } from '@fluentui/react-utilities';
|
|
13
|
-
import type { TabsterDOMAttribute } from '@fluentui/react-tabster';
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* InteractionTag component - a visual representation of an attribute with primary and secondary actions.
|
|
@@ -540,12 +539,7 @@ export declare const useTagGroup_unstable: (props: TagGroupProps, ref: React_2.R
|
|
|
540
539
|
* @param props - props from this instance of TagGroup (without appearance, size)
|
|
541
540
|
* @param ref - reference to root HTMLDivElement of TagGroup
|
|
542
541
|
*/
|
|
543
|
-
export declare const useTagGroupBase_unstable: (props: TagGroupBaseProps, ref: React_2.Ref<HTMLDivElement
|
|
544
|
-
|
|
545
|
-
declare type UseTagGroupBaseOptions = {
|
|
546
|
-
arrowNavigationProps?: TabsterDOMAttribute;
|
|
547
|
-
onAfterTagDismiss?: (container: HTMLElement | null) => void;
|
|
548
|
-
};
|
|
542
|
+
export declare const useTagGroupBase_unstable: (props: TagGroupBaseProps, ref: React_2.Ref<HTMLDivElement>) => TagGroupBaseState;
|
|
549
543
|
|
|
550
544
|
export declare const useTagGroupContext_unstable: () => TagGroupContextValue;
|
|
551
545
|
|
|
@@ -9,19 +9,15 @@ import { interactionTagSecondaryClassNames } from '../InteractionTagSecondary/us
|
|
|
9
9
|
*
|
|
10
10
|
* @param props - props from this instance of TagGroup (without appearance, size)
|
|
11
11
|
* @param ref - reference to root HTMLDivElement of TagGroup
|
|
12
|
-
*/ export const useTagGroupBase_unstable = (props, ref
|
|
12
|
+
*/ export const useTagGroupBase_unstable = (props, ref)=>{
|
|
13
13
|
const { onDismiss, disabled = false, defaultSelectedValues, dismissible = false, role = 'toolbar', onTagSelect, selectedValues, ...rest } = props;
|
|
14
|
-
const innerRef = React.useRef(undefined);
|
|
15
14
|
const [items, setItems] = useControllableState({
|
|
16
15
|
defaultState: defaultSelectedValues,
|
|
17
16
|
state: selectedValues,
|
|
18
17
|
initialState: []
|
|
19
18
|
});
|
|
20
19
|
const handleTagDismiss = useEventCallback((e, data)=>{
|
|
21
|
-
var _options_onAfterTagDismiss;
|
|
22
20
|
onDismiss === null || onDismiss === void 0 ? void 0 : onDismiss(e, data);
|
|
23
|
-
var _innerRef_current;
|
|
24
|
-
options === null || options === void 0 ? void 0 : (_options_onAfterTagDismiss = options.onAfterTagDismiss) === null || _options_onAfterTagDismiss === void 0 ? void 0 : _options_onAfterTagDismiss.call(options, (_innerRef_current = innerRef.current) !== null && _innerRef_current !== void 0 ? _innerRef_current : null);
|
|
25
21
|
});
|
|
26
22
|
const handleTagSelect = useEventCallback(mergeCallbacks(onTagSelect, (_, data)=>{
|
|
27
23
|
if (items.includes(data.value)) {
|
|
@@ -44,13 +40,9 @@ import { interactionTagSecondaryClassNames } from '../InteractionTagSecondary/us
|
|
|
44
40
|
root: 'div'
|
|
45
41
|
},
|
|
46
42
|
root: slot.always(getIntrinsicElementProps('div', {
|
|
47
|
-
|
|
48
|
-
// `ref` is wrongly assigned to be `HTMLElement` instead of `HTMLDivElement`
|
|
49
|
-
// but since it would be a breaking change to fix it, we are casting ref to it's proper type
|
|
50
|
-
ref: useMergedRefs(ref, innerRef),
|
|
43
|
+
ref,
|
|
51
44
|
role,
|
|
52
45
|
'aria-disabled': disabled,
|
|
53
|
-
...options === null || options === void 0 ? void 0 : options.arrowNavigationProps,
|
|
54
46
|
...rest
|
|
55
47
|
}), {
|
|
56
48
|
elementType: 'div'
|
|
@@ -74,7 +66,12 @@ import { interactionTagSecondaryClassNames } from '../InteractionTagSecondary/us
|
|
|
74
66
|
axis: 'both',
|
|
75
67
|
memorizeCurrent: true
|
|
76
68
|
});
|
|
77
|
-
const
|
|
69
|
+
const innerRef = React.useRef(null);
|
|
70
|
+
const mergedRef = useMergedRefs(ref, innerRef);
|
|
71
|
+
const enhancedOnDismiss = useEventCallback((e, data)=>{
|
|
72
|
+
var _props_onDismiss;
|
|
73
|
+
(_props_onDismiss = props.onDismiss) === null || _props_onDismiss === void 0 ? void 0 : _props_onDismiss.call(props, e, data);
|
|
74
|
+
const container = innerRef.current;
|
|
78
75
|
const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;
|
|
79
76
|
if (container === null || container === void 0 ? void 0 : container.contains(activeElement)) {
|
|
80
77
|
// focus on next tag only if the active element is within the current tag group
|
|
@@ -100,10 +97,11 @@ import { interactionTagSecondaryClassNames } from '../InteractionTagSecondary/us
|
|
|
100
97
|
}
|
|
101
98
|
});
|
|
102
99
|
return {
|
|
103
|
-
...useTagGroupBase_unstable(
|
|
104
|
-
arrowNavigationProps,
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
...useTagGroupBase_unstable({
|
|
101
|
+
...arrowNavigationProps,
|
|
102
|
+
...props,
|
|
103
|
+
onDismiss: enhancedOnDismiss
|
|
104
|
+
}, mergedRef),
|
|
107
105
|
size,
|
|
108
106
|
appearance
|
|
109
107
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/TagGroup/useTagGroup.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport {\n getIntrinsicElementProps,\n useControllableState,\n useEventCallback,\n mergeCallbacks,\n useMergedRefs,\n slot,\n} from '@fluentui/react-utilities';\nimport type { TagGroupBaseProps, TagGroupBaseState, TagGroupProps, TagGroupState } from './TagGroup.types';\nimport { useArrowNavigationGroup, useFocusFinders } from '@fluentui/react-tabster';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { interactionTagSecondaryClassNames } from '../InteractionTagSecondary/useInteractionTagSecondaryStyles.styles';\nimport type { TagValue } from '../../utils/types';\
|
|
1
|
+
{"version":3,"sources":["../src/components/TagGroup/useTagGroup.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport {\n getIntrinsicElementProps,\n useControllableState,\n useEventCallback,\n mergeCallbacks,\n useMergedRefs,\n slot,\n} from '@fluentui/react-utilities';\nimport type { TagGroupBaseProps, TagGroupBaseState, TagGroupProps, TagGroupState } from './TagGroup.types';\nimport { useArrowNavigationGroup, useFocusFinders } from '@fluentui/react-tabster';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { interactionTagSecondaryClassNames } from '../InteractionTagSecondary/useInteractionTagSecondaryStyles.styles';\nimport type { TagValue } from '../../utils/types';\n\n/**\n * Create the base state required to render TagGroup, without design-only props.\n *\n * @param props - props from this instance of TagGroup (without appearance, size)\n * @param ref - reference to root HTMLDivElement of TagGroup\n */\nexport const useTagGroupBase_unstable = (\n props: TagGroupBaseProps,\n ref: React.Ref<HTMLDivElement>,\n): TagGroupBaseState => {\n const {\n onDismiss,\n disabled = false,\n defaultSelectedValues,\n dismissible = false,\n role = 'toolbar',\n onTagSelect,\n selectedValues,\n ...rest\n } = props;\n\n const [items, setItems] = useControllableState<Array<TagValue>>({\n defaultState: defaultSelectedValues,\n state: selectedValues,\n initialState: [],\n });\n\n const handleTagDismiss: TagGroupBaseState['handleTagDismiss'] = useEventCallback((e, data) => {\n onDismiss?.(e, data);\n });\n\n const handleTagSelect: TagGroupBaseState['handleTagSelect'] = useEventCallback(\n mergeCallbacks(onTagSelect, (_, data) => {\n if (items.includes(data.value)) {\n setItems(items.filter(item => item !== data.value));\n } else {\n setItems([...items, data.value]);\n }\n }),\n );\n\n return {\n handleTagDismiss,\n handleTagSelect: onTagSelect ? handleTagSelect : undefined,\n selectedValues: items,\n role,\n disabled,\n dismissible,\n components: {\n root: 'div',\n },\n\n root: slot.always(\n getIntrinsicElementProps('div', {\n ref,\n role,\n 'aria-disabled': disabled,\n ...rest,\n }),\n { elementType: 'div' },\n ),\n };\n};\n\n/**\n * Create the state required to render TagGroup.\n *\n * The returned state can be modified with hooks such as useTagGroupStyles_unstable,\n * before being passed to renderTagGroup_unstable.\n *\n * @param props - props from this instance of TagGroup\n * @param ref - reference to root HTMLDivElement of TagGroup\n */\nexport const useTagGroup_unstable = (props: TagGroupProps, ref: React.Ref<HTMLDivElement>): TagGroupState => {\n const { size = 'medium', appearance = 'filled' } = props;\n\n const { targetDocument } = useFluent();\n const { findNextFocusable, findPrevFocusable } = useFocusFinders();\n\n const arrowNavigationProps = useArrowNavigationGroup({\n circular: true,\n axis: 'both',\n memorizeCurrent: true,\n });\n\n const innerRef = React.useRef<HTMLDivElement>(null);\n const mergedRef = useMergedRefs(ref, innerRef);\n\n const enhancedOnDismiss: TagGroupProps['onDismiss'] = useEventCallback((e, data) => {\n props.onDismiss?.(e, data);\n\n const container = innerRef.current;\n const activeElement = targetDocument?.activeElement;\n\n if (container?.contains(activeElement as HTMLElement)) {\n // focus on next tag only if the active element is within the current tag group\n const next = findNextFocusable(activeElement as HTMLElement, { container });\n if (next) {\n next.focus();\n return;\n }\n\n // if there is no next focusable, focus on the previous focusable\n if (activeElement?.className.includes(interactionTagSecondaryClassNames.root)) {\n const prev = findPrevFocusable(activeElement.parentElement as HTMLElement, { container });\n prev?.focus();\n } else {\n const prev = findPrevFocusable(activeElement as HTMLElement, { container });\n prev?.focus();\n }\n }\n });\n\n return {\n ...useTagGroupBase_unstable({ ...arrowNavigationProps, ...props, onDismiss: enhancedOnDismiss }, mergedRef),\n size,\n appearance,\n };\n};\n"],"names":["React","getIntrinsicElementProps","useControllableState","useEventCallback","mergeCallbacks","useMergedRefs","slot","useArrowNavigationGroup","useFocusFinders","useFluent_unstable","useFluent","interactionTagSecondaryClassNames","useTagGroupBase_unstable","props","ref","onDismiss","disabled","defaultSelectedValues","dismissible","role","onTagSelect","selectedValues","rest","items","setItems","defaultState","state","initialState","handleTagDismiss","e","data","handleTagSelect","_","includes","value","filter","item","undefined","components","root","always","elementType","useTagGroup_unstable","size","appearance","targetDocument","findNextFocusable","findPrevFocusable","arrowNavigationProps","circular","axis","memorizeCurrent","innerRef","useRef","mergedRef","enhancedOnDismiss","container","current","activeElement","contains","next","focus","className","prev","parentElement"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SACEC,wBAAwB,EACxBC,oBAAoB,EACpBC,gBAAgB,EAChBC,cAAc,EACdC,aAAa,EACbC,IAAI,QACC,4BAA4B;AAEnC,SAASC,uBAAuB,EAAEC,eAAe,QAAQ,0BAA0B;AACnF,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,iCAAiC,QAAQ,qEAAqE;AAGvH;;;;;CAKC,GACD,OAAO,MAAMC,2BAA2B,CACtCC,OACAC;IAEA,MAAM,EACJC,SAAS,EACTC,WAAW,KAAK,EAChBC,qBAAqB,EACrBC,cAAc,KAAK,EACnBC,OAAO,SAAS,EAChBC,WAAW,EACXC,cAAc,EACd,GAAGC,MACJ,GAAGT;IAEJ,MAAM,CAACU,OAAOC,SAAS,GAAGtB,qBAAsC;QAC9DuB,cAAcR;QACdS,OAAOL;QACPM,cAAc,EAAE;IAClB;IAEA,MAAMC,mBAA0DzB,iBAAiB,CAAC0B,GAAGC;QACnFf,sBAAAA,gCAAAA,UAAYc,GAAGC;IACjB;IAEA,MAAMC,kBAAwD5B,iBAC5DC,eAAegB,aAAa,CAACY,GAAGF;QAC9B,IAAIP,MAAMU,QAAQ,CAACH,KAAKI,KAAK,GAAG;YAC9BV,SAASD,MAAMY,MAAM,CAACC,CAAAA,OAAQA,SAASN,KAAKI,KAAK;QACnD,OAAO;YACLV,SAAS;mBAAID;gBAAOO,KAAKI,KAAK;aAAC;QACjC;IACF;IAGF,OAAO;QACLN;QACAG,iBAAiBX,cAAcW,kBAAkBM;QACjDhB,gBAAgBE;QAChBJ;QACAH;QACAE;QACAoB,YAAY;YACVC,MAAM;QACR;QAEAA,MAAMjC,KAAKkC,MAAM,CACfvC,yBAAyB,OAAO;YAC9Ba;YACAK;YACA,iBAAiBH;YACjB,GAAGM,IAAI;QACT,IACA;YAAEmB,aAAa;QAAM;IAEzB;AACF,EAAE;AAE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X;QACAC;IACF;AACF,EAAE"}
|
|
@@ -23,19 +23,15 @@ const _reactutilities = require("@fluentui/react-utilities");
|
|
|
23
23
|
const _reacttabster = require("@fluentui/react-tabster");
|
|
24
24
|
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
|
|
25
25
|
const _useInteractionTagSecondaryStylesstyles = require("../InteractionTagSecondary/useInteractionTagSecondaryStyles.styles");
|
|
26
|
-
const useTagGroupBase_unstable = (props, ref
|
|
26
|
+
const useTagGroupBase_unstable = (props, ref)=>{
|
|
27
27
|
const { onDismiss, disabled = false, defaultSelectedValues, dismissible = false, role = 'toolbar', onTagSelect, selectedValues, ...rest } = props;
|
|
28
|
-
const innerRef = _react.useRef(undefined);
|
|
29
28
|
const [items, setItems] = (0, _reactutilities.useControllableState)({
|
|
30
29
|
defaultState: defaultSelectedValues,
|
|
31
30
|
state: selectedValues,
|
|
32
31
|
initialState: []
|
|
33
32
|
});
|
|
34
33
|
const handleTagDismiss = (0, _reactutilities.useEventCallback)((e, data)=>{
|
|
35
|
-
var _options_onAfterTagDismiss;
|
|
36
34
|
onDismiss === null || onDismiss === void 0 ? void 0 : onDismiss(e, data);
|
|
37
|
-
var _innerRef_current;
|
|
38
|
-
options === null || options === void 0 ? void 0 : (_options_onAfterTagDismiss = options.onAfterTagDismiss) === null || _options_onAfterTagDismiss === void 0 ? void 0 : _options_onAfterTagDismiss.call(options, (_innerRef_current = innerRef.current) !== null && _innerRef_current !== void 0 ? _innerRef_current : null);
|
|
39
35
|
});
|
|
40
36
|
const handleTagSelect = (0, _reactutilities.useEventCallback)((0, _reactutilities.mergeCallbacks)(onTagSelect, (_, data)=>{
|
|
41
37
|
if (items.includes(data.value)) {
|
|
@@ -58,13 +54,9 @@ const useTagGroupBase_unstable = (props, ref, options)=>{
|
|
|
58
54
|
root: 'div'
|
|
59
55
|
},
|
|
60
56
|
root: _reactutilities.slot.always((0, _reactutilities.getIntrinsicElementProps)('div', {
|
|
61
|
-
|
|
62
|
-
// `ref` is wrongly assigned to be `HTMLElement` instead of `HTMLDivElement`
|
|
63
|
-
// but since it would be a breaking change to fix it, we are casting ref to it's proper type
|
|
64
|
-
ref: (0, _reactutilities.useMergedRefs)(ref, innerRef),
|
|
57
|
+
ref,
|
|
65
58
|
role,
|
|
66
59
|
'aria-disabled': disabled,
|
|
67
|
-
...options === null || options === void 0 ? void 0 : options.arrowNavigationProps,
|
|
68
60
|
...rest
|
|
69
61
|
}), {
|
|
70
62
|
elementType: 'div'
|
|
@@ -80,7 +72,12 @@ const useTagGroup_unstable = (props, ref)=>{
|
|
|
80
72
|
axis: 'both',
|
|
81
73
|
memorizeCurrent: true
|
|
82
74
|
});
|
|
83
|
-
const
|
|
75
|
+
const innerRef = _react.useRef(null);
|
|
76
|
+
const mergedRef = (0, _reactutilities.useMergedRefs)(ref, innerRef);
|
|
77
|
+
const enhancedOnDismiss = (0, _reactutilities.useEventCallback)((e, data)=>{
|
|
78
|
+
var _props_onDismiss;
|
|
79
|
+
(_props_onDismiss = props.onDismiss) === null || _props_onDismiss === void 0 ? void 0 : _props_onDismiss.call(props, e, data);
|
|
80
|
+
const container = innerRef.current;
|
|
84
81
|
const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;
|
|
85
82
|
if (container === null || container === void 0 ? void 0 : container.contains(activeElement)) {
|
|
86
83
|
// focus on next tag only if the active element is within the current tag group
|
|
@@ -106,10 +103,11 @@ const useTagGroup_unstable = (props, ref)=>{
|
|
|
106
103
|
}
|
|
107
104
|
});
|
|
108
105
|
return {
|
|
109
|
-
...useTagGroupBase_unstable(
|
|
110
|
-
arrowNavigationProps,
|
|
111
|
-
|
|
112
|
-
|
|
106
|
+
...useTagGroupBase_unstable({
|
|
107
|
+
...arrowNavigationProps,
|
|
108
|
+
...props,
|
|
109
|
+
onDismiss: enhancedOnDismiss
|
|
110
|
+
}, mergedRef),
|
|
113
111
|
size,
|
|
114
112
|
appearance
|
|
115
113
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/TagGroup/useTagGroup.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport {\n getIntrinsicElementProps,\n useControllableState,\n useEventCallback,\n mergeCallbacks,\n useMergedRefs,\n slot,\n} from '@fluentui/react-utilities';\nimport type { TagGroupBaseProps, TagGroupBaseState, TagGroupProps, TagGroupState } from './TagGroup.types';\nimport { useArrowNavigationGroup, useFocusFinders } from '@fluentui/react-tabster';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { interactionTagSecondaryClassNames } from '../InteractionTagSecondary/useInteractionTagSecondaryStyles.styles';\nimport type { TagValue } from '../../utils/types';\
|
|
1
|
+
{"version":3,"sources":["../src/components/TagGroup/useTagGroup.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport {\n getIntrinsicElementProps,\n useControllableState,\n useEventCallback,\n mergeCallbacks,\n useMergedRefs,\n slot,\n} from '@fluentui/react-utilities';\nimport type { TagGroupBaseProps, TagGroupBaseState, TagGroupProps, TagGroupState } from './TagGroup.types';\nimport { useArrowNavigationGroup, useFocusFinders } from '@fluentui/react-tabster';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { interactionTagSecondaryClassNames } from '../InteractionTagSecondary/useInteractionTagSecondaryStyles.styles';\nimport type { TagValue } from '../../utils/types';\n\n/**\n * Create the base state required to render TagGroup, without design-only props.\n *\n * @param props - props from this instance of TagGroup (without appearance, size)\n * @param ref - reference to root HTMLDivElement of TagGroup\n */\nexport const useTagGroupBase_unstable = (\n props: TagGroupBaseProps,\n ref: React.Ref<HTMLDivElement>,\n): TagGroupBaseState => {\n const {\n onDismiss,\n disabled = false,\n defaultSelectedValues,\n dismissible = false,\n role = 'toolbar',\n onTagSelect,\n selectedValues,\n ...rest\n } = props;\n\n const [items, setItems] = useControllableState<Array<TagValue>>({\n defaultState: defaultSelectedValues,\n state: selectedValues,\n initialState: [],\n });\n\n const handleTagDismiss: TagGroupBaseState['handleTagDismiss'] = useEventCallback((e, data) => {\n onDismiss?.(e, data);\n });\n\n const handleTagSelect: TagGroupBaseState['handleTagSelect'] = useEventCallback(\n mergeCallbacks(onTagSelect, (_, data) => {\n if (items.includes(data.value)) {\n setItems(items.filter(item => item !== data.value));\n } else {\n setItems([...items, data.value]);\n }\n }),\n );\n\n return {\n handleTagDismiss,\n handleTagSelect: onTagSelect ? handleTagSelect : undefined,\n selectedValues: items,\n role,\n disabled,\n dismissible,\n components: {\n root: 'div',\n },\n\n root: slot.always(\n getIntrinsicElementProps('div', {\n ref,\n role,\n 'aria-disabled': disabled,\n ...rest,\n }),\n { elementType: 'div' },\n ),\n };\n};\n\n/**\n * Create the state required to render TagGroup.\n *\n * The returned state can be modified with hooks such as useTagGroupStyles_unstable,\n * before being passed to renderTagGroup_unstable.\n *\n * @param props - props from this instance of TagGroup\n * @param ref - reference to root HTMLDivElement of TagGroup\n */\nexport const useTagGroup_unstable = (props: TagGroupProps, ref: React.Ref<HTMLDivElement>): TagGroupState => {\n const { size = 'medium', appearance = 'filled' } = props;\n\n const { targetDocument } = useFluent();\n const { findNextFocusable, findPrevFocusable } = useFocusFinders();\n\n const arrowNavigationProps = useArrowNavigationGroup({\n circular: true,\n axis: 'both',\n memorizeCurrent: true,\n });\n\n const innerRef = React.useRef<HTMLDivElement>(null);\n const mergedRef = useMergedRefs(ref, innerRef);\n\n const enhancedOnDismiss: TagGroupProps['onDismiss'] = useEventCallback((e, data) => {\n props.onDismiss?.(e, data);\n\n const container = innerRef.current;\n const activeElement = targetDocument?.activeElement;\n\n if (container?.contains(activeElement as HTMLElement)) {\n // focus on next tag only if the active element is within the current tag group\n const next = findNextFocusable(activeElement as HTMLElement, { container });\n if (next) {\n next.focus();\n return;\n }\n\n // if there is no next focusable, focus on the previous focusable\n if (activeElement?.className.includes(interactionTagSecondaryClassNames.root)) {\n const prev = findPrevFocusable(activeElement.parentElement as HTMLElement, { container });\n prev?.focus();\n } else {\n const prev = findPrevFocusable(activeElement as HTMLElement, { container });\n prev?.focus();\n }\n }\n });\n\n return {\n ...useTagGroupBase_unstable({ ...arrowNavigationProps, ...props, onDismiss: enhancedOnDismiss }, mergedRef),\n size,\n appearance,\n };\n};\n"],"names":["React","getIntrinsicElementProps","useControllableState","useEventCallback","mergeCallbacks","useMergedRefs","slot","useArrowNavigationGroup","useFocusFinders","useFluent_unstable","useFluent","interactionTagSecondaryClassNames","useTagGroupBase_unstable","props","ref","onDismiss","disabled","defaultSelectedValues","dismissible","role","onTagSelect","selectedValues","rest","items","setItems","defaultState","state","initialState","handleTagDismiss","e","data","handleTagSelect","_","includes","value","filter","item","undefined","components","root","always","elementType","useTagGroup_unstable","size","appearance","targetDocument","findNextFocusable","findPrevFocusable","arrowNavigationProps","circular","axis","memorizeCurrent","innerRef","useRef","mergedRef","enhancedOnDismiss","container","current","activeElement","contains","next","focus","className","prev","parentElement"],"mappings":"AAAA;;;;;;;;;;;;IAuBaY,wBAAAA;;;wBAmEA8B;eAAAA;;;;iEAxFU,QAAQ;gCAQxB,4BAA4B;8BAEsB,0BAA0B;qCACnC,kCAAkC;wDAChC,qEAAqE;AAShH,iCAAiC,CACtC7B,OACAC;IAEA,MAAM,EACJC,SAAS,EACTC,WAAW,KAAK,EAChBC,qBAAqB,EACrBC,cAAc,KAAK,EACnBC,OAAO,SAAS,EAChBC,WAAW,EACXC,cAAc,EACd,GAAGC,MACJ,GAAGT;IAEJ,MAAM,CAACU,OAAOC,SAAS,OAAGtB,oCAAAA,EAAsC;QAC9DuB,cAAcR;QACdS,OAAOL;QACPM,cAAc,EAAE;IAClB;IAEA,MAAMC,uBAA0DzB,gCAAAA,EAAiB,CAAC0B,GAAGC;QACnFf,cAAAA,QAAAA,cAAAA,KAAAA,IAAAA,KAAAA,IAAAA,UAAYc,GAAGC;IACjB;IAEA,MAAMC,sBAAwD5B,gCAAAA,MAC5DC,8BAAAA,EAAegB,aAAa,CAACY,GAAGF;QAC9B,IAAIP,MAAMU,QAAQ,CAACH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