| 60 | * or application. |
| 61 | */ |
| 62 | export 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 | } |