Skip to content

Commit

Permalink
Merge pull request #1951 from SpareBank1/develop_fix-collapse
Browse files Browse the repository at this point in the history
fix(ffe-collapse-react): check if ref exist before removing event lis…
  • Loading branch information
pethel authored Apr 29, 2024
2 parents f2bbfac + 58bc672 commit 9c1b68c
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions packages/ffe-collapse-react/src/Collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,28 @@ export const Collapse = React.forwardRef(
const handleTransitionStart = handleTransition('start');
const handleTransitionEnd = handleTransition('end');

_collapse.current.addEventListener(
'transitionstart',
handleTransitionStart,
);
_collapse.current.addEventListener(
'transitionend',
handleTransitionEnd,
);
return () => {
_collapse.current.removeEventListener(
if (_collapse.current) {
_collapse.current.addEventListener(
'transitionstart',
handleTransitionStart,
);
_collapse.current.removeEventListener(
_collapse.current.addEventListener(
'transitionend',
handleTransitionEnd,
);
}

return () => {
if (_collapse.current) {
_collapse.current.removeEventListener(
'transitionstart',
handleTransitionStart,
);
_collapse.current.removeEventListener(
'transitionend',
handleTransitionEnd,
);
}
};
}, [collapse, isOpen, onRest]);

Expand Down

0 comments on commit 9c1b68c

Please sign in to comment.