import { AnchorHTMLAttributes } from "react";

interface IAnchorProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
	useRef?: React.LegacyRef<HTMLAnchorElement>
}

/** 阻止a標籤的href產生網頁跳轉 */
export default function A(props: IAnchorProps) {
	const { useRef, children, onClick } = props;

	function handleClick(event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) {
		event.preventDefault(); // 阻止默认点击行为
		onClick && onClick(event);
	}

	return (
		<a {...props} ref={useRef} onClick={handleClick}>
			{children}
		</a>
	);
}
