Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
WIP: Fix TouchEvent clientX bug
Browse files Browse the repository at this point in the history
  • Loading branch information
acdvorak committed Feb 12, 2019
1 parent 1e8b7e2 commit a0cce8c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/mdc-select/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,14 @@ class MDCSelect extends MDCComponent<MDCSelectFoundation> implements RippleCapab
*/
private getNormalizedXCoordinate_(evt: MouseEvent | TouchEvent): number {
const targetClientRect = (evt.target as Element).getBoundingClientRect();
const xCoordinate = (evt as MouseEvent).clientX; // TODO(acdvorak): How does this work for TouchEvent?
const xCoordinate = this.isTouchEvent_(evt) ? evt.touches[0].clientX : evt.clientX;
return xCoordinate - targetClientRect.left;
}

private isTouchEvent_(evt: MouseEvent | TouchEvent): evt is TouchEvent {
return Boolean((evt as TouchEvent).touches);
}

/**
* Returns a map of all subcomponents to subfoundations.
*/
Expand Down

0 comments on commit a0cce8c

Please sign in to comment.