Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3497: Ripple fix for touchable devices #3499

Merged
merged 1 commit into from
Oct 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions components/lib/ripple/Ripple.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const Ripple = React.memo(
React.forwardRef(() => {
const inkRef = React.useRef(null);
const targetRef = React.useRef(null);
const isTouchable = DomHandler.isTouchDevice();

const getTarget = () => {
return inkRef.current && inkRef.current.parentElement;
Expand All @@ -15,15 +16,22 @@ export const Ripple = React.memo(
const bindEvents = () => {
if (targetRef.current) {
targetRef.current.addEventListener('mousedown', onMouseDown);
isTouchable && targetRef.current.addEventListener('touchstart', onTouchStart);
}
};

const unbindEvents = () => {
if (targetRef.current) {
targetRef.current.removeEventListener('mousedown', onMouseDown);
isTouchable && targetRef.current.removeEventListener('touchstart', onTouchStart);
}
};

const onTouchStart = (event) => {
this.onMouseDown(event);
event.preventDefault();
};

const onMouseDown = (event) => {
if (!inkRef.current || getComputedStyle(inkRef.current, null).display === 'none') {
return;
Expand Down