diff --git a/apps/site/components/Common/Button/index.tsx b/apps/site/components/Common/Button/index.tsx index cb7f77eed0c89..804cc296ecf46 100644 --- a/apps/site/components/Common/Button/index.tsx +++ b/apps/site/components/Common/Button/index.tsx @@ -1,5 +1,12 @@ +'use client'; + import classNames from 'classnames'; -import type { FC, AnchorHTMLAttributes } from 'react'; +import type { + FC, + AnchorHTMLAttributes, + KeyboardEvent, + MouseEvent, +} from 'react'; import Link from '@/components/Link'; @@ -7,7 +14,6 @@ import styles from './index.module.css'; type ButtonProps = AnchorHTMLAttributes & { kind?: 'neutral' | 'primary' | 'secondary' | 'special'; - // We have an extra `disabled` prop as we simulate a button disabled?: boolean; }; @@ -17,17 +23,48 @@ const Button: FC = ({ href = undefined, children, className, + onClick, ...props -}) => ( - - {children} - -); +}) => { + const onKeyDownHandler = (e: KeyboardEvent) => { + if (disabled) { + e.preventDefault(); + return; + } + + if (e.key === 'Enter' || e.key === ' ') { + e.preventDefault(); + if (typeof onClick === 'function') { + onClick(e as unknown as MouseEvent); + } + } + }; + + const onClickHandler = (e: MouseEvent) => { + if (disabled) { + e.preventDefault(); + return; + } + + if (typeof onClick === 'function') { + onClick(e); + } + }; + + return ( + + {children} + + ); +}; export default Button;