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

fix(text-field): Send client position to line ripple for touch events #4084

Merged
merged 3 commits into from
Nov 14, 2018
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
11 changes: 8 additions & 3 deletions packages/mdc-textfield/foundation.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,14 @@ class MDCTextFieldFoundation extends MDCFoundation {
* @param {!Event} evt
*/
setTransformOrigin(evt) {
const targetClientRect = evt.target.getBoundingClientRect();
const evtCoords = {x: evt.clientX, y: evt.clientY};
const normalizedX = evtCoords.x - targetClientRect.left;
let targetEvent;
if (evt.touches) {
targetEvent = evt.touches[0];
} else {
targetEvent = evt;
}
const targetClientRect = targetEvent.target.getBoundingClientRect();
const normalizedX = targetEvent.clientX - targetClientRect.left;
this.adapter_.setLineRippleTransformOrigin(normalizedX);
}

Expand Down
23 changes: 14 additions & 9 deletions test/unit/mdc-textfield/foundation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,14 +772,18 @@ test('mousedown on the input sets the line ripple origin', () => {

test('touchstart on the input sets the line ripple origin', () => {
const {foundation, mockAdapter} = setupTest();
const mockEvt = {
target: {
getBoundingClientRect: () => {
return {};
const clientRectLeft = 50;
const clientX = 200;
const mockTouchStartEvent = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we update the verify call to expect a specific value passed to setLineRippleTransformOrigin in order to better test this fix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

touches: [{
target: {
getBoundingClientRect: () => {
return {left: clientRectLeft};
},
},
},
clientX: 200,
clientY: 200,
clientX: clientX,
clientY: 200,
}],
};

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

foundation.init();
clickHandler(mockEvt);
clickHandler(mockTouchStartEvent);

td.verify(mockAdapter.setLineRippleTransformOrigin(td.matchers.anything()));
const argMatcher = td.matchers.argThat((normalizedX) => (normalizedX === (clientX - clientRectLeft)));
td.verify(mockAdapter.setLineRippleTransformOrigin(argMatcher));
});

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