@atlaskit/navigation-system
Version:
The latest navigation system for Atlassian apps.
47 lines (46 loc) • 1.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useSkipLinkInternal = void 0;
var _react = require("react");
var _skipLinksContext = require("./skip-links-context");
/**
* Internal-only hook for registering skip links.
*
* `useSkipLink` is the public API wrapper of this.
*
* This private version exists for us to support `onBeforeNavigate` / `navigate` for the side nav use case,
* where we might need to expand it before moving focus, without having to support those publicly.
*/
var useSkipLinkInternal = exports.useSkipLinkInternal = function useSkipLinkInternal(_ref) {
var id = _ref.id,
label = _ref.label,
listIndex = _ref.listIndex,
onBeforeNavigate = _ref.onBeforeNavigate,
navigate = _ref.navigate,
isHidden = _ref.isHidden;
var _useContext = (0, _react.useContext)(_skipLinksContext.SkipLinksContext),
registerSkipLink = _useContext.registerSkipLink,
unregisterSkipLink = _useContext.unregisterSkipLink;
(0, _react.useEffect)(function () {
if (isHidden) {
/**
* Skip links are hidden for slots with 0 height or width.
* They should not be registered.
*/
return;
}
registerSkipLink({
id: id,
label: label,
listIndex: listIndex,
onBeforeNavigate: onBeforeNavigate,
navigate: navigate,
isHidden: isHidden
});
return function () {
unregisterSkipLink(id);
};
}, [id, isHidden, label, listIndex, onBeforeNavigate, navigate, registerSkipLink, unregisterSkipLink]);
};