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

Commit 95c0a98

Browse files
authored
fix(text-field): Send client position to line ripple for touch events (#4084)
1 parent c640d50 commit 95c0a98

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

packages/mdc-textfield/foundation.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,14 @@ class MDCTextFieldFoundation extends MDCFoundation {
243243
* @param {!Event} evt
244244
*/
245245
setTransformOrigin(evt) {
246-
const targetClientRect = evt.target.getBoundingClientRect();
247-
const evtCoords = {x: evt.clientX, y: evt.clientY};
248-
const normalizedX = evtCoords.x - targetClientRect.left;
246+
let targetEvent;
247+
if (evt.touches) {
248+
targetEvent = evt.touches[0];
249+
} else {
250+
targetEvent = evt;
251+
}
252+
const targetClientRect = targetEvent.target.getBoundingClientRect();
253+
const normalizedX = targetEvent.clientX - targetClientRect.left;
249254
this.adapter_.setLineRippleTransformOrigin(normalizedX);
250255
}
251256

test/unit/mdc-textfield/foundation.test.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -772,14 +772,18 @@ test('mousedown on the input sets the line ripple origin', () => {
772772

773773
test('touchstart on the input sets the line ripple origin', () => {
774774
const {foundation, mockAdapter} = setupTest();
775-
const mockEvt = {
776-
target: {
777-
getBoundingClientRect: () => {
778-
return {};
775+
const clientRectLeft = 50;
776+
const clientX = 200;
777+
const mockTouchStartEvent = {
778+
touches: [{
779+
target: {
780+
getBoundingClientRect: () => {
781+
return {left: clientRectLeft};
782+
},
779783
},
780-
},
781-
clientX: 200,
782-
clientY: 200,
784+
clientX: clientX,
785+
clientY: 200,
786+
}],
783787
};
784788

785789
let clickHandler;
@@ -788,9 +792,10 @@ test('touchstart on the input sets the line ripple origin', () => {
788792
.thenDo((evtType, handler) => clickHandler = handler);
789793

790794
foundation.init();
791-
clickHandler(mockEvt);
795+
clickHandler(mockTouchStartEvent);
792796

793-
td.verify(mockAdapter.setLineRippleTransformOrigin(td.matchers.anything()));
797+
const argMatcher = td.matchers.argThat((normalizedX) => (normalizedX === (clientX - clientRectLeft)));
798+
td.verify(mockAdapter.setLineRippleTransformOrigin(argMatcher));
794799
});
795800

796801
test('on validation attribute change calls styleValidity_', () => {

0 commit comments

Comments
 (0)