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

Commit 82a9fa3

Browse files
authoredJan 12, 2018
fix(select): Remove unused JS logic for bottom-line scaleX transform (#1910)
fix(select): Remove unused JS logic for bottom-line scaleX transform and matching test
1 parent d62beff commit 82a9fa3

File tree

3 files changed

+3
-99
lines changed

3 files changed

+3
-99
lines changed
 

‎packages/mdc-select/foundation.js

-17
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ export default class MDCSelectFoundation extends MDCFoundation {
8888
/** @private {number} */
8989
this.animationRequestId_ = 0;
9090

91-
this.setPointerXOffset_ = (evt) => this.setBottomLineOrigin_(evt);
9291
this.displayHandler_ = (evt) => {
9392
evt.preventDefault();
9493
if (!this.adapter_.isMenuOpen()) {
@@ -123,9 +122,6 @@ export default class MDCSelectFoundation extends MDCFoundation {
123122
MDCSimpleMenuFoundation.strings.SELECTED_EVENT, this.selectionHandler_);
124123
this.adapter_.registerMenuInteractionHandler(
125124
MDCSimpleMenuFoundation.strings.CANCEL_EVENT, this.cancelHandler_);
126-
['mousedown', 'touchstart'].forEach((evtType) => {
127-
this.adapter_.registerInteractionHandler(evtType, this.setPointerXOffset_);
128-
});
129125
this.resize();
130126
}
131127

@@ -140,9 +136,6 @@ export default class MDCSelectFoundation extends MDCFoundation {
140136
MDCSimpleMenuFoundation.strings.SELECTED_EVENT, this.selectionHandler_);
141137
this.adapter_.deregisterMenuInteractionHandler(
142138
MDCSimpleMenuFoundation.strings.CANCEL_EVENT, this.cancelHandler_);
143-
['mousedown', 'touchstart'].forEach((evtType) => {
144-
this.adapter_.deregisterInteractionHandler(evtType, this.setPointerXOffset_);
145-
});
146139
}
147140

148141
getValue() {
@@ -230,16 +223,6 @@ export default class MDCSelectFoundation extends MDCFoundation {
230223
});
231224
}
232225

233-
setBottomLineOrigin_(evt) {
234-
const targetClientRect = evt.target.getBoundingClientRect();
235-
const evtCoords = {x: evt.clientX, y: evt.clientY};
236-
const normalizedX = evtCoords.x - targetClientRect.left;
237-
const attributeString =
238-
`transform-origin: ${normalizedX}px bottom`;
239-
240-
this.adapter_.setBottomLineAttr('style', attributeString);
241-
}
242-
243226
setMenuStylesForOpenAtIndex_(index) {
244227
const innerHeight = this.adapter_.getWindowInnerHeight();
245228
const {left, top} = this.adapter_.computeBoundingRect();

‎packages/mdc-select/mdc-select.scss

+3-8
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ $mdc-select-menu-transition: transform 180ms $mdc-animation-standard-curve-timin
144144
left: 0;
145145
width: 100%;
146146
height: 1px;
147-
transform: scaleY(1);
148147
transform-origin: bottom;
149148
transition: $mdc-select-menu-transition;
150149
background-color: rgba(black, .5);
@@ -167,14 +166,14 @@ $mdc-select-menu-transition: transform 180ms $mdc-animation-standard-curve-timin
167166

168167
&__bottom-line--active {
169168
&::after {
170-
transform: scaleX(1);
169+
transform: scale(1, 2);
171170
opacity: 1;
172171
}
173172
}
174173

175174
// JS-enhanced and CSS-only Selects require different selectors for focused bottom-line due to different DOM structure
176-
&__surface:focus .mdc-select__bottom-line,
177-
&__surface:focus ~ .mdc-select__bottom-line {
175+
&__surface:focus:not(.mdc-ripple-upgraded) .mdc-select__bottom-line,
176+
&__surface:focus:not(.mdc-ripple-upgraded) ~ .mdc-select__bottom-line {
178177
@include mdc-theme-prop(background-color, primary);
179178

180179
transform: scaleY(2);
@@ -203,10 +202,6 @@ $mdc-select-menu-transition: transform 180ms $mdc-animation-standard-curve-timin
203202
}
204203

205204
.mdc-select__bottom-line {
206-
@include mdc-theme-prop(background-color, primary);
207-
208-
transform: scaleY(2);
209-
210205
&::after {
211206
opacity: 1;
212207
}

‎test/unit/mdc-select/foundation.test.js

-74
Original file line numberDiff line numberDiff line change
@@ -270,77 +270,3 @@ test('#getValue() returns an empty string if selected index < 0', () => {
270270
const {foundation} = setupTest();
271271
assert.equal(foundation.getValue(), '');
272272
});
273-
274-
test('mousedown event sets bottom line origin', () => {
275-
const {foundation, mockAdapter} = setupTest();
276-
const clickLeftOffset = 50;
277-
const mockPointerEvt = td.object({
278-
clientX: 100,
279-
clientY: 5,
280-
target: {
281-
getBoundingClientRect: () => {},
282-
},
283-
});
284-
const ctx = td.object({
285-
font: 'default font',
286-
measureText: () => {},
287-
});
288-
const paddingRight = 16;
289-
const paddingLeft = 20;
290-
let pointerDownEventHandler;
291-
292-
td.when(mockPointerEvt.target.getBoundingClientRect()).thenReturn({left: clickLeftOffset});
293-
td.when(mockAdapter.create2dRenderingContext()).thenReturn(ctx);
294-
td.when(mockAdapter.getComputedStyleValue('font')).thenReturn(null);
295-
td.when(mockAdapter.getComputedStyleValue('font-size')).thenReturn('16px');
296-
td.when(mockAdapter.getComputedStyleValue('font-family')).thenReturn('Roboto,sans-serif');
297-
td.when(mockAdapter.getComputedStyleValue('letter-spacing')).thenReturn('2.5px');
298-
td.when(mockAdapter.getComputedStyleValue('padding-right')).thenReturn(`${paddingRight}px`);
299-
td.when(mockAdapter.getComputedStyleValue('padding-left')).thenReturn(`${paddingLeft}px`);
300-
301-
td.when(mockAdapter.registerInteractionHandler('mousedown', td.matchers.isA(Function))).thenDo((type, handler) => {
302-
pointerDownEventHandler = handler;
303-
});
304-
305-
foundation.init();
306-
pointerDownEventHandler(mockPointerEvt);
307-
308-
td.verify(mockAdapter.setBottomLineAttr('style', `transform-origin: ${clickLeftOffset}px bottom`));
309-
});
310-
311-
test('touchstart event sets bottom line origin', () => {
312-
const {foundation, mockAdapter} = setupTest();
313-
const clickLeftOffset = 50;
314-
const mockPointerEvt = td.object({
315-
clientX: 100,
316-
clientY: 5,
317-
target: {
318-
getBoundingClientRect: () => {},
319-
},
320-
});
321-
const ctx = td.object({
322-
font: 'default font',
323-
measureText: () => {},
324-
});
325-
const paddingRight = 16;
326-
const paddingLeft = 20;
327-
let pointerDownEventHandler;
328-
329-
td.when(mockPointerEvt.target.getBoundingClientRect()).thenReturn({left: clickLeftOffset});
330-
td.when(mockAdapter.create2dRenderingContext()).thenReturn(ctx);
331-
td.when(mockAdapter.getComputedStyleValue('font')).thenReturn(null);
332-
td.when(mockAdapter.getComputedStyleValue('font-size')).thenReturn('16px');
333-
td.when(mockAdapter.getComputedStyleValue('font-family')).thenReturn('Roboto,sans-serif');
334-
td.when(mockAdapter.getComputedStyleValue('letter-spacing')).thenReturn('2.5px');
335-
td.when(mockAdapter.getComputedStyleValue('padding-right')).thenReturn(`${paddingRight}px`);
336-
td.when(mockAdapter.getComputedStyleValue('padding-left')).thenReturn(`${paddingLeft}px`);
337-
338-
td.when(mockAdapter.registerInteractionHandler('touchstart', td.matchers.isA(Function))).thenDo((type, handler) => {
339-
pointerDownEventHandler = handler;
340-
});
341-
342-
foundation.init();
343-
pointerDownEventHandler(mockPointerEvt);
344-
345-
td.verify(mockAdapter.setBottomLineAttr('style', `transform-origin: ${clickLeftOffset}px bottom`));
346-
});

0 commit comments

Comments
 (0)
This repository has been archived.