69 lines
2.3 KiB
JavaScript
69 lines
2.3 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
Object.defineProperty(exports, "useFocusFinders", {
|
|
enumerable: true,
|
|
get: function() {
|
|
return useFocusFinders;
|
|
}
|
|
});
|
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
|
|
const _useTabster = require("./useTabster");
|
|
const useFocusFinders = ()=>{
|
|
const tabster = (0, _useTabster.useTabster)();
|
|
const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
|
|
// Narrow props for now and let need dictate additional props in the future
|
|
const findAllFocusable = _react.useCallback((container, acceptCondition)=>(tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findAll({
|
|
container,
|
|
acceptCondition
|
|
})) || [], [
|
|
tabster
|
|
]);
|
|
const findFirstFocusable = _react.useCallback((container)=>tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findFirst({
|
|
container
|
|
}), [
|
|
tabster
|
|
]);
|
|
const findLastFocusable = _react.useCallback((container)=>tabster === null || tabster === void 0 ? void 0 : tabster.focusable.findLast({
|
|
container
|
|
}), [
|
|
tabster
|
|
]);
|
|
const findNextFocusable = _react.useCallback((currentElement, options = {})=>{
|
|
if (!tabster || !targetDocument) {
|
|
return null;
|
|
}
|
|
const { container = targetDocument.body } = options;
|
|
return tabster.focusable.findNext({
|
|
currentElement,
|
|
container
|
|
});
|
|
}, [
|
|
tabster,
|
|
targetDocument
|
|
]);
|
|
const findPrevFocusable = _react.useCallback((currentElement, options = {})=>{
|
|
if (!tabster || !targetDocument) {
|
|
return null;
|
|
}
|
|
const { container = targetDocument.body } = options;
|
|
return tabster.focusable.findPrev({
|
|
currentElement,
|
|
container
|
|
});
|
|
}, [
|
|
tabster,
|
|
targetDocument
|
|
]);
|
|
return {
|
|
findAllFocusable,
|
|
findFirstFocusable,
|
|
findLastFocusable,
|
|
findNextFocusable,
|
|
findPrevFocusable
|
|
};
|
|
};
|