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

Use onPointer instead of onMouse for consistent touch-screen behavior #2608

Merged
merged 5 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
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
14 changes: 6 additions & 8 deletions src/components/Pronunciations/RecorderIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ export default function RecorderIcon(props: RecorderIconProps): ReactElement {
// Temporarily disable context menu since some browsers
// interpret a long-press touch as a right-click.
document.addEventListener("contextmenu", disableContextMenu, false);
toggleIsRecordingToTrue();
}
function handleTouchEnd(): void {
enableContextMenu();
toggleIsRecordingToFalse();
}

function disableContextMenu(event: any): void {
Expand All @@ -68,15 +66,15 @@ export default function RecorderIcon(props: RecorderIconProps): ReactElement {
return (
<Tooltip title={t("pronunciations.recordTooltip")} placement="top">
<IconButton
tabIndex={-1}
onMouseDown={toggleIsRecordingToTrue}
onTouchStart={handleTouchStart}
onMouseUp={toggleIsRecordingToFalse}
onTouchEnd={handleTouchEnd}
className={classes.button}
aria-label="record"
className={classes.button}
id={recordButtonId}
onPointerDown={toggleIsRecordingToTrue}
onPointerUp={toggleIsRecordingToFalse}
onTouchEnd={handleTouchEnd}
onTouchStart={handleTouchStart}
size="large"
tabIndex={-1}
>
<FiberManualRecord
className={
Expand Down
6 changes: 3 additions & 3 deletions src/components/Pronunciations/tests/Pronunciations.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe("Pronunciations", () => {
expect(testRenderer.toJSON()).toMatchSnapshot();
});

it("mouseDown and mouseUp", () => {
it("pointereDown and pointerUp", () => {
const mockStartRecording = jest.fn();
const mockStopRecording = jest.fn();
renderer.act(() => {
Expand All @@ -91,11 +91,11 @@ describe("Pronunciations", () => {
});

expect(mockStartRecording).not.toBeCalled();
testRenderer.root.findByProps({ id: recordButtonId }).props.onMouseDown();
testRenderer.root.findByProps({ id: recordButtonId }).props.onPointerDown();
expect(mockStartRecording).toBeCalled();

expect(mockStopRecording).not.toBeCalled();
testRenderer.root.findByProps({ id: recordButtonId }).props.onMouseUp();
testRenderer.root.findByProps({ id: recordButtonId }).props.onPointerUp();
expect(mockStopRecording).toBeCalled();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Array [
onMouseLeave={[Function]}
onMouseOver={[Function]}
onMouseUp={[Function]}
onPointerDown={[Function]}
onPointerUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
Expand Down