@fluentui/react-tabster 9.7.4 → 9.8.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.json +77 -1
- package/CHANGELOG.md +29 -2
- package/dist/index.d.ts +3 -3
- package/lib/focus/constants.js +4 -7
- package/lib/focus/constants.js.map +1 -1
- package/lib/focus/createCustomFocusIndicatorStyle.js +9 -13
- package/lib/focus/createCustomFocusIndicatorStyle.js.map +1 -1
- package/lib/focus/createFocusOutlineStyle.js +49 -52
- package/lib/focus/createFocusOutlineStyle.js.map +1 -1
- package/lib/focus/focusVisiblePolyfill.js +56 -58
- package/lib/focus/focusVisiblePolyfill.js.map +1 -1
- package/lib/focus/focusWithinPolyfill.js +36 -38
- package/lib/focus/focusWithinPolyfill.js.map +1 -1
- package/lib/focus/index.js +0 -1
- package/lib/focus/index.js.map +1 -1
- package/lib/hooks/index.js +0 -1
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useArrowNavigationGroup.js +34 -41
- package/lib/hooks/useArrowNavigationGroup.js.map +1 -1
- package/lib/hooks/useFocusFinders.js +59 -55
- package/lib/hooks/useFocusFinders.js.map +1 -1
- package/lib/hooks/useFocusVisible.js +13 -11
- package/lib/hooks/useFocusVisible.js.map +1 -1
- package/lib/hooks/useFocusWithin.js +12 -13
- package/lib/hooks/useFocusWithin.js.map +1 -1
- package/lib/hooks/useFocusableGroup.js +20 -22
- package/lib/hooks/useFocusableGroup.js.map +1 -1
- package/lib/hooks/useKeyboardNavAttribute.js +27 -27
- package/lib/hooks/useKeyboardNavAttribute.js.map +1 -1
- package/lib/hooks/useModalAttributes.js +24 -30
- package/lib/hooks/useModalAttributes.js.map +1 -1
- package/lib/hooks/useTabster.js +24 -24
- package/lib/hooks/useTabster.js.map +1 -1
- package/lib/hooks/useTabsterAttributes.js +5 -7
- package/lib/hooks/useTabsterAttributes.js.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib-commonjs/focus/constants.js +1 -3
- package/lib-commonjs/focus/constants.js.map +1 -1
- package/lib-commonjs/focus/createCustomFocusIndicatorStyle.js +1 -3
- package/lib-commonjs/focus/createCustomFocusIndicatorStyle.js.map +1 -1
- package/lib-commonjs/focus/createFocusOutlineStyle.js +19 -12
- package/lib-commonjs/focus/createFocusOutlineStyle.js.map +1 -1
- package/lib-commonjs/focus/focusVisiblePolyfill.js +1 -3
- package/lib-commonjs/focus/focusVisiblePolyfill.js.map +1 -1
- package/lib-commonjs/focus/focusWithinPolyfill.js +1 -3
- package/lib-commonjs/focus/focusWithinPolyfill.js.map +1 -1
- package/lib-commonjs/focus/index.js +0 -3
- package/lib-commonjs/focus/index.js.map +1 -1
- package/lib-commonjs/hooks/index.js +0 -3
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useArrowNavigationGroup.js +4 -5
- package/lib-commonjs/hooks/useArrowNavigationGroup.js.map +1 -1
- package/lib-commonjs/hooks/useFocusFinders.js +1 -3
- package/lib-commonjs/hooks/useFocusFinders.js.map +1 -1
- package/lib-commonjs/hooks/useFocusVisible.js +1 -3
- package/lib-commonjs/hooks/useFocusVisible.js.map +1 -1
- package/lib-commonjs/hooks/useFocusWithin.js +1 -3
- package/lib-commonjs/hooks/useFocusWithin.js.map +1 -1
- package/lib-commonjs/hooks/useFocusableGroup.js +1 -3
- package/lib-commonjs/hooks/useFocusableGroup.js.map +1 -1
- package/lib-commonjs/hooks/useKeyboardNavAttribute.js +1 -3
- package/lib-commonjs/hooks/useKeyboardNavAttribute.js.map +1 -1
- package/lib-commonjs/hooks/useModalAttributes.js +1 -3
- package/lib-commonjs/hooks/useModalAttributes.js.map +1 -1
- package/lib-commonjs/hooks/useTabster.js +1 -3
- package/lib-commonjs/hooks/useTabster.js.map +1 -1
- package/lib-commonjs/hooks/useTabsterAttributes.js +1 -3
- package/lib-commonjs/hooks/useTabsterAttributes.js.map +1 -1
- package/lib-commonjs/index.js +0 -3
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +6 -6
@@ -4,48 +4,46 @@ import { FOCUS_WITHIN_ATTR } from './constants';
|
|
4
4
|
* A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation
|
5
5
|
* like `:focus-visible` https://github.com/WICG/focus-visible/issues/151
|
6
6
|
* @returns ref to the element that uses `:focus-within` styles
|
7
|
-
*/
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
}
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
};
|
7
|
+
*/ export function applyFocusWithinPolyfill(element, win) {
|
8
|
+
const keyborg = createKeyborg(win);
|
9
|
+
// When navigation mode changes to mouse, remove the focus-within selector
|
10
|
+
keyborg.subscribe((isNavigatingWithKeyboard)=>{
|
11
|
+
if (!isNavigatingWithKeyboard) {
|
12
|
+
removeFocusWithinClass(element);
|
13
|
+
}
|
14
|
+
});
|
15
|
+
// Keyborg's focusin event is delegated so it's only registered once on the window
|
16
|
+
// and contains metadata about the focus event
|
17
|
+
const keyborgListener = (e)=>{
|
18
|
+
if (keyborg.isNavigatingWithKeyboard() && isHTMLElement(e.target)) {
|
19
|
+
// Griffel can't create chained global styles so use the parent element for now
|
20
|
+
applyFocusWithinClass(element);
|
21
|
+
}
|
22
|
+
};
|
23
|
+
// Make sure that when focus leaves the scope, the focus within class is removed
|
24
|
+
const blurListener = (e)=>{
|
25
|
+
if (!e.relatedTarget || isHTMLElement(e.relatedTarget) && !element.contains(e.relatedTarget)) {
|
26
|
+
removeFocusWithinClass(element);
|
27
|
+
}
|
28
|
+
};
|
29
|
+
element.addEventListener(KEYBORG_FOCUSIN, keyborgListener);
|
30
|
+
element.addEventListener('focusout', blurListener);
|
31
|
+
// Return disposer
|
32
|
+
return ()=>{
|
33
|
+
element.removeEventListener(KEYBORG_FOCUSIN, keyborgListener);
|
34
|
+
element.removeEventListener('focusout', blurListener);
|
35
|
+
disposeKeyborg(keyborg);
|
36
|
+
};
|
38
37
|
}
|
39
38
|
function applyFocusWithinClass(el) {
|
40
|
-
|
39
|
+
el.setAttribute(FOCUS_WITHIN_ATTR, '');
|
41
40
|
}
|
42
41
|
function removeFocusWithinClass(el) {
|
43
|
-
|
42
|
+
el.removeAttribute(FOCUS_WITHIN_ATTR);
|
44
43
|
}
|
45
44
|
function isHTMLElement(target) {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
if (!target) {
|
46
|
+
return false;
|
47
|
+
}
|
48
|
+
return Boolean(target && typeof target === 'object' && 'classList' in target && 'contains' in target);
|
50
49
|
}
|
51
|
-
//# sourceMappingURL=focusWithinPolyfill.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["focusWithinPolyfill.ts"],"sourcesContent":["import { KEYBORG_FOCUSIN, KeyborgFocusInEvent, createKeyborg, disposeKeyborg } from 'keyborg';\nimport { FOCUS_WITHIN_ATTR } from './constants';\n\n/**\n * Because `addEventListener` type override falls back to 2nd definition (evt name is unknown string literal)\n * evt is being typed as a base class of MouseEvent -> `Event`.\n * This type is used to override `listener` calls to make TS happy\n */\ntype ListenerOverride = (evt: Event) => void;\n\n/**\n * A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation\n * like `:focus-visible` https://github.com/WICG/focus-visible/issues/151\n * @returns ref to the element that uses `:focus-within` styles\n */\nexport function applyFocusWithinPolyfill(element: HTMLElement, win: Window): () => void {\n const keyborg = createKeyborg(win);\n\n // When navigation mode changes to mouse, remove the focus-within selector\n keyborg.subscribe(isNavigatingWithKeyboard => {\n if (!isNavigatingWithKeyboard) {\n removeFocusWithinClass(element);\n }\n });\n\n // Keyborg's focusin event is delegated so it's only registered once on the window\n // and contains metadata about the focus event\n const keyborgListener = (e: KeyborgFocusInEvent) => {\n if (keyborg.isNavigatingWithKeyboard() && isHTMLElement(e.target)) {\n // Griffel can't create chained global styles so use the parent element for now\n applyFocusWithinClass(element);\n }\n };\n\n // Make sure that when focus leaves the scope, the focus within class is removed\n const blurListener = (e: FocusEvent) => {\n if (!e.relatedTarget || (isHTMLElement(e.relatedTarget) && !element.contains(e.relatedTarget))) {\n removeFocusWithinClass(element);\n }\n };\n\n element.addEventListener(KEYBORG_FOCUSIN, keyborgListener as ListenerOverride);\n element.addEventListener('focusout', blurListener);\n\n // Return disposer\n return () => {\n element.removeEventListener(KEYBORG_FOCUSIN, keyborgListener as ListenerOverride);\n element.removeEventListener('focusout', blurListener);\n disposeKeyborg(keyborg);\n };\n}\n\nfunction applyFocusWithinClass(el: HTMLElement) {\n el.setAttribute(FOCUS_WITHIN_ATTR, '');\n}\n\nfunction removeFocusWithinClass(el: HTMLElement) {\n el.removeAttribute(FOCUS_WITHIN_ATTR);\n}\n\nfunction isHTMLElement(target: EventTarget | null): target is HTMLElement {\n if (!target) {\n return false;\n }\n return Boolean(target && typeof target === 'object' && 'classList' in target && 'contains' in target);\n}\n"],"names":["KEYBORG_FOCUSIN","createKeyborg","disposeKeyborg","FOCUS_WITHIN_ATTR","applyFocusWithinPolyfill","element","win","keyborg","subscribe","isNavigatingWithKeyboard","removeFocusWithinClass","keyborgListener","e","isHTMLElement","target","applyFocusWithinClass","blurListener","relatedTarget","contains","addEventListener","removeEventListener","el","setAttribute","removeAttribute","Boolean"],"mappings":"AAAA,SAASA,eAAe,EAAuBC,aAAa,EAAEC,cAAc,QAAQ,UAAU;AAC9F,SAASC,iBAAiB,QAAQ,cAAc;AAShD;;;;CAIC,GACD,OAAO,SAASC,yBAAyBC,OAAoB,EAAEC,GAAW,EAAc;IACtF,MAAMC,UAAUN,cAAcK;IAE9B,0EAA0E;IAC1EC,QAAQC,SAAS,CAACC,CAAAA,2BAA4B;QAC5C,IAAI,CAACA,0BAA0B;YAC7BC,uBAAuBL;QACzB,CAAC;IACH;IAEA,kFAAkF;IAClF,8CAA8C;IAC9C,MAAMM,kBAAkB,CAACC,IAA2B;QAClD,IAAIL,QAAQE,wBAAwB,MAAMI,cAAcD,EAAEE,MAAM,GAAG;YACjE,+EAA+E;YAC/EC,sBAAsBV;QACxB,CAAC;IACH;IAEA,gFAAgF;IAChF,MAAMW,eAAe,CAACJ,IAAkB;QACtC,IAAI,CAACA,EAAEK,aAAa,IAAKJ,cAAcD,EAAEK,aAAa,KAAK,CAACZ,QAAQa,QAAQ,CAACN,EAAEK,aAAa,GAAI;YAC9FP,uBAAuBL;QACzB,CAAC;IACH;IAEAA,QAAQc,gBAAgB,CAACnB,iBAAiBW;IAC1CN,QAAQc,gBAAgB,CAAC,YAAYH;IAErC,kBAAkB;IAClB,OAAO,IAAM;QACXX,QAAQe,mBAAmB,CAACpB,iBAAiBW;QAC7CN,QAAQe,mBAAmB,CAAC,YAAYJ;QACxCd,eAAeK;IACjB;AACF,CAAC;AAED,SAASQ,sBAAsBM,EAAe,EAAE;IAC9CA,GAAGC,YAAY,CAACnB,mBAAmB;AACrC;AAEA,SAASO,uBAAuBW,EAAe,EAAE;IAC/CA,GAAGE,eAAe,CAACpB;AACrB;AAEA,SAASU,cAAcC,MAA0B,EAAyB;IACxE,IAAI,CAACA,QAAQ;QACX,OAAO,KAAK;IACd,CAAC;IACD,OAAOU,QAAQV,UAAU,OAAOA,WAAW,YAAY,eAAeA,UAAU,cAAcA;AAChG"}
|
package/lib/focus/index.js
CHANGED
package/lib/focus/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export * from './createCustomFocusIndicatorStyle';\nexport * from './createFocusOutlineStyle';\nexport * from './focusVisiblePolyfill';\nexport * from './focusWithinPolyfill';\n"],"names":[],"mappings":"AAAA,cAAc,oCAAoC;AAClD,cAAc,4BAA4B;AAC1C,cAAc,yBAAyB;AACvC,cAAc,wBAAwB"}
|
package/lib/hooks/index.js
CHANGED
package/lib/hooks/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export * from './useArrowNavigationGroup';\nexport * from './useFocusableGroup';\nexport * from './useFocusFinders';\nexport * from './useFocusVisible';\nexport * from './useFocusWithin';\nexport * from './useKeyboardNavAttribute';\nexport * from './useModalAttributes';\nexport * from './useTabsterAttributes';\n"],"names":[],"mappings":"AAAA,cAAc,4BAA4B;AAC1C,cAAc,sBAAsB;AACpC,cAAc,oBAAoB;AAClC,cAAc,oBAAoB;AAClC,cAAc,mBAAmB;AACjC,cAAc,4BAA4B;AAC1C,cAAc,uBAAuB;AACrC,cAAc,yBAAyB"}
|
@@ -4,47 +4,40 @@ import { useTabster } from './useTabster';
|
|
4
4
|
/**
|
5
5
|
* A hook that returns the necessary tabster attributes to support arrow key navigation
|
6
6
|
* @param options - Options to configure keyboard navigation
|
7
|
-
*/
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
hasDefault: unstable_hasDefault
|
29
|
-
},
|
30
|
-
...(ignoreDefaultKeydown && {
|
31
|
-
focusable: {
|
32
|
-
ignoreKeydown: ignoreDefaultKeydown
|
33
|
-
}
|
34
|
-
})
|
35
|
-
});
|
7
|
+
*/ export const useArrowNavigationGroup = (options = {})=>{
|
8
|
+
const { circular , axis , memorizeCurrent , tabbable , ignoreDefaultKeydown , // eslint-disable-next-line @typescript-eslint/naming-convention
|
9
|
+
unstable_hasDefault } = options;
|
10
|
+
const tabster = useTabster();
|
11
|
+
if (tabster) {
|
12
|
+
getMover(tabster);
|
13
|
+
}
|
14
|
+
return useTabsterAttributes({
|
15
|
+
mover: {
|
16
|
+
cyclic: !!circular,
|
17
|
+
direction: axisToMoverDirection(axis !== null && axis !== void 0 ? axis : 'vertical'),
|
18
|
+
memorizeCurrent,
|
19
|
+
tabbable,
|
20
|
+
hasDefault: unstable_hasDefault
|
21
|
+
},
|
22
|
+
...ignoreDefaultKeydown && {
|
23
|
+
focusable: {
|
24
|
+
ignoreKeydown: ignoreDefaultKeydown
|
25
|
+
}
|
26
|
+
}
|
27
|
+
});
|
36
28
|
};
|
37
29
|
function axisToMoverDirection(axis) {
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
30
|
+
switch(axis){
|
31
|
+
case 'horizontal':
|
32
|
+
return Types.MoverDirections.Horizontal;
|
33
|
+
case 'grid':
|
34
|
+
return Types.MoverDirections.Grid;
|
35
|
+
case 'grid-linear':
|
36
|
+
return Types.MoverDirections.GridLinear;
|
37
|
+
case 'both':
|
38
|
+
return Types.MoverDirections.Both;
|
39
|
+
case 'vertical':
|
40
|
+
default:
|
41
|
+
return Types.MoverDirections.Vertical;
|
42
|
+
}
|
49
43
|
}
|
50
|
-
//# sourceMappingURL=useArrowNavigationGroup.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["useArrowNavigationGroup.ts"],"sourcesContent":["import { Types, getMover } from 'tabster';\nimport { useTabsterAttributes } from './useTabsterAttributes';\nimport { useTabster } from './useTabster';\n\nexport interface UseArrowNavigationGroupOptions {\n /**\n * Focus will navigate vertically, horizontally or in both directions (grid), defaults to horizontally\n * @defaultValue vertical\n */\n axis?: 'vertical' | 'horizontal' | 'grid' | 'grid-linear' | 'both';\n /**\n * Focus will cycle to the first/last elements of the group without stopping\n */\n circular?: boolean;\n /**\n * Last focused element in the group will be remembered and focused (if still\n * available) when tabbing from outside of the group\n */\n memorizeCurrent?: boolean;\n /**\n * Allow tabbing within the arrow navigation group items.\n */\n tabbable?: boolean;\n /**\n * Tabster should ignore default handling of keydown events\n */\n ignoreDefaultKeydown?: Types.FocusableProps['ignoreKeydown'];\n /**\n * The default focusable item in the group will be an element with Focusable.isDefault property.\n * Note that there is no way in \\@fluentui/react-tabster to set default focusable element,\n * and this option is currently for internal testing purposes only.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_hasDefault?: boolean;\n}\n\n/**\n * A hook that returns the necessary tabster attributes to support arrow key navigation\n * @param options - Options to configure keyboard navigation\n */\nexport const useArrowNavigationGroup = (options: UseArrowNavigationGroupOptions = {}): Types.TabsterDOMAttribute => {\n const {\n circular,\n axis,\n memorizeCurrent,\n tabbable,\n ignoreDefaultKeydown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_hasDefault,\n } = options;\n const tabster = useTabster();\n\n if (tabster) {\n getMover(tabster);\n }\n\n return useTabsterAttributes({\n mover: {\n cyclic: !!circular,\n direction: axisToMoverDirection(axis ?? 'vertical'),\n memorizeCurrent,\n tabbable,\n hasDefault: unstable_hasDefault,\n },\n ...(ignoreDefaultKeydown && {\n focusable: {\n ignoreKeydown: ignoreDefaultKeydown,\n },\n }),\n });\n};\n\nfunction axisToMoverDirection(axis: UseArrowNavigationGroupOptions['axis']): Types.MoverDirection {\n switch (axis) {\n case 'horizontal':\n return Types.MoverDirections.Horizontal;\n case 'grid':\n return Types.MoverDirections.Grid;\n case 'grid-linear':\n return Types.MoverDirections.GridLinear;\n case 'both':\n return Types.MoverDirections.Both;\n\n case 'vertical':\n default:\n return Types.MoverDirections.Vertical;\n }\n}\n"],"names":["Types","getMover","useTabsterAttributes","useTabster","useArrowNavigationGroup","options","circular","axis","memorizeCurrent","tabbable","ignoreDefaultKeydown","unstable_hasDefault","tabster","mover","cyclic","direction","axisToMoverDirection","hasDefault","focusable","ignoreKeydown","MoverDirections","Horizontal","Grid","GridLinear","Both","Vertical"],"mappings":"AAAA,SAASA,KAAK,EAAEC,QAAQ,QAAQ,UAAU;AAC1C,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,UAAU,QAAQ,eAAe;AAkC1C;;;CAGC,GACD,OAAO,MAAMC,0BAA0B,CAACC,UAA0C,CAAC,CAAC,GAAgC;IAClH,MAAM,EACJC,SAAQ,EACRC,KAAI,EACJC,gBAAe,EACfC,SAAQ,EACRC,qBAAoB,EACpB,gEAAgE;IAChEC,oBAAmB,EACpB,GAAGN;IACJ,MAAMO,UAAUT;IAEhB,IAAIS,SAAS;QACXX,SAASW;IACX,CAAC;IAED,OAAOV,qBAAqB;QAC1BW,OAAO;YACLC,QAAQ,CAAC,CAACR;YACVS,WAAWC,qBAAqBT,iBAAAA,kBAAAA,OAAQ,UAAU;YAClDC;YACAC;YACAQ,YAAYN;QACd;QACA,GAAID,wBAAwB;YAC1BQ,WAAW;gBACTC,eAAeT;YACjB;QACF,CAAC;IACH;AACF,EAAE;AAEF,SAASM,qBAAqBT,IAA4C,EAAwB;IAChG,OAAQA;QACN,KAAK;YACH,OAAOP,MAAMoB,eAAe,CAACC,UAAU;QACzC,KAAK;YACH,OAAOrB,MAAMoB,eAAe,CAACE,IAAI;QACnC,KAAK;YACH,OAAOtB,MAAMoB,eAAe,CAACG,UAAU;QACzC,KAAK;YACH,OAAOvB,MAAMoB,eAAe,CAACI,IAAI;QAEnC,KAAK;QACL;YACE,OAAOxB,MAAMoB,eAAe,CAACK,QAAQ;IACzC;AACF"}
|
@@ -3,59 +3,63 @@ import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts
|
|
3
3
|
import { useTabster } from './useTabster';
|
4
4
|
/**
|
5
5
|
* Returns a set of helper functions that will traverse focusable elements in the context of a root DOM element
|
6
|
-
*/
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
}
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
}
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
const {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
6
|
+
*/ export const useFocusFinders = ()=>{
|
7
|
+
const tabster = useTabster();
|
8
|
+
const { targetDocument } = useFluent();
|
9
|
+
// Narrow props for now and let need dictate additional props in the future
|
10
|
+
const findAllFocusable = React.useCallback((container, acceptCondition)=>{
|
11
|
+
return (tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findAll({
|
12
|
+
container,
|
13
|
+
acceptCondition
|
14
|
+
})) || [];
|
15
|
+
}, [
|
16
|
+
tabster
|
17
|
+
]);
|
18
|
+
const findFirstFocusable = React.useCallback((container)=>{
|
19
|
+
return tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findFirst({
|
20
|
+
container
|
21
|
+
});
|
22
|
+
}, [
|
23
|
+
tabster
|
24
|
+
]);
|
25
|
+
const findLastFocusable = React.useCallback((container)=>{
|
26
|
+
return tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findLast({
|
27
|
+
container
|
28
|
+
});
|
29
|
+
}, [
|
30
|
+
tabster
|
31
|
+
]);
|
32
|
+
const findNextFocusable = React.useCallback((currentElement, options = {})=>{
|
33
|
+
if (!tabster || !targetDocument) {
|
34
|
+
return null;
|
35
|
+
}
|
36
|
+
const { container =targetDocument.body } = options;
|
37
|
+
return tabster.focusable.findNext({
|
38
|
+
currentElement,
|
39
|
+
container
|
40
|
+
});
|
41
|
+
}, [
|
42
|
+
tabster,
|
43
|
+
targetDocument
|
44
|
+
]);
|
45
|
+
const findPrevFocusable = React.useCallback((currentElement, options = {})=>{
|
46
|
+
if (!tabster || !targetDocument) {
|
47
|
+
return null;
|
48
|
+
}
|
49
|
+
const { container =targetDocument.body } = options;
|
50
|
+
return tabster.focusable.findPrev({
|
51
|
+
currentElement,
|
52
|
+
container
|
53
|
+
});
|
54
|
+
}, [
|
55
|
+
tabster,
|
56
|
+
targetDocument
|
57
|
+
]);
|
58
|
+
return {
|
59
|
+
findAllFocusable,
|
60
|
+
findFirstFocusable,
|
61
|
+
findLastFocusable,
|
62
|
+
findNextFocusable,
|
63
|
+
findPrevFocusable
|
64
|
+
};
|
60
65
|
};
|
61
|
-
//# sourceMappingURL=useFocusFinders.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["useFocusFinders.ts"],"sourcesContent":["import * as React from 'react';\nimport { Types as TabsterTypes } from 'tabster';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useTabster } from './useTabster';\n\n/**\n * Returns a set of helper functions that will traverse focusable elements in the context of a root DOM element\n */\nexport const useFocusFinders = () => {\n const tabster = useTabster();\n const { targetDocument } = useFluent();\n\n // Narrow props for now and let need dictate additional props in the future\n const findAllFocusable = React.useCallback(\n (container: HTMLElement, acceptCondition?: (el: HTMLElement) => boolean) =>\n tabster?.focusable.findAll({ container, acceptCondition }) || [],\n [tabster],\n );\n\n const findFirstFocusable = React.useCallback(\n (container: HTMLElement) => tabster?.focusable.findFirst({ container }),\n [tabster],\n );\n\n const findLastFocusable = React.useCallback(\n (container: HTMLElement) => tabster?.focusable.findLast({ container }),\n [tabster],\n );\n\n const findNextFocusable = React.useCallback(\n (currentElement: HTMLElement, options: Pick<Partial<TabsterTypes.FindNextProps>, 'container'> = {}) => {\n if (!tabster || !targetDocument) {\n return null;\n }\n\n const { container = targetDocument.body } = options;\n\n return tabster.focusable.findNext({ currentElement, container });\n },\n [tabster, targetDocument],\n );\n\n const findPrevFocusable = React.useCallback(\n (currentElement: HTMLElement, options: Pick<Partial<TabsterTypes.FindNextProps>, 'container'> = {}) => {\n if (!tabster || !targetDocument) {\n return null;\n }\n\n const { container = targetDocument.body } = options;\n\n return tabster.focusable.findPrev({ currentElement, container });\n },\n [tabster, targetDocument],\n );\n\n return {\n findAllFocusable,\n findFirstFocusable,\n findLastFocusable,\n findNextFocusable,\n findPrevFocusable,\n };\n};\n"],"names":["React","useFluent_unstable","useFluent","useTabster","useFocusFinders","tabster","targetDocument","findAllFocusable","useCallback","container","acceptCondition","focusable","findAll","findFirstFocusable","findFirst","findLastFocusable","findLast","findNextFocusable","currentElement","options","body","findNext","findPrevFocusable","findPrev"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,UAAU,QAAQ,eAAe;AAE1C;;CAEC,GACD,OAAO,MAAMC,kBAAkB,IAAM;IACnC,MAAMC,UAAUF;IAChB,MAAM,EAAEG,eAAc,EAAE,GAAGJ;IAE3B,2EAA2E;IAC3E,MAAMK,mBAAmBP,MAAMQ,WAAW,CACxC,CAACC,WAAwBC;QACvBL,OAAAA,CAAAA,oBAAAA,qBAAAA,KAAAA,IAAAA,QAASM,SAAS,CAACC,OAAO,CAAC;YAAEH;YAAWC;QAAgB,EAAE,AAAD,KAAK,EAAE;OAClE;QAACL;KAAQ;IAGX,MAAMQ,qBAAqBb,MAAMQ,WAAW,CAC1C,CAACC;QAA2BJ,OAAAA,oBAAAA,qBAAAA,KAAAA,IAAAA,QAASM,SAAS,CAACG,SAAS,CAAC;YAAEL;QAAU,EAAE;OACvE;QAACJ;KAAQ;IAGX,MAAMU,oBAAoBf,MAAMQ,WAAW,CACzC,CAACC;QAA2BJ,OAAAA,oBAAAA,qBAAAA,KAAAA,IAAAA,QAASM,SAAS,CAACK,QAAQ,CAAC;YAAEP;QAAU,EAAE;OACtE;QAACJ;KAAQ;IAGX,MAAMY,oBAAoBjB,MAAMQ,WAAW,CACzC,CAACU,gBAA6BC,UAAkE,CAAC,CAAC,GAAK;QACrG,IAAI,CAACd,WAAW,CAACC,gBAAgB;YAC/B,OAAO,IAAI;QACb,CAAC;QAED,MAAM,EAAEG,WAAYH,eAAec,IAAI,CAAA,EAAE,GAAGD;QAE5C,OAAOd,QAAQM,SAAS,CAACU,QAAQ,CAAC;YAAEH;YAAgBT;QAAU;IAChE,GACA;QAACJ;QAASC;KAAe;IAG3B,MAAMgB,oBAAoBtB,MAAMQ,WAAW,CACzC,CAACU,gBAA6BC,UAAkE,CAAC,CAAC,GAAK;QACrG,IAAI,CAACd,WAAW,CAACC,gBAAgB;YAC/B,OAAO,IAAI;QACb,CAAC;QAED,MAAM,EAAEG,WAAYH,eAAec,IAAI,CAAA,EAAE,GAAGD;QAE5C,OAAOd,QAAQM,SAAS,CAACY,QAAQ,CAAC;YAAEL;YAAgBT;QAAU;IAChE,GACA;QAACJ;QAASC;KAAe;IAG3B,OAAO;QACLC;QACAM;QACAE;QACAE;QACAK;IACF;AACF,EAAE"}
|
@@ -2,15 +2,17 @@ import * as React from 'react';
|
|
2
2
|
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
3
3
|
import { applyFocusVisiblePolyfill } from '../focus/focusVisiblePolyfill';
|
4
4
|
export function useFocusVisible(options = {}) {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
const contentValue = useFluent();
|
6
|
+
const scopeRef = React.useRef(null);
|
7
|
+
var _options_targetDocument;
|
8
|
+
const targetDocument = (_options_targetDocument = options.targetDocument) !== null && _options_targetDocument !== void 0 ? _options_targetDocument : contentValue.targetDocument;
|
9
|
+
React.useEffect(()=>{
|
10
|
+
if ((targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) && scopeRef.current) {
|
11
|
+
return applyFocusVisiblePolyfill(scopeRef.current, targetDocument.defaultView);
|
12
|
+
}
|
13
|
+
}, [
|
14
|
+
scopeRef,
|
15
|
+
targetDocument
|
16
|
+
]);
|
17
|
+
return scopeRef;
|
15
18
|
}
|
16
|
-
//# sourceMappingURL=useFocusVisible.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["useFocusVisible.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nimport { applyFocusVisiblePolyfill } from '../focus/focusVisiblePolyfill';\n\ntype UseFocusVisibleOptions = {\n targetDocument?: Document;\n};\n\nexport function useFocusVisible<TElement extends HTMLElement = HTMLElement>(options: UseFocusVisibleOptions = {}) {\n const contentValue = useFluent();\n const scopeRef = React.useRef<TElement>(null);\n\n const targetDocument = options.targetDocument ?? contentValue.targetDocument;\n\n React.useEffect(() => {\n if (targetDocument?.defaultView && scopeRef.current) {\n return applyFocusVisiblePolyfill(scopeRef.current, targetDocument.defaultView);\n }\n }, [scopeRef, targetDocument]);\n\n return scopeRef;\n}\n"],"names":["React","useFluent_unstable","useFluent","applyFocusVisiblePolyfill","useFocusVisible","options","contentValue","scopeRef","useRef","targetDocument","useEffect","defaultView","current"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAElF,SAASC,yBAAyB,QAAQ,gCAAgC;AAM1E,OAAO,SAASC,gBAA4DC,UAAkC,CAAC,CAAC,EAAE;IAChH,MAAMC,eAAeJ;IACrB,MAAMK,WAAWP,MAAMQ,MAAM,CAAW,IAAI;QAErBH;IAAvB,MAAMI,iBAAiBJ,CAAAA,0BAAAA,QAAQI,cAAc,cAAtBJ,qCAAAA,0BAA0BC,aAAaG,cAAc;IAE5ET,MAAMU,SAAS,CAAC,IAAM;QACpB,IAAID,CAAAA,2BAAAA,4BAAAA,KAAAA,IAAAA,eAAgBE,WAAW,AAAD,KAAKJ,SAASK,OAAO,EAAE;YACnD,OAAOT,0BAA0BI,SAASK,OAAO,EAAEH,eAAeE,WAAW;QAC/E,CAAC;IACH,GAAG;QAACJ;QAAUE;KAAe;IAE7B,OAAOF;AACT,CAAC"}
|
@@ -5,17 +5,16 @@ import { applyFocusWithinPolyfill } from '../focus/focusWithinPolyfill';
|
|
5
5
|
* A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation
|
6
6
|
* like `:focus-visible` https://github.com/WICG/focus-visible/issues/151
|
7
7
|
* @returns ref to the element that uses `:focus-within` styles
|
8
|
-
*/
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
8
|
+
*/ export function useFocusWithin() {
|
9
|
+
const { targetDocument } = useFluent();
|
10
|
+
const elementRef = React.useRef(null);
|
11
|
+
React.useEffect(()=>{
|
12
|
+
if ((targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) && elementRef.current) {
|
13
|
+
return applyFocusWithinPolyfill(elementRef.current, targetDocument.defaultView);
|
14
|
+
}
|
15
|
+
}, [
|
16
|
+
elementRef,
|
17
|
+
targetDocument
|
18
|
+
]);
|
19
|
+
return elementRef;
|
20
20
|
}
|
21
|
-
//# sourceMappingURL=useFocusWithin.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["useFocusWithin.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { applyFocusWithinPolyfill } from '../focus/focusWithinPolyfill';\n\n/**\n * A ponyfill that allows `:focus-within` to support visibility based on keyboard/mouse navigation\n * like `:focus-visible` https://github.com/WICG/focus-visible/issues/151\n * @returns ref to the element that uses `:focus-within` styles\n */\nexport function useFocusWithin<TElement extends HTMLElement = HTMLElement>() {\n const { targetDocument } = useFluent();\n const elementRef = React.useRef<TElement>(null);\n\n React.useEffect(() => {\n if (targetDocument?.defaultView && elementRef.current) {\n return applyFocusWithinPolyfill(elementRef.current, targetDocument.defaultView);\n }\n }, [elementRef, targetDocument]);\n\n return elementRef;\n}\n"],"names":["React","useFluent_unstable","useFluent","applyFocusWithinPolyfill","useFocusWithin","targetDocument","elementRef","useRef","useEffect","defaultView","current"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,wBAAwB,QAAQ,+BAA+B;AAExE;;;;CAIC,GACD,OAAO,SAASC,iBAA6D;IAC3E,MAAM,EAAEC,eAAc,EAAE,GAAGH;IAC3B,MAAMI,aAAaN,MAAMO,MAAM,CAAW,IAAI;IAE9CP,MAAMQ,SAAS,CAAC,IAAM;QACpB,IAAIH,CAAAA,2BAAAA,4BAAAA,KAAAA,IAAAA,eAAgBI,WAAW,AAAD,KAAKH,WAAWI,OAAO,EAAE;YACrD,OAAOP,yBAAyBG,WAAWI,OAAO,EAAEL,eAAeI,WAAW;QAChF,CAAC;IACH,GAAG;QAACH;QAAYD;KAAe;IAE/B,OAAOC;AACT,CAAC"}
|
@@ -4,28 +4,26 @@ import { useTabster } from './useTabster';
|
|
4
4
|
/**
|
5
5
|
* A hook that returns the necessary tabster attributes to support groupping.
|
6
6
|
* @param options - Options to configure keyboard navigation
|
7
|
-
*/
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
getGroupper(tabster);
|
12
|
-
}
|
13
|
-
return useTabsterAttributes({
|
14
|
-
groupper: {
|
15
|
-
tabbability: getTabbability(options === null || options === void 0 ? void 0 : options.tabBehavior)
|
7
|
+
*/ export const useFocusableGroup = (options)=>{
|
8
|
+
const tabster = useTabster();
|
9
|
+
if (tabster) {
|
10
|
+
getGroupper(tabster);
|
16
11
|
}
|
17
|
-
|
12
|
+
return useTabsterAttributes({
|
13
|
+
groupper: {
|
14
|
+
tabbability: getTabbability(options === null || options === void 0 ? void 0 : options.tabBehavior)
|
15
|
+
}
|
16
|
+
});
|
18
17
|
};
|
19
|
-
const getTabbability = tabBehavior
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
const getTabbability = (tabBehavior)=>{
|
19
|
+
switch(tabBehavior){
|
20
|
+
case 'unlimited':
|
21
|
+
return Types.GroupperTabbabilities.Unlimited;
|
22
|
+
case 'limited':
|
23
|
+
return Types.GroupperTabbabilities.Limited;
|
24
|
+
case 'limited-trap-focus':
|
25
|
+
return Types.GroupperTabbabilities.LimitedTrapFocus;
|
26
|
+
default:
|
27
|
+
return undefined;
|
28
|
+
}
|
30
29
|
};
|
31
|
-
//# sourceMappingURL=useFocusableGroup.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["useFocusableGroup.ts"],"sourcesContent":["import { Types, getGroupper } from 'tabster';\nimport { useTabsterAttributes } from './useTabsterAttributes';\nimport { useTabster } from './useTabster';\n\nexport interface UseFocusableGroupOptions {\n /**\n * Behavior for the Tab key.\n */\n tabBehavior?: 'unlimited' | 'limited' | 'limited-trap-focus';\n}\n\n/**\n * A hook that returns the necessary tabster attributes to support groupping.\n * @param options - Options to configure keyboard navigation\n */\nexport const useFocusableGroup = (options?: UseFocusableGroupOptions): Types.TabsterDOMAttribute => {\n const tabster = useTabster();\n\n if (tabster) {\n getGroupper(tabster);\n }\n\n return useTabsterAttributes({\n groupper: {\n tabbability: getTabbability(options?.tabBehavior),\n },\n });\n};\n\nconst getTabbability = (\n tabBehavior?: UseFocusableGroupOptions['tabBehavior'],\n): Types.GroupperTabbability | undefined => {\n switch (tabBehavior) {\n case 'unlimited':\n return Types.GroupperTabbabilities.Unlimited;\n case 'limited':\n return Types.GroupperTabbabilities.Limited;\n case 'limited-trap-focus':\n return Types.GroupperTabbabilities.LimitedTrapFocus;\n default:\n return undefined;\n }\n};\n"],"names":["Types","getGroupper","useTabsterAttributes","useTabster","useFocusableGroup","options","tabster","groupper","tabbability","getTabbability","tabBehavior","GroupperTabbabilities","Unlimited","Limited","LimitedTrapFocus","undefined"],"mappings":"AAAA,SAASA,KAAK,EAAEC,WAAW,QAAQ,UAAU;AAC7C,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,UAAU,QAAQ,eAAe;AAS1C;;;CAGC,GACD,OAAO,MAAMC,oBAAoB,CAACC,UAAkE;IAClG,MAAMC,UAAUH;IAEhB,IAAIG,SAAS;QACXL,YAAYK;IACd,CAAC;IAED,OAAOJ,qBAAqB;QAC1BK,UAAU;YACRC,aAAaC,eAAeJ,oBAAAA,qBAAAA,KAAAA,IAAAA,QAASK,WAAW;QAClD;IACF;AACF,EAAE;AAEF,MAAMD,iBAAiB,CACrBC,cAC0C;IAC1C,OAAQA;QACN,KAAK;YACH,OAAOV,MAAMW,qBAAqB,CAACC,SAAS;QAC9C,KAAK;YACH,OAAOZ,MAAMW,qBAAqB,CAACE,OAAO;QAC5C,KAAK;YACH,OAAOb,MAAMW,qBAAqB,CAACG,gBAAgB;QACrD;YACE,OAAOC;IACX;AACF"}
|
@@ -6,33 +6,33 @@ import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts
|
|
6
6
|
* Instantiates [keyborg](https://github.com/microsoft/keyborg) and adds `data-keyboard-nav`
|
7
7
|
* attribute to a referenced element to ensure keyboard navigation awareness
|
8
8
|
* synced to keyborg logic without having to cause a re-render on react tree.
|
9
|
-
*/
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
}
|
25
|
-
|
26
|
-
|
9
|
+
*/ export function useKeyboardNavAttribute() {
|
10
|
+
const { targetDocument } = useFluent();
|
11
|
+
const keyborg = useMemo(()=>targetDocument && createKeyborg(targetDocument.defaultView), [
|
12
|
+
targetDocument
|
13
|
+
]);
|
14
|
+
const ref = useRef(null);
|
15
|
+
useEffect(()=>{
|
16
|
+
if (keyborg) {
|
17
|
+
setBooleanAttribute(ref, KEYBOARD_NAV_ATTRIBUTE, keyborg.isNavigatingWithKeyboard());
|
18
|
+
const cb = (next)=>{
|
19
|
+
setBooleanAttribute(ref, KEYBOARD_NAV_ATTRIBUTE, next);
|
20
|
+
};
|
21
|
+
keyborg.subscribe(cb);
|
22
|
+
return ()=>keyborg.unsubscribe(cb);
|
23
|
+
}
|
24
|
+
}, [
|
25
|
+
keyborg
|
26
|
+
]);
|
27
|
+
return ref;
|
27
28
|
}
|
28
29
|
function setBooleanAttribute(elementRef, attribute, value) {
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
if (!elementRef.current) {
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
if (value) {
|
34
|
+
elementRef.current.setAttribute(attribute, '');
|
35
|
+
} else {
|
36
|
+
elementRef.current.removeAttribute(attribute);
|
37
|
+
}
|
37
38
|
}
|
38
|
-
//# sourceMappingURL=useKeyboardNavAttribute.js.map
|