@fluentui/react-aria 9.4.0 → 9.5.0
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 +13 -2
- package/lib/activedescendant/useActiveDescendant.js +25 -1
- package/lib/activedescendant/useActiveDescendant.js.map +1 -1
- package/lib-commonjs/activedescendant/useActiveDescendant.js +25 -1
- package/lib-commonjs/activedescendant/useActiveDescendant.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-aria
|
|
2
2
|
|
|
3
|
-
This log was last generated on Thu,
|
|
3
|
+
This log was last generated on Thu, 14 Dec 2023 09:51:32 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [9.5.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.5.0)
|
|
8
|
+
|
|
9
|
+
Thu, 14 Dec 2023 09:51:32 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-aria_v9.4.0..@fluentui/react-aria_v9.5.0)
|
|
11
|
+
|
|
12
|
+
### Minor changes
|
|
13
|
+
|
|
14
|
+
- feat(useActiveDescendant): Changing active descendant scrolls into view ([PR #29992](https://github.com/microsoft/fluentui/pull/29992) by lingfangao@hotmail.com)
|
|
15
|
+
- Bump @fluentui/react-shared-contexts to v9.13.1 ([commit](https://github.com/microsoft/fluentui/commit/80a1b02be2fbbdde916ac87fbf760e442a2295c4) by beachball)
|
|
16
|
+
- Bump @fluentui/react-utilities to v9.15.3 ([commit](https://github.com/microsoft/fluentui/commit/80a1b02be2fbbdde916ac87fbf760e442a2295c4) by beachball)
|
|
17
|
+
|
|
7
18
|
## [9.4.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.4.0)
|
|
8
19
|
|
|
9
|
-
Thu, 30 Nov 2023 13:
|
|
20
|
+
Thu, 30 Nov 2023 13:42:05 GMT
|
|
10
21
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-aria_v9.3.44..@fluentui/react-aria_v9.4.0)
|
|
11
22
|
|
|
12
23
|
### Minor changes
|
|
@@ -11,6 +11,25 @@ export function useActiveDescendant(options) {
|
|
|
11
11
|
var _listboxRef_current;
|
|
12
12
|
return (_listboxRef_current = listboxRef.current) === null || _listboxRef_current === void 0 ? void 0 : _listboxRef_current.querySelector(`[${ACTIVEDESCENDANT_ATTRIBUTE}]`);
|
|
13
13
|
};
|
|
14
|
+
const scrollActiveIntoView = (active)=>{
|
|
15
|
+
if (!listboxRef.current) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (listboxRef.current.offsetHeight >= listboxRef.current.scrollHeight) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const { offsetHeight, offsetTop } = active;
|
|
22
|
+
const { offsetHeight: parentOffsetHeight, scrollTop } = listboxRef.current;
|
|
23
|
+
const isAbove = offsetTop < scrollTop;
|
|
24
|
+
const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;
|
|
25
|
+
const buffer = 2;
|
|
26
|
+
if (isAbove) {
|
|
27
|
+
listboxRef.current.scrollTo(0, offsetTop - buffer);
|
|
28
|
+
}
|
|
29
|
+
if (isBelow) {
|
|
30
|
+
listboxRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
14
33
|
const setActiveDescendant = (nextActive)=>{
|
|
15
34
|
const active = getActiveDescendant();
|
|
16
35
|
if (active) {
|
|
@@ -19,6 +38,7 @@ export function useActiveDescendant(options) {
|
|
|
19
38
|
if (nextActive) {
|
|
20
39
|
var _activeParentRef_current;
|
|
21
40
|
nextActive.setAttribute(ACTIVEDESCENDANT_ATTRIBUTE, '');
|
|
41
|
+
scrollActiveIntoView(nextActive);
|
|
22
42
|
(_activeParentRef_current = activeParentRef.current) === null || _activeParentRef_current === void 0 ? void 0 : _activeParentRef_current.setAttribute('aria-activedescendant', nextActive.id);
|
|
23
43
|
} else {
|
|
24
44
|
var _activeParentRef_current1;
|
|
@@ -30,6 +50,7 @@ export function useActiveDescendant(options) {
|
|
|
30
50
|
if (!listboxRef.current || !activeParentRef.current) {
|
|
31
51
|
return;
|
|
32
52
|
}
|
|
53
|
+
optionWalker.setCurrent(listboxRef.current);
|
|
33
54
|
const first = optionWalker.first();
|
|
34
55
|
if (first) {
|
|
35
56
|
setActiveDescendant(first);
|
|
@@ -58,13 +79,16 @@ export function useActiveDescendant(options) {
|
|
|
58
79
|
return;
|
|
59
80
|
}
|
|
60
81
|
optionWalker.setCurrent(active);
|
|
82
|
+
if (!matchOption(active)) {
|
|
83
|
+
optionWalker.prev();
|
|
84
|
+
}
|
|
61
85
|
const next = optionWalker.prev();
|
|
62
86
|
if (next && next !== listboxRef.current) {
|
|
63
87
|
setActiveDescendant(next);
|
|
64
88
|
}
|
|
65
89
|
},
|
|
66
90
|
blur: ()=>{
|
|
67
|
-
if (!
|
|
91
|
+
if (!activeParentRef.current) {
|
|
68
92
|
return;
|
|
69
93
|
}
|
|
70
94
|
setActiveDescendant(undefined);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useActiveDescendant.ts"],"sourcesContent":["import * as React from 'react';\nimport { useOptionWalker } from './useOptionWalker';\nimport type { ActiveDescendantOptions } from './types';\nimport { ACTIVEDESCENDANT_ATTRIBUTE } from './constants';\n\nexport function useActiveDescendant<TActiveParentElement extends HTMLElement, TListboxElement extends HTMLElement>(\n options: ActiveDescendantOptions,\n) {\n const { imperativeRef, matchOption } = options;\n const activeParentRef = React.useRef<TActiveParentElement>(null);\n const { listboxRef, optionWalker } = useOptionWalker<TListboxElement>({ matchOption });\n const getActiveDescendant = () => {\n return listboxRef.current?.querySelector<HTMLElement>(`[${ACTIVEDESCENDANT_ATTRIBUTE}]`);\n };\n\n const setActiveDescendant = (nextActive: HTMLElement | undefined) => {\n const active = getActiveDescendant();\n if (active) {\n active.removeAttribute(ACTIVEDESCENDANT_ATTRIBUTE);\n }\n\n if (nextActive) {\n nextActive.setAttribute(ACTIVEDESCENDANT_ATTRIBUTE, '');\n activeParentRef.current?.setAttribute('aria-activedescendant', nextActive.id);\n } else {\n activeParentRef.current?.removeAttribute('aria-activedescendant');\n }\n };\n\n React.useImperativeHandle(imperativeRef, () => ({\n first: () => {\n if (!listboxRef.current || !activeParentRef.current) {\n return;\n }\n\n const first = optionWalker.first();\n if (first) {\n setActiveDescendant(first);\n }\n },\n next: () => {\n if (!listboxRef.current || !activeParentRef.current) {\n return;\n }\n\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n\n optionWalker.setCurrent(active);\n const next = optionWalker.next();\n if (next) {\n setActiveDescendant(next);\n }\n },\n prev: () => {\n if (!listboxRef.current || !activeParentRef.current) {\n return;\n }\n\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n\n optionWalker.setCurrent(active);\n const next = optionWalker.prev();\n\n if (next && next !== listboxRef.current) {\n setActiveDescendant(next);\n }\n },\n blur: () => {\n if (!
|
|
1
|
+
{"version":3,"sources":["useActiveDescendant.ts"],"sourcesContent":["import * as React from 'react';\nimport { useOptionWalker } from './useOptionWalker';\nimport type { ActiveDescendantOptions } from './types';\nimport { ACTIVEDESCENDANT_ATTRIBUTE } from './constants';\n\nexport function useActiveDescendant<TActiveParentElement extends HTMLElement, TListboxElement extends HTMLElement>(\n options: ActiveDescendantOptions,\n) {\n const { imperativeRef, matchOption } = options;\n const activeParentRef = React.useRef<TActiveParentElement>(null);\n const { listboxRef, optionWalker } = useOptionWalker<TListboxElement>({ matchOption });\n const getActiveDescendant = () => {\n return listboxRef.current?.querySelector<HTMLElement>(`[${ACTIVEDESCENDANT_ATTRIBUTE}]`);\n };\n\n const scrollActiveIntoView = (active: HTMLElement) => {\n if (!listboxRef.current) {\n return;\n }\n\n if (listboxRef.current.offsetHeight >= listboxRef.current.scrollHeight) {\n return;\n }\n\n const { offsetHeight, offsetTop } = active;\n const { offsetHeight: parentOffsetHeight, scrollTop } = listboxRef.current;\n\n const isAbove = offsetTop < scrollTop;\n const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;\n\n const buffer = 2;\n\n if (isAbove) {\n listboxRef.current.scrollTo(0, offsetTop - buffer);\n }\n\n if (isBelow) {\n listboxRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);\n }\n };\n\n const setActiveDescendant = (nextActive: HTMLElement | undefined) => {\n const active = getActiveDescendant();\n if (active) {\n active.removeAttribute(ACTIVEDESCENDANT_ATTRIBUTE);\n }\n\n if (nextActive) {\n nextActive.setAttribute(ACTIVEDESCENDANT_ATTRIBUTE, '');\n scrollActiveIntoView(nextActive);\n activeParentRef.current?.setAttribute('aria-activedescendant', nextActive.id);\n } else {\n activeParentRef.current?.removeAttribute('aria-activedescendant');\n }\n };\n\n React.useImperativeHandle(imperativeRef, () => ({\n first: () => {\n if (!listboxRef.current || !activeParentRef.current) {\n return;\n }\n\n optionWalker.setCurrent(listboxRef.current);\n const first = optionWalker.first();\n if (first) {\n setActiveDescendant(first);\n }\n },\n next: () => {\n if (!listboxRef.current || !activeParentRef.current) {\n return;\n }\n\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n\n optionWalker.setCurrent(active);\n const next = optionWalker.next();\n if (next) {\n setActiveDescendant(next);\n }\n },\n prev: () => {\n if (!listboxRef.current || !activeParentRef.current) {\n return;\n }\n\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n\n optionWalker.setCurrent(active);\n if (!matchOption(active)) {\n optionWalker.prev();\n }\n\n const next = optionWalker.prev();\n\n if (next && next !== listboxRef.current) {\n setActiveDescendant(next);\n }\n },\n blur: () => {\n if (!activeParentRef.current) {\n return;\n }\n\n setActiveDescendant(undefined);\n },\n active: () => {\n if (listboxRef.current) {\n return getActiveDescendant()?.id;\n }\n },\n\n focus: (id: string) => {\n if (!listboxRef.current) {\n return;\n }\n\n optionWalker.setCurrent(listboxRef.current);\n let cur = optionWalker.next();\n\n while (cur && cur.id !== id) {\n cur = optionWalker.next();\n }\n\n if (cur) {\n setActiveDescendant(cur);\n }\n },\n }));\n\n return { listboxRef, activeParentRef };\n}\n"],"names":["React","useOptionWalker","ACTIVEDESCENDANT_ATTRIBUTE","useActiveDescendant","options","imperativeRef","matchOption","activeParentRef","useRef","listboxRef","optionWalker","getActiveDescendant","current","querySelector","scrollActiveIntoView","active","offsetHeight","scrollHeight","offsetTop","parentOffsetHeight","scrollTop","isAbove","isBelow","buffer","scrollTo","setActiveDescendant","nextActive","removeAttribute","setAttribute","id","useImperativeHandle","first","setCurrent","next","prev","blur","undefined","focus","cur"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,eAAe,QAAQ,oBAAoB;AAEpD,SAASC,0BAA0B,QAAQ,cAAc;AAEzD,OAAO,SAASC,oBACdC,OAAgC;IAEhC,MAAM,EAAEC,aAAa,EAAEC,WAAW,EAAE,GAAGF;IACvC,MAAMG,kBAAkBP,MAAMQ,MAAM,CAAuB;IAC3D,MAAM,EAAEC,UAAU,EAAEC,YAAY,EAAE,GAAGT,gBAAiC;QAAEK;IAAY;IACpF,MAAMK,sBAAsB;YACnBF;QAAP,QAAOA,sBAAAA,WAAWG,OAAO,cAAlBH,0CAAAA,oBAAoBI,aAAa,CAAc,CAAC,CAAC,EAAEX,2BAA2B,CAAC,CAAC;IACzF;IAEA,MAAMY,uBAAuB,CAACC;QAC5B,IAAI,CAACN,WAAWG,OAAO,EAAE;YACvB;QACF;QAEA,IAAIH,WAAWG,OAAO,CAACI,YAAY,IAAIP,WAAWG,OAAO,CAACK,YAAY,EAAE;YACtE;QACF;QAEA,MAAM,EAAED,YAAY,EAAEE,SAAS,EAAE,GAAGH;QACpC,MAAM,EAAEC,cAAcG,kBAAkB,EAAEC,SAAS,EAAE,GAAGX,WAAWG,OAAO;QAE1E,MAAMS,UAAUH,YAAYE;QAC5B,MA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AAO,EAAE;oBACnD;gBACF;gBAEA,MAAMG,SAASJ;gBACf,IAAI,CAACI,QAAQ;oBACX;gBACF;gBAEAL,aAAasB,UAAU,CAACjB;gBACxB,IAAI,CAACT,YAAYS,SAAS;oBACxBL,aAAawB,IAAI;gBACnB;gBAEA,MAAMD,OAAOvB,aAAawB,IAAI;gBAE9B,IAAID,QAAQA,SAASxB,WAAWG,OAAO,EAAE;oBACvCa,oBAAoBQ;gBACtB;YACF;YACAE,MAAM;gBACJ,IAAI,CAAC5B,gBAAgBK,OAAO,EAAE;oBAC5B;gBACF;gBAEAa,oBAAoBW;YACtB;YACArB,QAAQ;gBACN,IAAIN,WAAWG,OAAO,EAAE;wBACfD;oBAAP,QAAOA,uBAAAA,mCAAAA,2CAAAA,qBAAuBkB,EAAE;gBAClC;YACF;YAEAQ,OAAO,CAACR;gBACN,IAAI,CAACpB,WAAWG,OAAO,EAAE;oBACvB;gBACF;gBAEAF,aAAasB,UAAU,CAACvB,WAAWG,OAAO;gBAC1C,IAAI0B,MAAM5B,aAAauB,IAAI;gBAE3B,MAAOK,OAAOA,IAAIT,EAAE,KAAKA,GAAI;oBAC3BS,MAAM5B,aAAauB,IAAI;gBACzB;gBAEA,IAAIK,KAAK;oBACPb,oBAAoBa;gBACtB;YACF;QACF,CAAA;IAEA,OAAO;QAAE7B;QAAYF;IAAgB;AACvC"}
|
|
@@ -22,6 +22,25 @@ function useActiveDescendant(options) {
|
|
|
22
22
|
var _listboxRef_current;
|
|
23
23
|
return (_listboxRef_current = listboxRef.current) === null || _listboxRef_current === void 0 ? void 0 : _listboxRef_current.querySelector(`[${_constants.ACTIVEDESCENDANT_ATTRIBUTE}]`);
|
|
24
24
|
};
|
|
25
|
+
const scrollActiveIntoView = (active)=>{
|
|
26
|
+
if (!listboxRef.current) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (listboxRef.current.offsetHeight >= listboxRef.current.scrollHeight) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const { offsetHeight, offsetTop } = active;
|
|
33
|
+
const { offsetHeight: parentOffsetHeight, scrollTop } = listboxRef.current;
|
|
34
|
+
const isAbove = offsetTop < scrollTop;
|
|
35
|
+
const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;
|
|
36
|
+
const buffer = 2;
|
|
37
|
+
if (isAbove) {
|
|
38
|
+
listboxRef.current.scrollTo(0, offsetTop - buffer);
|
|
39
|
+
}
|
|
40
|
+
if (isBelow) {
|
|
41
|
+
listboxRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
25
44
|
const setActiveDescendant = (nextActive)=>{
|
|
26
45
|
const active = getActiveDescendant();
|
|
27
46
|
if (active) {
|
|
@@ -30,6 +49,7 @@ function useActiveDescendant(options) {
|
|
|
30
49
|
if (nextActive) {
|
|
31
50
|
var _activeParentRef_current;
|
|
32
51
|
nextActive.setAttribute(_constants.ACTIVEDESCENDANT_ATTRIBUTE, '');
|
|
52
|
+
scrollActiveIntoView(nextActive);
|
|
33
53
|
(_activeParentRef_current = activeParentRef.current) === null || _activeParentRef_current === void 0 ? void 0 : _activeParentRef_current.setAttribute('aria-activedescendant', nextActive.id);
|
|
34
54
|
} else {
|
|
35
55
|
var _activeParentRef_current1;
|
|
@@ -41,6 +61,7 @@ function useActiveDescendant(options) {
|
|
|
41
61
|
if (!listboxRef.current || !activeParentRef.current) {
|
|
42
62
|
return;
|
|
43
63
|
}
|
|
64
|
+
optionWalker.setCurrent(listboxRef.current);
|
|
44
65
|
const first = optionWalker.first();
|
|
45
66
|
if (first) {
|
|
46
67
|
setActiveDescendant(first);
|
|
@@ -69,13 +90,16 @@ function useActiveDescendant(options) {
|
|
|
69
90
|
return;
|
|
70
91
|
}
|
|
71
92
|
optionWalker.setCurrent(active);
|
|
93
|
+
if (!matchOption(active)) {
|
|
94
|
+
optionWalker.prev();
|
|
95
|
+
}
|
|
72
96
|
const next = optionWalker.prev();
|
|
73
97
|
if (next && next !== listboxRef.current) {
|
|
74
98
|
setActiveDescendant(next);
|
|
75
99
|
}
|
|
76
100
|
},
|
|
77
101
|
blur: ()=>{
|
|
78
|
-
if (!
|
|
102
|
+
if (!activeParentRef.current) {
|
|
79
103
|
return;
|
|
80
104
|
}
|
|
81
105
|
setActiveDescendant(undefined);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useActiveDescendant.js"],"sourcesContent":["import * as React from 'react';\nimport { useOptionWalker } from './useOptionWalker';\nimport { ACTIVEDESCENDANT_ATTRIBUTE } from './constants';\nexport function useActiveDescendant(options) {\n const { imperativeRef, matchOption } = options;\n const activeParentRef = React.useRef(null);\n const { listboxRef, optionWalker } = useOptionWalker({\n matchOption\n });\n const getActiveDescendant = ()=>{\n var _listboxRef_current;\n return (_listboxRef_current = listboxRef.current) === null || _listboxRef_current === void 0 ? void 0 : _listboxRef_current.querySelector(`[${ACTIVEDESCENDANT_ATTRIBUTE}]`);\n };\n const setActiveDescendant = (nextActive)=>{\n const active = getActiveDescendant();\n if (active) {\n active.removeAttribute(ACTIVEDESCENDANT_ATTRIBUTE);\n }\n if (nextActive) {\n var _activeParentRef_current;\n nextActive.setAttribute(ACTIVEDESCENDANT_ATTRIBUTE, '');\n (_activeParentRef_current = activeParentRef.current) === null || _activeParentRef_current === void 0 ? void 0 : _activeParentRef_current.setAttribute('aria-activedescendant', nextActive.id);\n } else {\n var _activeParentRef_current1;\n (_activeParentRef_current1 = activeParentRef.current) === null || _activeParentRef_current1 === void 0 ? void 0 : _activeParentRef_current1.removeAttribute('aria-activedescendant');\n }\n };\n React.useImperativeHandle(imperativeRef, ()=>({\n first: ()=>{\n if (!listboxRef.current || !activeParentRef.current) {\n return;\n }\n const first = optionWalker.first();\n if (first) {\n setActiveDescendant(first);\n }\n },\n next: ()=>{\n if (!listboxRef.current || !activeParentRef.current) {\n return;\n }\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n optionWalker.setCurrent(active);\n const next = optionWalker.next();\n if (next) {\n setActiveDescendant(next);\n }\n },\n prev: ()=>{\n if (!listboxRef.current || !activeParentRef.current) {\n return;\n }\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n optionWalker.setCurrent(active);\n const next = optionWalker.prev();\n if (next && next !== listboxRef.current) {\n setActiveDescendant(next);\n }\n },\n blur: ()=>{\n if (!
|
|
1
|
+
{"version":3,"sources":["useActiveDescendant.js"],"sourcesContent":["import * as React from 'react';\nimport { useOptionWalker } from './useOptionWalker';\nimport { ACTIVEDESCENDANT_ATTRIBUTE } from './constants';\nexport function useActiveDescendant(options) {\n const { imperativeRef, matchOption } = options;\n const activeParentRef = React.useRef(null);\n const { listboxRef, optionWalker } = useOptionWalker({\n matchOption\n });\n const getActiveDescendant = ()=>{\n var _listboxRef_current;\n return (_listboxRef_current = listboxRef.current) === null || _listboxRef_current === void 0 ? void 0 : _listboxRef_current.querySelector(`[${ACTIVEDESCENDANT_ATTRIBUTE}]`);\n };\n const scrollActiveIntoView = (active)=>{\n if (!listboxRef.current) {\n return;\n }\n if (listboxRef.current.offsetHeight >= listboxRef.current.scrollHeight) {\n return;\n }\n const { offsetHeight, offsetTop } = active;\n const { offsetHeight: parentOffsetHeight, scrollTop } = listboxRef.current;\n const isAbove = offsetTop < scrollTop;\n const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;\n const buffer = 2;\n if (isAbove) {\n listboxRef.current.scrollTo(0, offsetTop - buffer);\n }\n if (isBelow) {\n listboxRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);\n }\n };\n const setActiveDescendant = (nextActive)=>{\n const active = getActiveDescendant();\n if (active) {\n active.removeAttribute(ACTIVEDESCENDANT_ATTRIBUTE);\n }\n if (nextActive) {\n var _activeParentRef_current;\n nextActive.setAttribute(ACTIVEDESCENDANT_ATTRIBUTE, '');\n scrollActiveIntoView(nextActive);\n (_activeParentRef_current = activeParentRef.current) === null || _activeParentRef_current === void 0 ? void 0 : _activeParentRef_current.setAttribute('aria-activedescendant', nextActive.id);\n } else {\n var _activeParentRef_current1;\n (_activeParentRef_current1 = activeParentRef.current) === null || _activeParentRef_current1 === void 0 ? void 0 : _activeParentRef_current1.removeAttribute('aria-activedescendant');\n }\n };\n React.useImperativeHandle(imperativeRef, ()=>({\n first: ()=>{\n if (!listboxRef.current || !activeParentRef.current) {\n return;\n }\n optionWalker.setCurrent(listboxRef.current);\n const first = optionWalker.first();\n if (first) {\n setActiveDescendant(first);\n }\n },\n next: ()=>{\n if (!listboxRef.current || !activeParentRef.current) {\n return;\n }\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n optionWalker.setCurrent(active);\n const next = optionWalker.next();\n if (next) {\n setActiveDescendant(next);\n }\n },\n prev: ()=>{\n if (!listboxRef.current || !activeParentRef.current) {\n return;\n }\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n optionWalker.setCurrent(active);\n if (!matchOption(active)) {\n optionWalker.prev();\n }\n const next = optionWalker.prev();\n if (next && next !== listboxRef.current) {\n setActiveDescendant(next);\n }\n },\n blur: ()=>{\n if (!activeParentRef.current) {\n return;\n }\n setActiveDescendant(undefined);\n },\n active: ()=>{\n if (listboxRef.current) {\n var _getActiveDescendant;\n return (_getActiveDescendant = getActiveDescendant()) === null || _getActiveDescendant === void 0 ? void 0 : _getActiveDescendant.id;\n }\n },\n focus: (id)=>{\n if (!listboxRef.current) {\n return;\n }\n optionWalker.setCurrent(listboxRef.current);\n let cur = optionWalker.next();\n while(cur && cur.id !== id){\n cur = optionWalker.next();\n }\n if (cur) {\n setActiveDescendant(cur);\n }\n }\n }));\n return {\n listboxRef,\n activeParentRef\n };\n}\n"],"names":["useActiveDescendant","options","imperativeRef","matchOption","activeParentRef","React","useRef","listboxRef","optionWalker","useOptionWalker","getActiveDescendant","_listboxRef_current","current","querySelector","ACTIVEDESCENDANT_ATTRIBUTE","scrollActiveIntoView","active","offsetHeight","scrollHeight","offsetTop","parentOffsetHeight","scrollTop","isAbove","isBelow","buffer","scrollTo","setActiveDescendant","nextActive","removeAttribute","_activeParentRef_current","setAttribute","id","_activeParentRef_current1","useImperativeHandle","first","setCurrent","next","prev","blur","undefined","_getActiveDescendant","focus","cur"],"mappings":";;;;+BAGgBA;;;eAAAA;;;;iEAHO;iCACS;2BACW;AACpC,SAASA,oBAAoBC,OAAO;IACvC,MAAM,EAAEC,aAAa,EAAEC,WAAW,EAAE,GAAGF;IACvC,MAAMG,kBAAkBC,OAAMC,MAAM,CAAC;IACrC,MAAM,EAAEC,UAAU,EAAEC,YAAY,EAAE,GAAGC,IAAAA,gCAAe,EAAC;QACjDN;IACJ;IACA,MAAMO,sBAAsB;QACxB,IAAIC;QACJ,OAAO,AAACA,CAAAA,sBAAsBJ,WAAWK,OAAO,AAAD,MAAO,QAAQD,wBAAwB,KAAK,IAAI,KAAK,IAAIA,oBAAoBE,aAAa,CAAC,CAAC,CAAC,EAAEC,qCAA0B,CAAC,CAAC,CAAC;IAC/K;IACA,MAAMC,uBAAuB,CAACC;QAC1B,IAAI,CAACT,WAAWK,OAAO,EAAE;YACrB;QACJ;QACA,IAAIL,WAAWK,OAAO,CAACK,YAAY,IAAIV,WAAWK,OAAO,CAACM,YAAY,EAAE;YACpE;QACJ;QACA,MAAM,EAAED,YAAY,EAAEE,SAAS,EAAE,GAAGH;QACpC,MAAM,EAAEC,cAAcG,kBAAkB,EAAEC,SAAS,EAAE,GAAGd,WAAWK,OAAO;QAC1E,MAAMU,UAAUH,YAAYE;QAC5B,MAAME,UAAUJ,YAAYF,eAAeI,YAAYD;QACvD,MAAMI,SAAS;QACf,IAAIF,SAAS;YACTf,WAAWK,OAAO,CAACa,QAAQ,CAAC,GAAGN,YAAYK;QAC/C;QACA,IAAID,SAAS;YACThB,WAAWK,OAAO,CAACa,QAAQ,CAAC,GAAGN,YAAYC,qBAAqBH,eAAeO;QACnF;IACJ;IACA,MAAME,sBAAsB,CAACC;QACzB,MAAMX,SAASN;QACf,IAAIM,QAAQ;YAC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MD,OAAO5B,aAAa6B,IAAI;gBAC9B,IAAID,QAAQA,SAAS7B,WAAWK,OAAO,EAAE;oBACrCc,oBAAoBU;gBACxB;YACJ;YACAE,MAAM;gBACF,IAAI,CAAClC,gBAAgBQ,OAAO,EAAE;oBAC1B;gBACJ;gBACAc,oBAAoBa;YACxB;YACAvB,QAAQ;gBACJ,IAAIT,WAAWK,OAAO,EAAE;oBACpB,IAAI4B;oBACJ,OAAO,AAACA,CAAAA,uBAAuB9B,qBAAoB,MAAO,QAAQ8B,yBAAyB,KAAK,IAAI,KAAK,IAAIA,qBAAqBT,EAAE;gBACxI;YACJ;YACAU,OAAO,CAACV;gBACJ,IAAI,CAACxB,WAAWK,OAAO,EAAE;oBACrB;gBACJ;gBACAJ,aAAa2B,UAAU,CAAC5B,WAAWK,OAAO;gBAC1C,IAAI8B,MAAMlC,aAAa4B,IAAI;gBAC3B,MAAMM,OAAOA,IAAIX,EAAE,KAAKA,GAAG;oBACvBW,MAAMlC,aAAa4B,IAAI;gBAC3B;gBACA,IAAIM,KAAK;oBACLhB,oBAAoBgB;gBACxB;YACJ;QACJ,CAAA;IACJ,OAAO;QACHnC;QACAH;IACJ;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui/react-aria",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.5.0",
|
|
4
4
|
"description": "React helper to ensure ARIA",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@fluentui/keyboard-keys": "^9.0.7",
|
|
35
|
-
"@fluentui/react-shared-contexts": "^9.13.
|
|
36
|
-
"@fluentui/react-utilities": "^9.15.
|
|
35
|
+
"@fluentui/react-shared-contexts": "^9.13.1",
|
|
36
|
+
"@fluentui/react-utilities": "^9.15.3",
|
|
37
37
|
"@swc/helpers": "^0.5.1"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|