Skip to content

Commit

Permalink
don't trigger on special types of activations
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanstitt committed Dec 13, 2024
1 parent 553ba59 commit 71dafbd
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/components/button.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import Link from 'next/link'
import { Button, type ButtonProps } from '@mantine/core'
import { useDisclosure } from '@mantine/hooks';
import { MouseEventHandler } from 'react';

type ButtonLinkProps = ButtonProps & {
href: string
target?: string
rel?: string
}

export const ButtonNav: React.FC<{ href: string } & ButtonProps> = ({ href, children, ...buttonProps }) => {
export const ButtonNav: React.FC<ButtonLinkProps> = ({ href, children, target, rel, ...buttonProps }) => {
const [isBusy, { open: setBusy }] = useDisclosure()

const handleClicks = Boolean(target !== '_blank' && rel !== 'external')

const onClick: MouseEventHandler<HTMLAnchorElement> = (event) => {
if (event.button != null && event.button > 0) return; // 0 == main button
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
if (event.defaultPrevented) return;

setBusy()
}
return (
<Link href={href} onClick={setBusy}>
<Link href={href} onClick={handleClicks ? onClick : undefined} target={target} rel={rel}>
<Button {...buttonProps} aria-busy={isBusy} disabled={isBusy} loading={isBusy}>{children}</Button>
</Link>
)
Expand Down

0 comments on commit 71dafbd

Please sign in to comment.