Skip to content

Commit

Permalink
Fixed #4160 - Ripple: first click on component has incorrect location
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Mar 28, 2023
1 parent 16852fa commit 3e23251
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions components/lib/ripple/Ripple.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ export const Ripple = React.memo(

DomHandler.removeClass(inkRef.current, 'p-ink-active');

if (!DomHandler.getHeight(inkRef.current) && !DomHandler.getWidth(inkRef.current)) {
let d = Math.max(DomHandler.getOuterWidth(targetRef.current), DomHandler.getOuterHeight(targetRef.current));

inkRef.current.style.height = d + 'px';
inkRef.current.style.width = d + 'px';
}
setDimensions();

inkRef.current.style.top = offsetY + 'px';
inkRef.current.style.left = offsetX + 'px';
Expand All @@ -70,16 +65,27 @@ export const Ripple = React.memo(
DomHandler.removeClass(event.currentTarget, 'p-ink-active');
};

const setDimensions = () => {
if (inkRef.current && !DomHandler.getHeight(inkRef.current) && !DomHandler.getWidth(inkRef.current)) {
let d = Math.max(DomHandler.getOuterWidth(targetRef.current), DomHandler.getOuterHeight(targetRef.current));

inkRef.current.style.height = d + 'px';
inkRef.current.style.width = d + 'px';
}
};

useMountEffect(() => {
if (inkRef.current) {
targetRef.current = getTarget();
setDimensions();
bindEvents();
}
});

useUpdateEffect(() => {
if (inkRef.current && !targetRef.current) {
targetRef.current = getTarget();
setDimensions();
bindEvents();
}
});
Expand Down

0 comments on commit 3e23251

Please sign in to comment.