@atlaskit/navigation-system
Version:
The latest navigation system for Atlassian apps.
41 lines • 1.39 kB
JavaScript
import { useContext, useEffect } from 'react';
import { SkipLinksContext } from './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.
*/
export var 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 = useContext(SkipLinksContext),
registerSkipLink = _useContext.registerSkipLink,
unregisterSkipLink = _useContext.unregisterSkipLink;
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]);
};