Skip to content

Commit

Permalink
[Recorder] Use onPointer instead of onMouse for consistent touch-scre…
Browse files Browse the repository at this point in the history
…en behavior (#2608)
  • Loading branch information
imnasnainaec authored Sep 18, 2023
1 parent aae6c56 commit 47e97bb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
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

0 comments on commit 47e97bb

Please sign in to comment.