MCPcopy Index your code
hub / github.com/adobe/react-spectrum / useLink

Function useLink

packages/react-aria/src/link/useLink.ts:56–101  ·  view source on GitHub ↗
(props: AriaLinkOptions, ref: RefObject<FocusableElement | null>)

Source from the content-addressed store, hash-verified

54 * or application.
55 */
56export function useLink(props: AriaLinkOptions, ref: RefObject<FocusableElement | null>): LinkAria {
57 let {
58 elementType = 'a',
59 onPress,
60 onPressStart,
61 onPressEnd,
62 onClick,
63 isDisabled,
64 ...otherProps
65 } = props;
66
67 let linkProps: DOMAttributes = {};
68 if (elementType !== 'a') {
69 linkProps = {
70 role: 'link',
71 tabIndex: !isDisabled ? 0 : undefined
72 };
73 }
74 let {focusableProps} = useFocusable(props, ref);
75 let {pressProps, isPressed} = usePress({
76 onPress,
77 onPressStart,
78 onPressEnd,
79 onClick,
80 isDisabled,
81 ref
82 });
83 let domProps = filterDOMProps(otherProps, {labelable: true});
84 let interactionHandlers = mergeProps(focusableProps, pressProps);
85 let router = useRouter();
86 let routerLinkProps = useLinkProps(props);
87
88 return {
89 isPressed, // Used to indicate press state for visual
90 linkProps: mergeProps(domProps, routerLinkProps, {
91 ...interactionHandlers,
92 ...linkProps,
93 'aria-disabled': isDisabled || undefined,
94 'aria-current': props['aria-current'],
95 onClick: (e: React.MouseEvent<HTMLAnchorElement>) => {
96 pressProps.onClick?.(e);
97 handleLinkClick(e, router, props.href, props.routerOptions);
98 }
99 })
100 };
101}

Callers 4

renderLinkHookFunction · 0.90
useBreadcrumbItemFunction · 0.90
Link.tsxFile · 0.90
LinkFunction · 0.90

Calls 8

useFocusableFunction · 0.90
usePressFunction · 0.90
filterDOMPropsFunction · 0.90
mergePropsFunction · 0.90
useRouterFunction · 0.90
useLinkPropsFunction · 0.90
handleLinkClickFunction · 0.90
onClickMethod · 0.80

Tested by 1

renderLinkHookFunction · 0.72