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

Commit f9ef8f5

Browse files
committed
fix(select): Only add line ripple listeners when line ripple is present (#3470)
(cherry picked from commit 453b5c5)
1 parent 7fe8a97 commit f9ef8f5

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

packages/mdc-select/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,12 @@ class MDCSelect extends MDCComponent {
176176
this.nativeControl_.addEventListener('change', this.handleChange_);
177177
this.nativeControl_.addEventListener('focus', this.handleFocus_);
178178
this.nativeControl_.addEventListener('blur', this.handleBlur_);
179-
['mousedown', 'touchstart'].forEach((evtType) => {
180-
this.nativeControl_.addEventListener(evtType, this.handleClick_);
181-
});
179+
180+
if (this.lineRipple_) {
181+
['mousedown', 'touchstart'].forEach((evtType) => {
182+
this.nativeControl_.addEventListener(evtType, this.handleClick_);
183+
});
184+
}
182185

183186
// Initially sync floating label
184187
this.foundation_.handleChange();

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,19 @@ test('mousedown on the select sets the line ripple origin', () => {
488488
td.verify(bottomLine.setRippleCenter(200), {times: 1});
489489
});
490490

491+
test('mousedown on the select does nothing if the it does not have a lineRipple', () => {
492+
const hasOutline = true;
493+
const {bottomLine, fixture} = setupTest(hasOutline);
494+
const event = document.createEvent('MouseEvent');
495+
const clientX = 200;
496+
const clientY = 200;
497+
// IE11 mousedown event.
498+
event.initMouseEvent('mousedown', true, true, window, 0, 0, 0, clientX, clientY, false, false, false, false, 0, null);
499+
fixture.querySelector('select').dispatchEvent(event);
500+
501+
td.verify(bottomLine.setRippleCenter(200), {times: 0});
502+
});
503+
491504
test('#destroy removes the mousedown listener', () => {
492505
const {bottomLine, component, fixture} = setupTest();
493506
const event = document.createEvent('MouseEvent');

0 commit comments

Comments
 (0)