Skip to content

Commit

Permalink
An even better hackier workaround to prevent popovers on touch devices
Browse files Browse the repository at this point in the history
- This one plays with input events instead of using media queries
  • Loading branch information
BenjaVR committed Feb 26, 2019
1 parent a605a40 commit 13ac8eb
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/components/planning/PlanningsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface IPlanningsPageState {
isPlanningsDetailVisible: boolean;
studentsForPlanningsDetail: Student[];
selectedDateForPlanningDetail: moment.Moment | undefined;
userIsTouching: boolean;
}

class PlanningsPage extends React.Component<PlanningsPageProps, IPlanningsPageState> {
Expand Down Expand Up @@ -66,6 +67,7 @@ class PlanningsPage extends React.Component<PlanningsPageProps, IPlanningsPageSt
isPlanningsDetailVisible: false,
studentsForPlanningsDetail: [],
selectedDateForPlanningDetail: undefined,
userIsTouching: false,
};

this.unsubscribeFromPlannedStudents = () => {
Expand All @@ -86,6 +88,9 @@ class PlanningsPage extends React.Component<PlanningsPageProps, IPlanningsPageSt
this.handleToday = this.handleToday.bind(this);
this.handleEditInternship = this.handleEditInternship.bind(this);
this.handleDeleteInternship = this.handleDeleteInternship.bind(this);
this.handleContextMenu = this.handleContextMenu.bind(this);
this.handleTouchStart = this.handleTouchStart.bind(this);
this.handleTouchEnd = this.handleTouchEnd.bind(this);
this.addInternshipForStudent = this.addInternshipForStudent.bind(this);
this.editInternshipForStudent = this.editInternshipForStudent.bind(this);
this.closeAddInternshipModal = this.closeAddInternshipModal.bind(this);
Expand Down Expand Up @@ -255,8 +260,9 @@ class PlanningsPage extends React.Component<PlanningsPageProps, IPlanningsPageSt
title={<b>Capaciteiten</b>}
content={this.renderDepartmentPopoverContent(plannedStudentsToday)}
mouseEnterDelay={0.5}
trigger={this.state.userIsTouching ? "contextMenu" : "hover"}
>
<div className={styles.calendarCellContainer}>
<div className={styles.calendarCellContainer} onContextMenu={this.handleContextMenu} onTouchStart={this.handleTouchStart} onTouchEnd={this.handleTouchEnd}>
{departmentsRows}
</div>
</Popover>
Expand Down Expand Up @@ -302,6 +308,20 @@ class PlanningsPage extends React.Component<PlanningsPageProps, IPlanningsPageSt
return departmentsRows;
}

private handleContextMenu(event: React.SyntheticEvent): void {
event.preventDefault();
}

private handleTouchStart(_: React.TouchEvent): void {
this.setState({ userIsTouching: true });
}

private handleTouchEnd(_: React.TouchEvent): void {
window.setTimeout(() => {
this.setState({ userIsTouching: false });
}, 100);
}

private handlePlanningsDetailClose(): void {
this.setState({
isPlanningsDetailVisible: false,
Expand Down

1 comment on commit 13ac8eb

@BenjaVR
Copy link
Owner

@BenjaVR BenjaVR commented on 13ac8eb Feb 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#65

Please sign in to comment.