@fluentui/react-aria 9.8.2 → 9.9.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 +15 -3
- package/dist/index.d.ts +18 -1
- package/lib/activedescendant/ActiveDescendantContext.js +21 -0
- package/lib/activedescendant/ActiveDescendantContext.js.map +1 -0
- package/lib/activedescendant/index.js +1 -0
- package/lib/activedescendant/index.js.map +1 -1
- package/lib/activedescendant/types.js.map +1 -1
- package/lib/activedescendant/useActiveDescendant.js +6 -5
- package/lib/activedescendant/useActiveDescendant.js.map +1 -1
- package/lib/activedescendant/useOptionWalker.js +14 -9
- package/lib/activedescendant/useOptionWalker.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib-commonjs/activedescendant/ActiveDescendantContext.js +43 -0
- package/lib-commonjs/activedescendant/ActiveDescendantContext.js.map +1 -0
- package/lib-commonjs/activedescendant/index.js +1 -0
- package/lib-commonjs/activedescendant/index.js.map +1 -1
- package/lib-commonjs/activedescendant/useActiveDescendant.js +5 -4
- package/lib-commonjs/activedescendant/useActiveDescendant.js.map +1 -1
- package/lib-commonjs/activedescendant/useOptionWalker.js +13 -8
- package/lib-commonjs/activedescendant/useOptionWalker.js.map +1 -1
- package/lib-commonjs/index.js +9 -0
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-aria
|
|
2
2
|
|
|
3
|
-
This log was last generated on Tue,
|
|
3
|
+
This log was last generated on Tue, 20 Feb 2024 14:15:20 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [9.9.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.9.0)
|
|
8
|
+
|
|
9
|
+
Tue, 20 Feb 2024 14:15:20 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-aria_v9.8.2..@fluentui/react-aria_v9.9.0)
|
|
11
|
+
|
|
12
|
+
### Minor changes
|
|
13
|
+
|
|
14
|
+
- feat: adds a context for active descendant ([PR #30528](https://github.com/microsoft/fluentui/pull/30528) by lingfan.gao@microsoft.com)
|
|
15
|
+
- Bump @fluentui/react-jsx-runtime to v9.0.30 ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by beachball)
|
|
16
|
+
- Bump @fluentui/react-tabster to v9.19.1 ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by beachball)
|
|
17
|
+
- Bump @fluentui/react-utilities to v9.18.1 ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by beachball)
|
|
18
|
+
|
|
7
19
|
## [9.8.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.8.2)
|
|
8
20
|
|
|
9
|
-
Tue, 06 Feb 2024 17:
|
|
21
|
+
Tue, 06 Feb 2024 17:55:18 GMT
|
|
10
22
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-aria_v9.8.1..@fluentui/react-aria_v9.8.2)
|
|
11
23
|
|
|
12
24
|
### Patches
|
|
13
25
|
|
|
14
26
|
- chore: adds @fluentui/react-jsx-runtime as dependency ([PR #30485](https://github.com/microsoft/fluentui/pull/30485) by bernardo.sunderhus@gmail.com)
|
|
15
|
-
- Bump @fluentui/react-tabster to v9.19.0 ([PR #
|
|
27
|
+
- Bump @fluentui/react-tabster to v9.19.0 ([PR #30392](https://github.com/microsoft/fluentui/pull/30392) by beachball)
|
|
16
28
|
|
|
17
29
|
## [9.8.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-aria_v9.8.1)
|
|
18
30
|
|
package/dist/index.d.ts
CHANGED
|
@@ -10,12 +10,18 @@ import type { UnionToIntersection } from '@fluentui/react-utilities';
|
|
|
10
10
|
*/
|
|
11
11
|
export declare const ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE = "data-activedescendant-focusvisible";
|
|
12
12
|
|
|
13
|
+
export declare const ActiveDescendantContextProvider: React_2.Provider<ActiveDescendantContextValue | undefined>;
|
|
14
|
+
|
|
15
|
+
export declare type ActiveDescendantContextValue = {
|
|
16
|
+
controller: ActiveDescendantImperativeRef;
|
|
17
|
+
};
|
|
18
|
+
|
|
13
19
|
export declare interface ActiveDescendantImperativeRef {
|
|
14
20
|
first: (options?: IteratorOptions) => string | undefined;
|
|
15
21
|
last: (options?: IteratorOptions) => string | undefined;
|
|
16
22
|
next: (options?: IteratorOptions) => string | undefined;
|
|
17
23
|
prev: (options?: IteratorOptions) => string | undefined;
|
|
18
|
-
find: (predicate: (id: string) => boolean, options?: IteratorOptions) => string | undefined;
|
|
24
|
+
find: (predicate: (id: string) => boolean, options?: IteratorOptions & FindOptions) => string | undefined;
|
|
19
25
|
blur: () => void;
|
|
20
26
|
active: () => string | undefined;
|
|
21
27
|
focus: (id: string) => void;
|
|
@@ -93,6 +99,13 @@ export declare type AriaLiveAnnouncerState = {
|
|
|
93
99
|
children?: React_2.ReactNode;
|
|
94
100
|
};
|
|
95
101
|
|
|
102
|
+
declare interface FindOptions {
|
|
103
|
+
/**
|
|
104
|
+
* Starts the search from a specific id
|
|
105
|
+
*/
|
|
106
|
+
startFrom?: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
96
109
|
declare interface IteratorOptions {
|
|
97
110
|
/**
|
|
98
111
|
* When passive, the active descendant is changed
|
|
@@ -105,6 +118,8 @@ export declare const renderAriaLiveAnnouncer_unstable: (state: AriaLiveAnnouncer
|
|
|
105
118
|
|
|
106
119
|
export declare function useActiveDescendant<TActiveParentElement extends HTMLElement, TListboxElement extends HTMLElement>(options: ActiveDescendantOptions): UseActiveDescendantReturn<TActiveParentElement, TListboxElement>;
|
|
107
120
|
|
|
121
|
+
export declare const useActiveDescendantContext: () => ActiveDescendantContextValue;
|
|
122
|
+
|
|
108
123
|
declare interface UseActiveDescendantReturn<TActiveParentElement extends HTMLElement = HTMLElement, TListboxElement extends HTMLElement = HTMLElement> {
|
|
109
124
|
/**
|
|
110
125
|
* Attach this to the element that contains all active descendants
|
|
@@ -166,4 +181,6 @@ export declare const useAriaLiveAnnouncer_unstable: (props: AriaLiveAnnouncerPro
|
|
|
166
181
|
|
|
167
182
|
export declare function useAriaLiveAnnouncerContextValues_unstable(state: AriaLiveAnnouncerState): AriaLiveAnnouncerContextValues;
|
|
168
183
|
|
|
184
|
+
export declare const useHasParentActiveDescendantContext: () => boolean;
|
|
185
|
+
|
|
169
186
|
export { }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
const noop = ()=>undefined;
|
|
3
|
+
const activeDescendantContextDefaultValue = {
|
|
4
|
+
controller: {
|
|
5
|
+
active: noop,
|
|
6
|
+
blur: noop,
|
|
7
|
+
find: noop,
|
|
8
|
+
first: noop,
|
|
9
|
+
focus: noop,
|
|
10
|
+
last: noop,
|
|
11
|
+
next: noop,
|
|
12
|
+
prev: noop
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const ActiveDescendantContext = React.createContext(undefined);
|
|
16
|
+
export const ActiveDescendantContextProvider = ActiveDescendantContext.Provider;
|
|
17
|
+
export const useActiveDescendantContext = ()=>{
|
|
18
|
+
var _React_useContext;
|
|
19
|
+
return (_React_useContext = React.useContext(ActiveDescendantContext)) !== null && _React_useContext !== void 0 ? _React_useContext : activeDescendantContextDefaultValue;
|
|
20
|
+
};
|
|
21
|
+
export const useHasParentActiveDescendantContext = ()=>!!React.useContext(ActiveDescendantContext);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["ActiveDescendantContext.ts"],"sourcesContent":["import * as React from 'react';\nimport { ActiveDescendantImperativeRef } from './types';\n\nexport type ActiveDescendantContextValue = {\n controller: ActiveDescendantImperativeRef;\n};\n\nconst noop = () => undefined;\n\nconst activeDescendantContextDefaultValue: ActiveDescendantContextValue = {\n controller: {\n active: noop,\n blur: noop,\n find: noop,\n first: noop,\n focus: noop,\n last: noop,\n next: noop,\n prev: noop,\n },\n};\n\nconst ActiveDescendantContext = React.createContext<ActiveDescendantContextValue | undefined>(undefined);\n\nexport const ActiveDescendantContextProvider = ActiveDescendantContext.Provider;\nexport const useActiveDescendantContext = () =>\n React.useContext(ActiveDescendantContext) ?? activeDescendantContextDefaultValue;\nexport const useHasParentActiveDescendantContext = () => !!React.useContext(ActiveDescendantContext);\n"],"names":["React","noop","undefined","activeDescendantContextDefaultValue","controller","active","blur","find","first","focus","last","next","prev","ActiveDescendantContext","createContext","ActiveDescendantContextProvider","Provider","useActiveDescendantContext","useContext","useHasParentActiveDescendantContext"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAO/B,MAAMC,OAAO,IAAMC;AAEnB,MAAMC,sCAAoE;IACxEC,YAAY;QACVC,QAAQJ;QACRK,MAAML;QACNM,MAAMN;QACNO,OAAOP;QACPQ,OAAOR;QACPS,MAAMT;QACNU,MAAMV;QACNW,MAAMX;IACR;AACF;AAEA,MAAMY,0BAA0Bb,MAAMc,aAAa,CAA2CZ;AAE9F,OAAO,MAAMa,kCAAkCF,wBAAwBG,QAAQ,CAAC;AAChF,OAAO,MAAMC,6BAA6B;QACxCjB;WAAAA,CAAAA,oBAAAA,MAAMkB,UAAU,CAACL,sCAAjBb,+BAAAA,oBAA6CG;AAAkC,EAAE;AACnF,OAAO,MAAMgB,sCAAsC,IAAM,CAAC,CAACnB,MAAMkB,UAAU,CAACL,yBAAyB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["export * from './useActiveDescendant';\nexport * from './constants';\nexport * from './types';\n"],"names":[],"mappings":"AAAA,cAAc,wBAAwB;AACtC,cAAc,cAAc;AAC5B,cAAc,UAAU"}
|
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export * from './ActiveDescendantContext';\nexport * from './useActiveDescendant';\nexport * from './constants';\nexport * from './types';\n"],"names":[],"mappings":"AAAA,cAAc,4BAA4B;AAC1C,cAAc,wBAAwB;AACtC,cAAc,cAAc;AAC5B,cAAc,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["types.ts"],"sourcesContent":["import * as React from 'react';\n\nexport interface ActiveDescendantImperativeRef {\n first: (options?: IteratorOptions) => string | undefined;\n last: (options?: IteratorOptions) => string | undefined;\n next: (options?: IteratorOptions) => string | undefined;\n prev: (options?: IteratorOptions) => string | undefined;\n find: (predicate: (id: string) => boolean, options?: IteratorOptions) => string | undefined;\n blur: () => void;\n active: () => string | undefined;\n focus: (id: string) => void;\n}\n\nexport interface ActiveDescendantOptions {\n /**\n * @param el - HTML element to test\n * @returns whether the element can be an active descendant\n */\n matchOption: (el: HTMLElement) => boolean;\n /**\n * Forward imperative refs when exposing functionality from a React component\n */\n imperativeRef?: React.RefObject<ActiveDescendantImperativeRef>;\n}\n\nexport interface UseActiveDescendantReturn<\n TActiveParentElement extends HTMLElement = HTMLElement,\n TListboxElement extends HTMLElement = HTMLElement,\n> {\n /**\n * Attach this to the element that contains all active descendants\n */\n listboxRef: React.Ref<TListboxElement>;\n /**\n * Attach this to the element that has an active descendant\n */\n activeParentRef: React.Ref<TActiveParentElement>;\n /**\n * Imperative functions to manage active descendants within the listboxRef\n */\n controller: ActiveDescendantImperativeRef;\n}\n\nexport interface IteratorOptions {\n /**\n * When passive, the active descendant is changed\n * @default false\n */\n passive?: boolean;\n}\n"],"names":["React"],"mappings":"AAAA,YAAYA,WAAW,QAAQ"}
|
|
1
|
+
{"version":3,"sources":["types.ts"],"sourcesContent":["import * as React from 'react';\n\nexport interface ActiveDescendantImperativeRef {\n first: (options?: IteratorOptions) => string | undefined;\n last: (options?: IteratorOptions) => string | undefined;\n next: (options?: IteratorOptions) => string | undefined;\n prev: (options?: IteratorOptions) => string | undefined;\n find: (predicate: (id: string) => boolean, options?: IteratorOptions & FindOptions) => string | undefined;\n blur: () => void;\n active: () => string | undefined;\n focus: (id: string) => void;\n}\n\nexport interface ActiveDescendantOptions {\n /**\n * @param el - HTML element to test\n * @returns whether the element can be an active descendant\n */\n matchOption: (el: HTMLElement) => boolean;\n /**\n * Forward imperative refs when exposing functionality from a React component\n */\n imperativeRef?: React.RefObject<ActiveDescendantImperativeRef>;\n}\n\nexport interface FindOptions {\n /**\n * Starts the search from a specific id\n */\n startFrom?: string;\n}\n\nexport interface UseActiveDescendantReturn<\n TActiveParentElement extends HTMLElement = HTMLElement,\n TListboxElement extends HTMLElement = HTMLElement,\n> {\n /**\n * Attach this to the element that contains all active descendants\n */\n listboxRef: React.Ref<TListboxElement>;\n /**\n * Attach this to the element that has an active descendant\n */\n activeParentRef: React.Ref<TActiveParentElement>;\n /**\n * Imperative functions to manage active descendants within the listboxRef\n */\n controller: ActiveDescendantImperativeRef;\n}\n\nexport interface IteratorOptions {\n /**\n * When passive, the active descendant is changed\n * @default false\n */\n passive?: boolean;\n}\n"],"names":["React"],"mappings":"AAAA,YAAYA,WAAW,QAAQ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useEventCallback } from '@fluentui/react-utilities';
|
|
2
|
+
import { useEventCallback, useMergedRefs } from '@fluentui/react-utilities';
|
|
3
3
|
import { useOnKeyboardNavigationChange } from '@fluentui/react-tabster';
|
|
4
4
|
import { useOptionWalker } from './useOptionWalker';
|
|
5
5
|
import { ACTIVEDESCENDANT_ATTRIBUTE, ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE } from './constants';
|
|
@@ -22,7 +22,8 @@ export function useActiveDescendant(options) {
|
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
const matchOption = useEventCallback(matchOptionUnstable);
|
|
25
|
-
const
|
|
25
|
+
const listboxRef = React.useRef(null);
|
|
26
|
+
const { optionWalker, listboxCallbackRef } = useOptionWalker({
|
|
26
27
|
matchOption
|
|
27
28
|
});
|
|
28
29
|
const getActiveDescendant = React.useCallback(()=>{
|
|
@@ -117,8 +118,8 @@ export function useActiveDescendant(options) {
|
|
|
117
118
|
focusActiveDescendant(target);
|
|
118
119
|
}
|
|
119
120
|
},
|
|
120
|
-
find (predicate, { passive } = {}) {
|
|
121
|
-
const target = optionWalker.find(predicate);
|
|
121
|
+
find (predicate, { passive, startFrom } = {}) {
|
|
122
|
+
const target = optionWalker.find(predicate, startFrom);
|
|
122
123
|
if (!passive) {
|
|
123
124
|
focusActiveDescendant(target);
|
|
124
125
|
}
|
|
@@ -133,7 +134,7 @@ export function useActiveDescendant(options) {
|
|
|
133
134
|
]);
|
|
134
135
|
React.useImperativeHandle(imperativeRef, ()=>controller);
|
|
135
136
|
return {
|
|
136
|
-
listboxRef,
|
|
137
|
+
listboxRef: useMergedRefs(listboxRef, listboxCallbackRef),
|
|
137
138
|
activeParentRef,
|
|
138
139
|
controller
|
|
139
140
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useActiveDescendant.ts"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from '@fluentui/react-utilities';\nimport { useOnKeyboardNavigationChange } from '@fluentui/react-tabster';\nimport { useOptionWalker } from './useOptionWalker';\nimport type { ActiveDescendantImperativeRef, ActiveDescendantOptions, UseActiveDescendantReturn } from './types';\nimport { ACTIVEDESCENDANT_ATTRIBUTE, ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE } from './constants';\nimport { scrollIntoView } from './scrollIntoView';\n\nexport function useActiveDescendant<TActiveParentElement extends HTMLElement, TListboxElement extends HTMLElement>(\n options: ActiveDescendantOptions,\n): UseActiveDescendantReturn<TActiveParentElement, TListboxElement> {\n const { imperativeRef, matchOption: matchOptionUnstable } = options;\n const focusVisibleRef = React.useRef(false);\n const activeIdRef = React.useRef<string | null>(null);\n const activeParentRef = React.useRef<TActiveParentElement>(null);\n\n useOnKeyboardNavigationChange(isNavigatingWithKeyboard => {\n focusVisibleRef.current = isNavigatingWithKeyboard;\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n\n if (isNavigatingWithKeyboard) {\n active.setAttribute(ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE, '');\n } else {\n active.removeAttribute(ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE);\n }\n });\n\n const matchOption = useEventCallback(matchOptionUnstable);\n const {
|
|
1
|
+
{"version":3,"sources":["useActiveDescendant.ts"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { useOnKeyboardNavigationChange } from '@fluentui/react-tabster';\nimport { useOptionWalker } from './useOptionWalker';\nimport type { ActiveDescendantImperativeRef, ActiveDescendantOptions, UseActiveDescendantReturn } from './types';\nimport { ACTIVEDESCENDANT_ATTRIBUTE, ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE } from './constants';\nimport { scrollIntoView } from './scrollIntoView';\n\nexport function useActiveDescendant<TActiveParentElement extends HTMLElement, TListboxElement extends HTMLElement>(\n options: ActiveDescendantOptions,\n): UseActiveDescendantReturn<TActiveParentElement, TListboxElement> {\n const { imperativeRef, matchOption: matchOptionUnstable } = options;\n const focusVisibleRef = React.useRef(false);\n const activeIdRef = React.useRef<string | null>(null);\n const activeParentRef = React.useRef<TActiveParentElement>(null);\n\n useOnKeyboardNavigationChange(isNavigatingWithKeyboard => {\n focusVisibleRef.current = isNavigatingWithKeyboard;\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n\n if (isNavigatingWithKeyboard) {\n active.setAttribute(ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE, '');\n } else {\n active.removeAttribute(ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE);\n }\n });\n\n const matchOption = useEventCallback(matchOptionUnstable);\n const listboxRef = React.useRef<TListboxElement>(null);\n const { optionWalker, listboxCallbackRef } = useOptionWalker<TListboxElement>({ matchOption });\n const getActiveDescendant = React.useCallback(() => {\n return listboxRef.current?.querySelector<HTMLElement>(`#${activeIdRef.current}`);\n }, [listboxRef]);\n\n const blurActiveDescendant = React.useCallback(() => {\n const active = getActiveDescendant();\n if (active) {\n active.removeAttribute(ACTIVEDESCENDANT_ATTRIBUTE);\n active.removeAttribute(ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE);\n }\n\n activeParentRef.current?.removeAttribute('aria-activedescendant');\n activeIdRef.current = null;\n }, [activeParentRef, getActiveDescendant]);\n\n const focusActiveDescendant = React.useCallback(\n (nextActive: HTMLElement | null) => {\n if (!nextActive) {\n return;\n }\n\n blurActiveDescendant();\n\n scrollIntoView(nextActive, listboxRef.current);\n activeParentRef.current?.setAttribute('aria-activedescendant', nextActive.id);\n activeIdRef.current = nextActive.id;\n nextActive.setAttribute(ACTIVEDESCENDANT_ATTRIBUTE, '');\n\n if (focusVisibleRef.current) {\n nextActive.setAttribute(ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE, '');\n }\n },\n [activeParentRef, listboxRef, blurActiveDescendant],\n );\n\n const controller: ActiveDescendantImperativeRef = React.useMemo(\n () => ({\n first: ({ passive } = {}) => {\n const first = optionWalker.first();\n if (!passive) {\n focusActiveDescendant(first);\n }\n\n return first?.id;\n },\n last: ({ passive } = {}) => {\n const last = optionWalker.last();\n if (!passive) {\n focusActiveDescendant(last);\n }\n\n return last?.id;\n },\n next: ({ passive } = {}) => {\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n\n optionWalker.setCurrent(active);\n const next = optionWalker.next();\n if (!passive) {\n focusActiveDescendant(next);\n }\n\n return next?.id;\n },\n prev: ({ passive } = {}) => {\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n\n optionWalker.setCurrent(active);\n const next = optionWalker.prev();\n\n if (!passive) {\n focusActiveDescendant(next);\n }\n\n return next?.id;\n },\n blur: () => {\n blurActiveDescendant();\n },\n active: () => {\n return getActiveDescendant()?.id;\n },\n\n focus: (id: string) => {\n if (!listboxRef.current) {\n return;\n }\n\n const target = listboxRef.current.querySelector<HTMLElement>(`#${id}`);\n if (target) {\n focusActiveDescendant(target);\n }\n },\n\n find(predicate, { passive, startFrom } = {}) {\n const target = optionWalker.find(predicate, startFrom);\n if (!passive) {\n focusActiveDescendant(target);\n }\n\n return target?.id;\n },\n }),\n [optionWalker, listboxRef, focusActiveDescendant, blurActiveDescendant, getActiveDescendant],\n );\n\n React.useImperativeHandle(imperativeRef, () => controller);\n\n return { listboxRef: useMergedRefs(listboxRef, listboxCallbackRef), activeParentRef, controller };\n}\n"],"names":["React","useEventCallback","useMergedRefs","useOnKeyboardNavigationChange","useOptionWalker","ACTIVEDESCENDANT_ATTRIBUTE","ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE","scrollIntoView","useActiveDescendant","options","imperativeRef","matchOption","matchOptionUnstable","focusVisibleRef","useRef","activeIdRef","activeParentRef","isNavigatingWithKeyboard","current","active","getActiveDescendant","setAttribute","removeAttribute","listboxRef","optionWalker","listboxCallbackRef","useCallback","querySelector","blurActiveDescendant","focusActiveDescendant","nextActive","id","controller","useMemo","first","passive","last","next","setCurrent","prev","blur","focus","target","find","predicate","startFrom","useImperativeHandle"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,gBAAgB,EAAEC,aAAa,QAAQ,4BAA4B;AAC5E,SAASC,6BAA6B,QAAQ,0BAA0B;AACxE,SAASC,eAAe,QAAQ,oBAAoB;AAEpD,SAASC,0BAA0B,EAAEC,uCAAuC,QAAQ,cAAc;AAClG,SAASC,cAAc,QAAQ,mBAAmB;AAElD,OAAO,SAASC,oBACdC,OAAgC;IAEhC,MAAM,EAAEC,aAAa,EAAEC,aAAaC,mBAAmB,EAAE,GAAGH;IAC5D,MAAMI,kBAAkBb,MAAMc,MAAM,CAAC;IACrC,MAAMC,cAAcf,MAAMc,MAAM,CAAgB;IAChD,MAAME,kBAAkBhB,MAAMc,MAAM,CAAuB;IAE3DX,8BAA8Bc,CAAAA;QAC5BJ,gBAAgBK,OAAO,GAAGD;QAC1B,MAAME,SAASC;QACf,IAAI,CAACD,QAA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,sBAAsBa;gBACxB;YACF;YAEAC,MAAKC,SAAS,EAAE,EAAET,OAAO,EAAEU,SAAS,EAAE,GAAG,CAAC,CAAC;gBACzC,MAAMH,SAASlB,aAAamB,IAAI,CAACC,WAAWC;gBAC5C,IAAI,CAACV,SAAS;oBACZN,sBAAsBa;gBACxB;gBAEA,OAAOA,mBAAAA,6BAAAA,OAAQX,EAAE;YACnB;QACF,CAAA,GACA;QAACP;QAAcD;QAAYM;QAAuBD;QAAsBR;KAAoB;IAG9FpB,MAAM8C,mBAAmB,CAACpC,eAAe,IAAMsB;IAE/C,OAAO;QAAET,YAAYrB,cAAcqB,YAAYE;QAAqBT;QAAiBgB;IAAW;AAClG"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
|
3
|
-
import { isHTMLElement
|
|
3
|
+
import { isHTMLElement } from '@fluentui/react-utilities';
|
|
4
4
|
export function useOptionWalker(options) {
|
|
5
5
|
const { matchOption } = options;
|
|
6
6
|
const { targetDocument } = useFluent();
|
|
@@ -14,11 +14,13 @@ export function useOptionWalker(options) {
|
|
|
14
14
|
}, [
|
|
15
15
|
matchOption
|
|
16
16
|
]);
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
|
|
17
|
+
const setListbox = React.useCallback((el)=>{
|
|
18
|
+
if (el && targetDocument) {
|
|
19
|
+
listboxRef.current = el;
|
|
20
|
+
treeWalkerRef.current = targetDocument.createTreeWalker(el, NodeFilter.SHOW_ELEMENT, optionFilter);
|
|
21
|
+
} else {
|
|
22
|
+
listboxRef.current = null;
|
|
20
23
|
}
|
|
21
|
-
treeWalkerRef.current = targetDocument.createTreeWalker(listboxRef.current, NodeFilter.SHOW_ELEMENT, optionFilter);
|
|
22
24
|
}, [
|
|
23
25
|
targetDocument,
|
|
24
26
|
optionFilter
|
|
@@ -49,11 +51,12 @@ export function useOptionWalker(options) {
|
|
|
49
51
|
}
|
|
50
52
|
return treeWalkerRef.current.previousNode();
|
|
51
53
|
},
|
|
52
|
-
find: (predicate)=>{
|
|
54
|
+
find: (predicate, startFrom)=>{
|
|
53
55
|
if (!treeWalkerRef.current || !listboxRef.current) {
|
|
54
56
|
return null;
|
|
55
57
|
}
|
|
56
|
-
|
|
58
|
+
const start = startFrom ? targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.getElementById(startFrom) : null;
|
|
59
|
+
treeWalkerRef.current.currentNode = start !== null && start !== void 0 ? start : listboxRef.current;
|
|
57
60
|
let cur = treeWalkerRef.current.currentNode;
|
|
58
61
|
while(cur && !predicate(cur.id)){
|
|
59
62
|
cur = treeWalkerRef.current.nextNode();
|
|
@@ -66,9 +69,11 @@ export function useOptionWalker(options) {
|
|
|
66
69
|
}
|
|
67
70
|
treeWalkerRef.current.currentNode = el;
|
|
68
71
|
}
|
|
69
|
-
}), [
|
|
72
|
+
}), [
|
|
73
|
+
targetDocument
|
|
74
|
+
]);
|
|
70
75
|
return {
|
|
71
76
|
optionWalker,
|
|
72
|
-
|
|
77
|
+
listboxCallbackRef: setListbox
|
|
73
78
|
};
|
|
74
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useOptionWalker.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { isHTMLElement
|
|
1
|
+
{"version":3,"sources":["useOptionWalker.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { isHTMLElement } from '@fluentui/react-utilities';\n\ninterface UseOptionWalkerOptions {\n matchOption: (el: HTMLElement) => boolean;\n}\n\nexport function useOptionWalker<TListboxElement extends HTMLElement>(options: UseOptionWalkerOptions) {\n const { matchOption } = options;\n const { targetDocument } = useFluent();\n const treeWalkerRef = React.useRef<TreeWalker | null>(null);\n const listboxRef = React.useRef<TListboxElement | null>(null);\n\n const optionFilter = React.useCallback(\n (node: Node) => {\n if (isHTMLElement(node) && matchOption(node)) {\n return NodeFilter.FILTER_ACCEPT;\n }\n\n return NodeFilter.FILTER_SKIP;\n },\n [matchOption],\n );\n\n const setListbox = React.useCallback(\n (el: TListboxElement) => {\n if (el && targetDocument) {\n listboxRef.current = el;\n treeWalkerRef.current = targetDocument.createTreeWalker(el, NodeFilter.SHOW_ELEMENT, optionFilter);\n } else {\n listboxRef.current = null;\n }\n },\n [targetDocument, optionFilter],\n );\n\n const optionWalker = React.useMemo(\n () => ({\n first: () => {\n if (!treeWalkerRef.current || !listboxRef.current) {\n return null;\n }\n\n treeWalkerRef.current.currentNode = listboxRef.current;\n return treeWalkerRef.current.firstChild() as HTMLElement | null;\n },\n last: () => {\n if (!treeWalkerRef.current || !listboxRef.current) {\n return null;\n }\n\n return treeWalkerRef.current.lastChild() as HTMLElement | null;\n },\n next: () => {\n if (!treeWalkerRef.current) {\n return null;\n }\n\n return treeWalkerRef.current.nextNode() as HTMLElement | null;\n },\n prev: () => {\n if (!treeWalkerRef.current) {\n return null;\n }\n\n return treeWalkerRef.current.previousNode() as HTMLElement | null;\n },\n find: (predicate: (id: string) => boolean, startFrom?: string) => {\n if (!treeWalkerRef.current || !listboxRef.current) {\n return null;\n }\n\n const start = startFrom ? targetDocument?.getElementById(startFrom) : null;\n treeWalkerRef.current.currentNode = start ?? listboxRef.current;\n let cur: HTMLElement | null = treeWalkerRef.current.currentNode as HTMLElement;\n while (cur && !predicate(cur.id)) {\n cur = treeWalkerRef.current.nextNode() as HTMLElement | null;\n }\n\n return cur;\n },\n setCurrent: (el: HTMLElement) => {\n if (!treeWalkerRef.current) {\n return;\n }\n\n treeWalkerRef.current.currentNode = el;\n },\n }),\n [targetDocument],\n );\n\n return {\n optionWalker,\n listboxCallbackRef: setListbox,\n };\n}\n"],"names":["React","useFluent_unstable","useFluent","isHTMLElement","useOptionWalker","options","matchOption","targetDocument","treeWalkerRef","useRef","listboxRef","optionFilter","useCallback","node","NodeFilter","FILTER_ACCEPT","FILTER_SKIP","setListbox","el","current","createTreeWalker","SHOW_ELEMENT","optionWalker","useMemo","first","currentNode","firstChild","last","lastChild","next","nextNode","prev","previousNode","find","predicate","startFrom","start","getElementById","cur","id","setCurrent","listboxCallbackRef"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,aAAa,QAAQ,4BAA4B;AAM1D,OAAO,SAASC,gBAAqDC,OAA+B;IAClG,MAAM,EAAEC,WAAW,EAAE,GAAGD;IACxB,MAAM,EAAEE,cAAc,EAAE,GAAGL;IAC3B,MAAMM,gBAAgBR,MAAMS,MAAM,CAAoB;IACtD,MAAMC,aAAaV,MAAMS,MAAM,CAAyB;IAExD,MAAME,eAAeX,MAAMY,WAAW,CACpC,CAACC;QACC,IAAIV,cAAcU,SAASP,YAAYO,OAAO;YAC5C,OAAOC,WAAWC,aAAa;QACjC;QAEA,OAAOD,WAAWE,WAAW;IAC/B,GACA;QAACV;KAAY;IAGf,MAAMW,aAAajB,MAAMY,WAAW,CAClC,CAACM;QACC,IAAIA,MAAMX,gBAAgB;YACxBG,WAAWS,OAAO,GAAGD;YACrBV,cAAcW,OAAO,GAAGZ,eAAea,gBAAgB,CAACF,IAAIJ,WAAWO,YAAY,EAAEV;QACvF,OAAO;YACLD,WAAWS,OAAO,GAAG;QACvB;IACF,GACA;QAACZ;QAAgBI;KAAa;IAGhC,MAAMW,eAAetB,MAAMuB,OAAO,CAChC,IAAO,CAAA;YACLC,OAAO;gBACL,IAAI,CAAChB,cAAcW,OAAO,IAAI,CAACT,WAAWS,OAAO,EAAE;oBACjD,OAAO;gBACT;gBAEAX,cAAcW,OAAO,CAACM,WAAW,GAAGf,WAAWS,OAAO;gBACtD,OAAOX,cAAcW,OAAO,CAACO,UAAU;YACzC;YACAC,MAAM;gBACJ,IAAI,CAACnB,cAAcW,OAAO,IAAI,CAACT,WAAWS,OAAO,EAAE;oBACjD,OAAO;gBACT;gBAEA,OAAOX,cAAcW,OAAO,CAACS,SAAS;YACxC;YACAC,MAAM;gBACJ,IAAI,CAACrB,cAAcW,OAAO,EAAE;oBAC1B,OAAO;gBACT;gBAEA,OAAOX,cAAcW,OAAO,CAACW,QAAQ;YACvC;YACAC,MAAM;gBACJ,IAAI,CAACvB,cAAcW,OAAO,EAAE;oBAC1B,OAAO;gBACT;gBAEA,OAAOX,cAAcW,OAAO,CAACa,YAAY;YAC3C;YACAC,MAAM,CAACC,WAAoCC;gBACzC,IAAI,CAAC3B,cAAcW,OAAO,IAAI,CAACT,WAAWS,OAAO,EAAE;oBACjD,OAAO;gBACT;gBAEA,MAAMiB,QAAQD,YAAY5B,2BAAAA,qCAAAA,eAAgB8B,cAAc,CAACF,aAAa;gBACtE3B,cAAcW,OAAO,CAACM,WAAW,GAAGW,kBAAAA,mBAAAA,QAAS1B,WAAWS,OAAO;gBAC/D,IAAImB,MAA0B9B,cAAcW,OAAO,CAACM,WAAW;gBAC/D,MAAOa,OAAO,CAACJ,UAAUI,IAAIC,EAAE,EAAG;oBAChCD,MAAM9B,cAAcW,OAAO,CAACW,QAAQ;gBACtC;gBAEA,OAAOQ;YACT;YACAE,YAAY,CAACtB;gBACX,IAAI,CAACV,cAAcW,OAAO,EAAE;oBAC1B;gBACF;gBAEAX,cAAcW,OAAO,CAACM,WAAW,GAAGP;YACtC;QACF,CAAA,GACA;QAACX;KAAe;IAGlB,OAAO;QACLe;QACAmB,oBAAoBxB;IACtB;AACF"}
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { // eslint-disable-next-line deprecation/deprecation
|
|
2
2
|
useARIAButtonShorthand, useARIAButtonProps } from './button/index';
|
|
3
|
-
export { useActiveDescendant, ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE } from './activedescendant';
|
|
3
|
+
export { useActiveDescendant, ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE, ActiveDescendantContextProvider, useActiveDescendantContext, useHasParentActiveDescendantContext } from './activedescendant';
|
|
4
4
|
export { AriaLiveAnnouncer, renderAriaLiveAnnouncer_unstable, useAriaLiveAnnouncer_unstable, useAriaLiveAnnouncerContextValues_unstable } from './AriaLiveAnnouncer/index';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["export {\n // eslint-disable-next-line deprecation/deprecation\n useARIAButtonShorthand,\n useARIAButtonProps,\n} from './button/index';\nexport {
|
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export {\n // eslint-disable-next-line deprecation/deprecation\n useARIAButtonShorthand,\n useARIAButtonProps,\n} from './button/index';\nexport {\n useActiveDescendant,\n ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE,\n ActiveDescendantContextProvider,\n useActiveDescendantContext,\n useHasParentActiveDescendantContext,\n} from './activedescendant';\nexport type {\n ActiveDescendantImperativeRef,\n ActiveDescendantOptions,\n ActiveDescendantContextValue,\n} from './activedescendant';\nexport type {\n ARIAButtonSlotProps,\n ARIAButtonProps,\n ARIAButtonResultProps,\n ARIAButtonType,\n ARIAButtonElement,\n ARIAButtonElementIntersection,\n ARIAButtonAlteredProps,\n} from './button/index';\n\nexport {\n AriaLiveAnnouncer,\n renderAriaLiveAnnouncer_unstable,\n useAriaLiveAnnouncer_unstable,\n useAriaLiveAnnouncerContextValues_unstable,\n} from './AriaLiveAnnouncer/index';\nexport type { AriaLiveAnnouncerProps, AriaLiveAnnouncerState } from './AriaLiveAnnouncer/index';\n"],"names":["useARIAButtonShorthand","useARIAButtonProps","useActiveDescendant","ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE","ActiveDescendantContextProvider","useActiveDescendantContext","useHasParentActiveDescendantContext","AriaLiveAnnouncer","renderAriaLiveAnnouncer_unstable","useAriaLiveAnnouncer_unstable","useAriaLiveAnnouncerContextValues_unstable"],"mappings":"AAAA,SACE,mDAAmD;AACnDA,sBAAsB,EACtBC,kBAAkB,QACb,iBAAiB;AACxB,SACEC,mBAAmB,EACnBC,uCAAuC,EACvCC,+BAA+B,EAC/BC,0BAA0B,EAC1BC,mCAAmC,QAC9B,qBAAqB;AAgB5B,SACEC,iBAAiB,EACjBC,gCAAgC,EAChCC,6BAA6B,EAC7BC,0CAA0C,QACrC,4BAA4B"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
ActiveDescendantContextProvider: function() {
|
|
13
|
+
return ActiveDescendantContextProvider;
|
|
14
|
+
},
|
|
15
|
+
useActiveDescendantContext: function() {
|
|
16
|
+
return useActiveDescendantContext;
|
|
17
|
+
},
|
|
18
|
+
useHasParentActiveDescendantContext: function() {
|
|
19
|
+
return useHasParentActiveDescendantContext;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
23
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
24
|
+
const noop = ()=>undefined;
|
|
25
|
+
const activeDescendantContextDefaultValue = {
|
|
26
|
+
controller: {
|
|
27
|
+
active: noop,
|
|
28
|
+
blur: noop,
|
|
29
|
+
find: noop,
|
|
30
|
+
first: noop,
|
|
31
|
+
focus: noop,
|
|
32
|
+
last: noop,
|
|
33
|
+
next: noop,
|
|
34
|
+
prev: noop
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const ActiveDescendantContext = /*#__PURE__*/ _react.createContext(undefined);
|
|
38
|
+
const ActiveDescendantContextProvider = ActiveDescendantContext.Provider;
|
|
39
|
+
const useActiveDescendantContext = ()=>{
|
|
40
|
+
var _React_useContext;
|
|
41
|
+
return (_React_useContext = _react.useContext(ActiveDescendantContext)) !== null && _React_useContext !== void 0 ? _React_useContext : activeDescendantContextDefaultValue;
|
|
42
|
+
};
|
|
43
|
+
const useHasParentActiveDescendantContext = ()=>!!_react.useContext(ActiveDescendantContext);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["ActiveDescendantContext.js"],"sourcesContent":["import * as React from 'react';\nconst noop = ()=>undefined;\nconst activeDescendantContextDefaultValue = {\n controller: {\n active: noop,\n blur: noop,\n find: noop,\n first: noop,\n focus: noop,\n last: noop,\n next: noop,\n prev: noop\n }\n};\nconst ActiveDescendantContext = React.createContext(undefined);\nexport const ActiveDescendantContextProvider = ActiveDescendantContext.Provider;\nexport const useActiveDescendantContext = ()=>{\n var _React_useContext;\n return (_React_useContext = React.useContext(ActiveDescendantContext)) !== null && _React_useContext !== void 0 ? _React_useContext : activeDescendantContextDefaultValue;\n};\nexport const useHasParentActiveDescendantContext = ()=>!!React.useContext(ActiveDescendantContext);\n"],"names":["ActiveDescendantContextProvider","useActiveDescendantContext","useHasParentActiveDescendantContext","noop","undefined","activeDescendantContextDefaultValue","controller","active","blur","find","first","focus","last","next","prev","ActiveDescendantContext","React","createContext","Provider","_React_useContext","useContext"],"mappings":";;;;;;;;;;;IAeaA,+BAA+B;eAA/BA;;IACAC,0BAA0B;eAA1BA;;IAIAC,mCAAmC;eAAnCA;;;;iEApBU;AACvB,MAAMC,OAAO,IAAIC;AACjB,MAAMC,sCAAsC;IACxCC,YAAY;QACRC,QAAQJ;QACRK,MAAML;QACNM,MAAMN;QACNO,OAAOP;QACPQ,OAAOR;QACPS,MAAMT;QACNU,MAAMV;QACNW,MAAMX;IACV;AACJ;AACA,MAAMY,wCAA0BC,OAAMC,aAAa,CAACb;AAC7C,MAAMJ,kCAAkCe,wBAAwBG,QAAQ;AACxE,MAAMjB,6BAA6B;IACtC,IAAIkB;IACJ,OAAO,AAACA,CAAAA,oBAAoBH,OAAMI,UAAU,CAACL,wBAAuB,MAAO,QAAQI,sBAAsB,KAAK,IAAIA,oBAAoBd;AAC1I;AACO,MAAMH,sCAAsC,IAAI,CAAC,CAACc,OAAMI,UAAU,CAACL"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
const _export_star = require("@swc/helpers/_/_export_star");
|
|
6
|
+
_export_star._(require("./ActiveDescendantContext"), exports);
|
|
6
7
|
_export_star._(require("./useActiveDescendant"), exports);
|
|
7
8
|
_export_star._(require("./constants"), exports);
|
|
8
9
|
_export_star._(require("./types"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.js"],"sourcesContent":["export * from './useActiveDescendant';\nexport * from './constants';\nexport * from './types';\n"],"names":[],"mappings":";;;;;uBAAc;uBACA;uBACA"}
|
|
1
|
+
{"version":3,"sources":["index.js"],"sourcesContent":["export * from './ActiveDescendantContext';\nexport * from './useActiveDescendant';\nexport * from './constants';\nexport * from './types';\n"],"names":[],"mappings":";;;;;uBAAc;uBACA;uBACA;uBACA"}
|
|
@@ -33,7 +33,8 @@ function useActiveDescendant(options) {
|
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
35
|
const matchOption = (0, _reactutilities.useEventCallback)(matchOptionUnstable);
|
|
36
|
-
const
|
|
36
|
+
const listboxRef = _react.useRef(null);
|
|
37
|
+
const { optionWalker, listboxCallbackRef } = (0, _useOptionWalker.useOptionWalker)({
|
|
37
38
|
matchOption
|
|
38
39
|
});
|
|
39
40
|
const getActiveDescendant = _react.useCallback(()=>{
|
|
@@ -128,8 +129,8 @@ function useActiveDescendant(options) {
|
|
|
128
129
|
focusActiveDescendant(target);
|
|
129
130
|
}
|
|
130
131
|
},
|
|
131
|
-
find (predicate, { passive } = {}) {
|
|
132
|
-
const target = optionWalker.find(predicate);
|
|
132
|
+
find (predicate, { passive, startFrom } = {}) {
|
|
133
|
+
const target = optionWalker.find(predicate, startFrom);
|
|
133
134
|
if (!passive) {
|
|
134
135
|
focusActiveDescendant(target);
|
|
135
136
|
}
|
|
@@ -144,7 +145,7 @@ function useActiveDescendant(options) {
|
|
|
144
145
|
]);
|
|
145
146
|
_react.useImperativeHandle(imperativeRef, ()=>controller);
|
|
146
147
|
return {
|
|
147
|
-
listboxRef,
|
|
148
|
+
listboxRef: (0, _reactutilities.useMergedRefs)(listboxRef, listboxCallbackRef),
|
|
148
149
|
activeParentRef,
|
|
149
150
|
controller
|
|
150
151
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useActiveDescendant.js"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from '@fluentui/react-utilities';\nimport { useOnKeyboardNavigationChange } from '@fluentui/react-tabster';\nimport { useOptionWalker } from './useOptionWalker';\nimport { ACTIVEDESCENDANT_ATTRIBUTE, ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE } from './constants';\nimport { scrollIntoView } from './scrollIntoView';\nexport function useActiveDescendant(options) {\n const { imperativeRef, matchOption: matchOptionUnstable } = options;\n const focusVisibleRef = React.useRef(false);\n const activeIdRef = React.useRef(null);\n const activeParentRef = React.useRef(null);\n useOnKeyboardNavigationChange((isNavigatingWithKeyboard)=>{\n focusVisibleRef.current = isNavigatingWithKeyboard;\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n if (isNavigatingWithKeyboard) {\n active.setAttribute(ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE, '');\n } else {\n active.removeAttribute(ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE);\n }\n });\n const matchOption = useEventCallback(matchOptionUnstable);\n const { listboxRef, optionWalker } = useOptionWalker({\n matchOption\n });\n const getActiveDescendant = React.useCallback(()=>{\n var _listboxRef_current;\n return (_listboxRef_current = listboxRef.current) === null || _listboxRef_current === void 0 ? void 0 : _listboxRef_current.querySelector(`#${activeIdRef.current}`);\n }, [\n listboxRef\n ]);\n const blurActiveDescendant = React.useCallback(()=>{\n var _activeParentRef_current;\n const active = getActiveDescendant();\n if (active) {\n active.removeAttribute(ACTIVEDESCENDANT_ATTRIBUTE);\n active.removeAttribute(ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE);\n }\n (_activeParentRef_current = activeParentRef.current) === null || _activeParentRef_current === void 0 ? void 0 : _activeParentRef_current.removeAttribute('aria-activedescendant');\n activeIdRef.current = null;\n }, [\n activeParentRef,\n getActiveDescendant\n ]);\n const focusActiveDescendant = React.useCallback((nextActive)=>{\n var _activeParentRef_current;\n if (!nextActive) {\n return;\n }\n blurActiveDescendant();\n scrollIntoView(nextActive, listboxRef.current);\n (_activeParentRef_current = activeParentRef.current) === null || _activeParentRef_current === void 0 ? void 0 : _activeParentRef_current.setAttribute('aria-activedescendant', nextActive.id);\n activeIdRef.current = nextActive.id;\n nextActive.setAttribute(ACTIVEDESCENDANT_ATTRIBUTE, '');\n if (focusVisibleRef.current) {\n nextActive.setAttribute(ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE, '');\n }\n }, [\n activeParentRef,\n listboxRef,\n blurActiveDescendant\n ]);\n const controller = React.useMemo(()=>({\n first: ({ passive } = {})=>{\n const first = optionWalker.first();\n if (!passive) {\n focusActiveDescendant(first);\n }\n return first === null || first === void 0 ? void 0 : first.id;\n },\n last: ({ passive } = {})=>{\n const last = optionWalker.last();\n if (!passive) {\n focusActiveDescendant(last);\n }\n return last === null || last === void 0 ? void 0 : last.id;\n },\n next: ({ passive } = {})=>{\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n optionWalker.setCurrent(active);\n const next = optionWalker.next();\n if (!passive) {\n focusActiveDescendant(next);\n }\n return next === null || next === void 0 ? void 0 : next.id;\n },\n prev: ({ passive } = {})=>{\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n optionWalker.setCurrent(active);\n const next = optionWalker.prev();\n if (!passive) {\n focusActiveDescendant(next);\n }\n return next === null || next === void 0 ? void 0 : next.id;\n },\n blur: ()=>{\n blurActiveDescendant();\n },\n active: ()=>{\n var _getActiveDescendant;\n return (_getActiveDescendant = getActiveDescendant()) === null || _getActiveDescendant === void 0 ? void 0 : _getActiveDescendant.id;\n },\n focus: (id)=>{\n if (!listboxRef.current) {\n return;\n }\n const target = listboxRef.current.querySelector(`#${id}`);\n if (target) {\n focusActiveDescendant(target);\n }\n },\n find (predicate, { passive } = {}) {\n const target = optionWalker.find(predicate);\n if (!passive) {\n focusActiveDescendant(target);\n }\n return target === null || target === void 0 ? void 0 : target.id;\n }\n }), [\n optionWalker,\n listboxRef,\n focusActiveDescendant,\n blurActiveDescendant,\n getActiveDescendant\n ]);\n React.useImperativeHandle(imperativeRef, ()=>controller);\n return {\n listboxRef,\n activeParentRef,\n controller\n };\n}\n"],"names":["useActiveDescendant","options","imperativeRef","matchOption","matchOptionUnstable","focusVisibleRef","React","useRef","activeIdRef","activeParentRef","useOnKeyboardNavigationChange","isNavigatingWithKeyboard","current","active","getActiveDescendant","setAttribute","ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE","removeAttribute","useEventCallback","listboxRef","optionWalker","useOptionWalker","useCallback","_listboxRef_current","querySelector","blurActiveDescendant","_activeParentRef_current","ACTIVEDESCENDANT_ATTRIBUTE","focusActiveDescendant","nextActive","scrollIntoView","id","controller","useMemo","first","passive","last","next","setCurrent","prev","blur","_getActiveDescendant","focus","target","find","predicate","useImperativeHandle"],"mappings":";;;;+BAMgBA;;;eAAAA;;;;iEANO;gCACU;8BACa;iCACd;2BACoD;gCACrD;AACxB,SAASA,oBAAoBC,OAAO;IACvC,MAAM,EAAEC,aAAa,EAAEC,aAAaC,mBAAmB,EAAE,GAAGH;IAC5D,MAAMI,kBAAkBC,OAAMC,MAAM,CAAC;IACrC,MAAMC,cAAcF,OAAMC,MAAM,CAAC;IACjC,MAAME,kBAAkBH,OAAMC,MAAM,CAAC;IACrCG,IAAAA,2CAA6B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BAC1B;gBACA,OAAOA,SAAS,QAAQA,SAAS,KAAK,IAAI,KAAK,IAAIA,KAAKN,EAAE;YAC9D;YACAS,MAAM;gBACFf;YACJ;YACAZ,QAAQ;gBACJ,IAAI4B;gBACJ,OAAO,AAACA,CAAAA,uBAAuB3B,qBAAoB,MAAO,QAAQ2B,yBAAyB,KAAK,IAAI,KAAK,IAAIA,qBAAqBV,EAAE;YACxI;YACAW,OAAO,CAACX;gBACJ,IAAI,CAACZ,WAAWP,OAAO,EAAE;oBACrB;gBACJ;gBACA,MAAM+B,SAASxB,WAAWP,OAAO,CAACY,aAAa,CAAC,CAAC,CAAC,EAAEO,GAAG,CAAC;gBACxD,IAAIY,QAAQ;oBACRf,sBAAsBe;gBAC1B;YACJ;YACAC,MAAMC,SAAS,EAAE,EAAEV,OAAO,EAAE,GAAG,CAAC,CAAC;gBAC7B,MAAMQ,SAASvB,aAAawB,IAAI,CAACC;gBACjC,IAAI,CAACV,SAAS;oBACVP,sBAAsBe;gBAC1B;gBACA,OAAOA,WAAW,QAAQA,WAAW,KAAK,IAAI,KAAK,IAAIA,OAAOZ,EAAE;YACpE;QACJ,CAAA,GAAI;QACJX;QACAD;QACAS;QACAH;QACAX;KACH;IACDR,OAAMwC,mBAAmB,CAAC5C,eAAe,IAAI8B;IAC7C,OAAO;QACHb;QACAV;QACAuB;IACJ;AACJ"}
|
|
1
|
+
{"version":3,"sources":["useActiveDescendant.js"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { useOnKeyboardNavigationChange } from '@fluentui/react-tabster';\nimport { useOptionWalker } from './useOptionWalker';\nimport { ACTIVEDESCENDANT_ATTRIBUTE, ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE } from './constants';\nimport { scrollIntoView } from './scrollIntoView';\nexport function useActiveDescendant(options) {\n const { imperativeRef, matchOption: matchOptionUnstable } = options;\n const focusVisibleRef = React.useRef(false);\n const activeIdRef = React.useRef(null);\n const activeParentRef = React.useRef(null);\n useOnKeyboardNavigationChange((isNavigatingWithKeyboard)=>{\n focusVisibleRef.current = isNavigatingWithKeyboard;\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n if (isNavigatingWithKeyboard) {\n active.setAttribute(ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE, '');\n } else {\n active.removeAttribute(ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE);\n }\n });\n const matchOption = useEventCallback(matchOptionUnstable);\n const listboxRef = React.useRef(null);\n const { optionWalker, listboxCallbackRef } = useOptionWalker({\n matchOption\n });\n const getActiveDescendant = React.useCallback(()=>{\n var _listboxRef_current;\n return (_listboxRef_current = listboxRef.current) === null || _listboxRef_current === void 0 ? void 0 : _listboxRef_current.querySelector(`#${activeIdRef.current}`);\n }, [\n listboxRef\n ]);\n const blurActiveDescendant = React.useCallback(()=>{\n var _activeParentRef_current;\n const active = getActiveDescendant();\n if (active) {\n active.removeAttribute(ACTIVEDESCENDANT_ATTRIBUTE);\n active.removeAttribute(ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE);\n }\n (_activeParentRef_current = activeParentRef.current) === null || _activeParentRef_current === void 0 ? void 0 : _activeParentRef_current.removeAttribute('aria-activedescendant');\n activeIdRef.current = null;\n }, [\n activeParentRef,\n getActiveDescendant\n ]);\n const focusActiveDescendant = React.useCallback((nextActive)=>{\n var _activeParentRef_current;\n if (!nextActive) {\n return;\n }\n blurActiveDescendant();\n scrollIntoView(nextActive, listboxRef.current);\n (_activeParentRef_current = activeParentRef.current) === null || _activeParentRef_current === void 0 ? void 0 : _activeParentRef_current.setAttribute('aria-activedescendant', nextActive.id);\n activeIdRef.current = nextActive.id;\n nextActive.setAttribute(ACTIVEDESCENDANT_ATTRIBUTE, '');\n if (focusVisibleRef.current) {\n nextActive.setAttribute(ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE, '');\n }\n }, [\n activeParentRef,\n listboxRef,\n blurActiveDescendant\n ]);\n const controller = React.useMemo(()=>({\n first: ({ passive } = {})=>{\n const first = optionWalker.first();\n if (!passive) {\n focusActiveDescendant(first);\n }\n return first === null || first === void 0 ? void 0 : first.id;\n },\n last: ({ passive } = {})=>{\n const last = optionWalker.last();\n if (!passive) {\n focusActiveDescendant(last);\n }\n return last === null || last === void 0 ? void 0 : last.id;\n },\n next: ({ passive } = {})=>{\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n optionWalker.setCurrent(active);\n const next = optionWalker.next();\n if (!passive) {\n focusActiveDescendant(next);\n }\n return next === null || next === void 0 ? void 0 : next.id;\n },\n prev: ({ passive } = {})=>{\n const active = getActiveDescendant();\n if (!active) {\n return;\n }\n optionWalker.setCurrent(active);\n const next = optionWalker.prev();\n if (!passive) {\n focusActiveDescendant(next);\n }\n return next === null || next === void 0 ? void 0 : next.id;\n },\n blur: ()=>{\n blurActiveDescendant();\n },\n active: ()=>{\n var _getActiveDescendant;\n return (_getActiveDescendant = getActiveDescendant()) === null || _getActiveDescendant === void 0 ? void 0 : _getActiveDescendant.id;\n },\n focus: (id)=>{\n if (!listboxRef.current) {\n return;\n }\n const target = listboxRef.current.querySelector(`#${id}`);\n if (target) {\n focusActiveDescendant(target);\n }\n },\n find (predicate, { passive, startFrom } = {}) {\n const target = optionWalker.find(predicate, startFrom);\n if (!passive) {\n focusActiveDescendant(target);\n }\n return target === null || target === void 0 ? void 0 : target.id;\n }\n }), [\n optionWalker,\n listboxRef,\n focusActiveDescendant,\n blurActiveDescendant,\n getActiveDescendant\n ]);\n React.useImperativeHandle(imperativeRef, ()=>controller);\n return {\n listboxRef: useMergedRefs(listboxRef, listboxCallbackRef),\n activeParentRef,\n controller\n };\n}\n"],"names":["useActiveDescendant","options","imperativeRef","matchOption","matchOptionUnstable","focusVisibleRef","React","useRef","activeIdRef","activeParentRef","useOnKeyboardNavigationChange","isNavigatingWithKeyboard","current","active","getActiveDescendant","setAttribute","ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE","removeAttribute","useEventCallback","listboxRef","optionWalker","listboxCallbackRef","useOptionWalker","useCallback","_listboxRef_current","querySelector","blurActiveDescendant","_activeParentRef_current","ACTIVEDESCENDANT_ATTRIBUTE","focusActiveDescendant","nextActive","scrollIntoView","id","controller","useMemo","first","passive","last","next","setCurrent","prev","blur","_getActiveDescendant","focus","target","find","predicate","startFrom","useImperativeHandle","useMergedRefs"],"mappings":";;;;+BAMgBA;;;eAAAA;;;;iEANO;gCACyB;8BACF;iCACd;2BACoD;gCACrD;AACxB,SAASA,oBAAoBC,OAAO;IACvC,MAAM,EAAEC,aAAa,EAAEC,aAAaC,mBAAmB,EAAE,GAAGH;IAC5D,MAAMI,kBAAkBC,OAAMC,MAAM,CAAC;IACrC,MAAMC,cAAcF,OAAMC,MAAM,CAAC;IACjC,MAAME,kBAAkBH,OAAMC,MAAM,CAAC;IACrCG,IAAAA,2CAA6B,EAAC,CAACC;QAC3BN,gBAAgBO,OAAO,GAAGD;QAC1B,MAAME,SAASC;QACf,IAAI,CAACD,QAAQ;YACT;QACJ;QACA,IAAIF,0BAA0B;YAC1BE,OAAOE,YAAY,CAACC,kDAAuC,EAAE;QACjE,OAAO;YACHH,OAAOI,eAAe,CAACD,kDAAuC;QAClE;IACJ;IACA,MAAMb,cAAce,IAAAA,gCAAgB,EAACd;IACrC,MAAMe,aAAab,OAAMC,MAAM,CAAC;IAChC,MAAM,EAAEa,YAAY,EAAEC,kBAAkB,EAAE,GAAGC,IAAAA,gCAAe,EAAC;QACzDnB;IACJ;IACA,MAAMW,sBAAsBR,OAAMiB,WAAW,CAAC;QAC1C,IAAIC;QACJ,OAAO,AAACA,CAAAA,sBAAsBL,WAAWP,OAAO,AAAD,MAAO,QAAQY,wBAAwB,KAAK,IAAI,KAAK,IAAIA,oBAAoBC,aAAa,CAAC,CAAC,CAAC,EAAEjB,YAAYI,OAAO,CAAC,CAAC;IACvK,GAAG;QACCO;KACH;IACD,MAAMO,uBAAuBpB,OAAMiB,WAAW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AAsBe;gBAC1B;gBACA,OAAOA,WAAW,QAAQA,WAAW,KAAK,IAAI,KAAK,IAAIA,OAAOZ,EAAE;YACpE;QACJ,CAAA,GAAI;QACJZ;QACAD;QACAU;QACAH;QACAZ;KACH;IACDR,OAAM0C,mBAAmB,CAAC9C,eAAe,IAAI+B;IAC7C,OAAO;QACHd,YAAY8B,IAAAA,6BAAa,EAAC9B,YAAYE;QACtCZ;QACAwB;IACJ;AACJ"}
|
|
@@ -25,11 +25,13 @@ function useOptionWalker(options) {
|
|
|
25
25
|
}, [
|
|
26
26
|
matchOption
|
|
27
27
|
]);
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
|
|
28
|
+
const setListbox = _react.useCallback((el)=>{
|
|
29
|
+
if (el && targetDocument) {
|
|
30
|
+
listboxRef.current = el;
|
|
31
|
+
treeWalkerRef.current = targetDocument.createTreeWalker(el, NodeFilter.SHOW_ELEMENT, optionFilter);
|
|
32
|
+
} else {
|
|
33
|
+
listboxRef.current = null;
|
|
31
34
|
}
|
|
32
|
-
treeWalkerRef.current = targetDocument.createTreeWalker(listboxRef.current, NodeFilter.SHOW_ELEMENT, optionFilter);
|
|
33
35
|
}, [
|
|
34
36
|
targetDocument,
|
|
35
37
|
optionFilter
|
|
@@ -60,11 +62,12 @@ function useOptionWalker(options) {
|
|
|
60
62
|
}
|
|
61
63
|
return treeWalkerRef.current.previousNode();
|
|
62
64
|
},
|
|
63
|
-
find: (predicate)=>{
|
|
65
|
+
find: (predicate, startFrom)=>{
|
|
64
66
|
if (!treeWalkerRef.current || !listboxRef.current) {
|
|
65
67
|
return null;
|
|
66
68
|
}
|
|
67
|
-
|
|
69
|
+
const start = startFrom ? targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.getElementById(startFrom) : null;
|
|
70
|
+
treeWalkerRef.current.currentNode = start !== null && start !== void 0 ? start : listboxRef.current;
|
|
68
71
|
let cur = treeWalkerRef.current.currentNode;
|
|
69
72
|
while(cur && !predicate(cur.id)){
|
|
70
73
|
cur = treeWalkerRef.current.nextNode();
|
|
@@ -77,9 +80,11 @@ function useOptionWalker(options) {
|
|
|
77
80
|
}
|
|
78
81
|
treeWalkerRef.current.currentNode = el;
|
|
79
82
|
}
|
|
80
|
-
}), [
|
|
83
|
+
}), [
|
|
84
|
+
targetDocument
|
|
85
|
+
]);
|
|
81
86
|
return {
|
|
82
87
|
optionWalker,
|
|
83
|
-
|
|
88
|
+
listboxCallbackRef: setListbox
|
|
84
89
|
};
|
|
85
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useOptionWalker.js"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { isHTMLElement
|
|
1
|
+
{"version":3,"sources":["useOptionWalker.js"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { isHTMLElement } from '@fluentui/react-utilities';\nexport function useOptionWalker(options) {\n const { matchOption } = options;\n const { targetDocument } = useFluent();\n const treeWalkerRef = React.useRef(null);\n const listboxRef = React.useRef(null);\n const optionFilter = React.useCallback((node)=>{\n if (isHTMLElement(node) && matchOption(node)) {\n return NodeFilter.FILTER_ACCEPT;\n }\n return NodeFilter.FILTER_SKIP;\n }, [\n matchOption\n ]);\n const setListbox = React.useCallback((el)=>{\n if (el && targetDocument) {\n listboxRef.current = el;\n treeWalkerRef.current = targetDocument.createTreeWalker(el, NodeFilter.SHOW_ELEMENT, optionFilter);\n } else {\n listboxRef.current = null;\n }\n }, [\n targetDocument,\n optionFilter\n ]);\n const optionWalker = React.useMemo(()=>({\n first: ()=>{\n if (!treeWalkerRef.current || !listboxRef.current) {\n return null;\n }\n treeWalkerRef.current.currentNode = listboxRef.current;\n return treeWalkerRef.current.firstChild();\n },\n last: ()=>{\n if (!treeWalkerRef.current || !listboxRef.current) {\n return null;\n }\n return treeWalkerRef.current.lastChild();\n },\n next: ()=>{\n if (!treeWalkerRef.current) {\n return null;\n }\n return treeWalkerRef.current.nextNode();\n },\n prev: ()=>{\n if (!treeWalkerRef.current) {\n return null;\n }\n return treeWalkerRef.current.previousNode();\n },\n find: (predicate, startFrom)=>{\n if (!treeWalkerRef.current || !listboxRef.current) {\n return null;\n }\n const start = startFrom ? targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.getElementById(startFrom) : null;\n treeWalkerRef.current.currentNode = start !== null && start !== void 0 ? start : listboxRef.current;\n let cur = treeWalkerRef.current.currentNode;\n while(cur && !predicate(cur.id)){\n cur = treeWalkerRef.current.nextNode();\n }\n return cur;\n },\n setCurrent: (el)=>{\n if (!treeWalkerRef.current) {\n return;\n }\n treeWalkerRef.current.currentNode = el;\n }\n }), [\n targetDocument\n ]);\n return {\n optionWalker,\n listboxCallbackRef: setListbox\n };\n}\n"],"names":["useOptionWalker","options","matchOption","targetDocument","useFluent","treeWalkerRef","React","useRef","listboxRef","optionFilter","useCallback","node","isHTMLElement","NodeFilter","FILTER_ACCEPT","FILTER_SKIP","setListbox","el","current","createTreeWalker","SHOW_ELEMENT","optionWalker","useMemo","first","currentNode","firstChild","last","lastChild","next","nextNode","prev","previousNode","find","predicate","startFrom","start","getElementById","cur","id","setCurrent","listboxCallbackRef"],"mappings":";;;;+BAGgBA;;;eAAAA;;;;iEAHO;qCACyB;gCAClB;AACvB,SAASA,gBAAgBC,OAAO;IACnC,MAAM,EAAEC,WAAW,EAAE,GAAGD;IACxB,MAAM,EAAEE,cAAc,EAAE,GAAGC,IAAAA,uCAAS;IACpC,MAAMC,gBAAgBC,OAAMC,MAAM,CAAC;IACnC,MAAMC,aAAaF,OAAMC,MAAM,CAAC;IAChC,MAAME,eAAeH,OAAMI,WAAW,CAAC,CAACC;QACpC,IAAIC,IAAAA,6BAAa,EAACD,SAAST,YAAYS,OAAO;YAC1C,OAAOE,WAAWC,aAAa;QACnC;QACA,OAAOD,WAAWE,WAAW;IACjC,GAAG;QACCb;KACH;IACD,MAAMc,aAAaV,OAAMI,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AAIC,EAAE,EAAE;oBAC5BD,MAAMhC,cAAca,OAAO,CAACW,QAAQ;gBACxC;gBACA,OAAOQ;YACX;YACAE,YAAY,CAACtB;gBACT,IAAI,CAACZ,cAAca,OAAO,EAAE;oBACxB;gBACJ;gBACAb,cAAca,OAAO,CAACM,WAAW,GAAGP;YACxC;QACJ,CAAA,GAAI;QACJd;KACH;IACD,OAAO;QACHkB;QACAmB,oBAAoBxB;IACxB;AACJ"}
|
package/lib-commonjs/index.js
CHANGED
|
@@ -21,6 +21,15 @@ _export(exports, {
|
|
|
21
21
|
ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE: function() {
|
|
22
22
|
return _activedescendant.ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE;
|
|
23
23
|
},
|
|
24
|
+
ActiveDescendantContextProvider: function() {
|
|
25
|
+
return _activedescendant.ActiveDescendantContextProvider;
|
|
26
|
+
},
|
|
27
|
+
useActiveDescendantContext: function() {
|
|
28
|
+
return _activedescendant.useActiveDescendantContext;
|
|
29
|
+
},
|
|
30
|
+
useHasParentActiveDescendantContext: function() {
|
|
31
|
+
return _activedescendant.useHasParentActiveDescendantContext;
|
|
32
|
+
},
|
|
24
33
|
AriaLiveAnnouncer: function() {
|
|
25
34
|
return _index1.AriaLiveAnnouncer;
|
|
26
35
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.js"],"sourcesContent":["export { // eslint-disable-next-line deprecation/deprecation\nuseARIAButtonShorthand, useARIAButtonProps } from './button/index';\nexport { useActiveDescendant, ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE } from './activedescendant';\nexport { AriaLiveAnnouncer, renderAriaLiveAnnouncer_unstable, useAriaLiveAnnouncer_unstable, useAriaLiveAnnouncerContextValues_unstable } from './AriaLiveAnnouncer/index';\n"],"names":["useARIAButtonShorthand","useARIAButtonProps","useActiveDescendant","ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE","AriaLiveAnnouncer","renderAriaLiveAnnouncer_unstable","useAriaLiveAnnouncer_unstable","useAriaLiveAnnouncerContextValues_unstable"],"mappings":";;;;;;;;;;;IACAA,sBAAsB;eAAtBA,6BAAsB;;IAAEC,kBAAkB;eAAlBA,yBAAkB;;IACjCC,mBAAmB;eAAnBA,qCAAmB;;IAAEC,uCAAuC;eAAvCA,yDAAuC;;
|
|
1
|
+
{"version":3,"sources":["index.js"],"sourcesContent":["export { // eslint-disable-next-line deprecation/deprecation\nuseARIAButtonShorthand, useARIAButtonProps } from './button/index';\nexport { useActiveDescendant, ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE, ActiveDescendantContextProvider, useActiveDescendantContext, useHasParentActiveDescendantContext } from './activedescendant';\nexport { AriaLiveAnnouncer, renderAriaLiveAnnouncer_unstable, useAriaLiveAnnouncer_unstable, useAriaLiveAnnouncerContextValues_unstable } from './AriaLiveAnnouncer/index';\n"],"names":["useARIAButtonShorthand","useARIAButtonProps","useActiveDescendant","ACTIVEDESCENDANT_FOCUSVISIBLE_ATTRIBUTE","ActiveDescendantContextProvider","useActiveDescendantContext","useHasParentActiveDescendantContext","AriaLiveAnnouncer","renderAriaLiveAnnouncer_unstable","useAriaLiveAnnouncer_unstable","useAriaLiveAnnouncerContextValues_unstable"],"mappings":";;;;;;;;;;;IACAA,sBAAsB;eAAtBA,6BAAsB;;IAAEC,kBAAkB;eAAlBA,yBAAkB;;IACjCC,mBAAmB;eAAnBA,qCAAmB;;IAAEC,uCAAuC;eAAvCA,yDAAuC;;IAAEC,+BAA+B;eAA/BA,iDAA+B;;IAAEC,0BAA0B;eAA1BA,4CAA0B;;IAAEC,mCAAmC;eAAnCA,qDAAmC;;IAC9JC,iBAAiB;eAAjBA,yBAAiB;;IAAEC,gCAAgC;eAAhCA,wCAAgC;;IAAEC,6BAA6B;eAA7BA,qCAA6B;;IAAEC,0CAA0C;eAA1CA,kDAA0C;;;uBAFrF;kCAC6H;wBAChC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui/react-aria",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.9.0",
|
|
4
4
|
"description": "React helper to ensure ARIA",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@fluentui/keyboard-keys": "^9.0.7",
|
|
37
37
|
"@fluentui/react-shared-contexts": "^9.14.0",
|
|
38
|
-
"@fluentui/react-jsx-runtime": "^9.0.
|
|
39
|
-
"@fluentui/react-tabster": "^9.19.
|
|
40
|
-
"@fluentui/react-utilities": "^9.18.
|
|
38
|
+
"@fluentui/react-jsx-runtime": "^9.0.30",
|
|
39
|
+
"@fluentui/react-tabster": "^9.19.1",
|
|
40
|
+
"@fluentui/react-utilities": "^9.18.1",
|
|
41
41
|
"@swc/helpers": "^0.5.1"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|