From 1791b4ca91e161250e354ae96e1d32f0b7bf30c9 Mon Sep 17 00:00:00 2001 From: Christiaan Scheermeijer Date: Wed, 7 Feb 2024 15:58:24 +0100 Subject: [PATCH] fix: enter key not closing the account modal --- packages/ui-react/src/components/IconButton/IconButton.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/ui-react/src/components/IconButton/IconButton.tsx b/packages/ui-react/src/components/IconButton/IconButton.tsx index 1fdf9361f..3b687eac9 100644 --- a/packages/ui-react/src/components/IconButton/IconButton.tsx +++ b/packages/ui-react/src/components/IconButton/IconButton.tsx @@ -18,7 +18,12 @@ const IconButton: React.FC = ({ children, onClick, tabIndex = 0, classNam onClick={onClick} role="button" tabIndex={tabIndex} - onKeyDown={(event: React.KeyboardEvent) => (event.key === 'Enter' || event.key === ' ') && tabIndex >= 0 && onClick && onClick()} + onKeyDown={(event: React.KeyboardEvent) => { + if ((event.key === 'Enter' || event.key === ' ') && tabIndex >= 0 && onClick) { + onClick(); + event.preventDefault(); // prevent click being called when this component unmounts + } + }} {...ariaProps} > {children}