Prevent default event on icon button clicks

This commit is contained in:
Daniel Gasienica 2018-04-26 11:18:24 -04:00
parent b3d0438537
commit 43e19f3b06

View file

@ -54,9 +54,25 @@ interface IconButtonProps {
type: 'save' | 'close' | 'previous' | 'next';
onClick?: () => void;
}
const IconButton = ({ onClick, type }: IconButtonProps) => (
<a href="#" onClick={onClick} className={classNames('iconButton', type)} />
);
const IconButton = ({ onClick, type }: IconButtonProps) => {
const clickHandler = (event: React.MouseEvent<HTMLAnchorElement>): void => {
event.preventDefault();
if (!onClick) {
return;
}
onClick();
};
return (
<a
href="#"
onClick={clickHandler}
className={classNames('iconButton', type)}
/>
);
};
export class Lightbox extends React.Component<Props, {}> {
private containerRef: HTMLDivElement | null = null;