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

Function useLink

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

Source from the content-addressed store, hash-verified

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

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