MCPcopy Create free account
hub / github.com/adobe/react-spectrum / useLink

Function useLink

packages/react-aria/src/link/useLink.ts:56–103  ·  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 onPressChange,
63 onClick,
64 isDisabled,
65 ...otherProps
66 } = props;
67
68 let linkProps: DOMAttributes = {};
69 if (elementType !== 'a') {
70 linkProps = {
71 role: 'link',
72 tabIndex: !isDisabled ? 0 : undefined
73 };
74 }
75 let {focusableProps} = useFocusable(props, ref);
76 let {pressProps, isPressed} = usePress({
77 onPress,
78 onPressStart,
79 onPressEnd,
80 onPressChange,
81 onClick,
82 isDisabled,
83 ref
84 });
85 let domProps = filterDOMProps(otherProps, {labelable: true});
86 let interactionHandlers = mergeProps(focusableProps, pressProps);
87 let router = useRouter();
88 let routerLinkProps = useLinkProps(props);
89
90 return {
91 isPressed, // Used to indicate press state for visual
92 linkProps: mergeProps(domProps, routerLinkProps, {
93 ...interactionHandlers,
94 ...linkProps,
95 'aria-disabled': isDisabled || undefined,
96 'aria-current': props['aria-current'],
97 onClick: (e: React.MouseEvent<HTMLAnchorElement>) => {
98 pressProps.onClick?.(e);
99 handleLinkClick(e, router, props.href, props.routerOptions);
100 }
101 })
102 };
103}

Callers 5

renderLinkHookFunction · 0.90
useBreadcrumbItemFunction · 0.90
Link.tsxFile · 0.90
LinkFunction · 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