Skip to content

Commit 28cf16a

Browse files
manucorporatadamdbradley
authored andcommitted
fix(picker): number of dom children != number of options (#6551)
Under certain circustances the number of DOM children is not the same than the number of options, this causes an exception by access to undefined during iteration.
1 parent afd7cff commit 28cf16a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

ionic/components/picker/picker.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ class PickerColumnCmp {
306306

307307
} else if (this.y % this.optHeight !== 0) {
308308
// needs to still get locked into a position so options line up
309-
var currentPos = Math.abs(this.y % this.optHeight);
309+
var currentPos = Math.abs(this.y % this.optHeight);
310310

311311
// create a velocity in the direction it needs to scroll
312312
this.velocity = (currentPos > (this.optHeight / 2) ? 1 : -1);
@@ -343,8 +343,12 @@ class PickerColumnCmp {
343343
this.col.selectedIndex = Math.max(Math.abs(Math.round(y / this.optHeight)), 0);
344344

345345
let colElements = this.colEle.nativeElement.querySelectorAll('.picker-opt');
346-
347-
for (var i = 0; i < this.col.options.length; i++) {
346+
if (colElements.length != this.col.options.length) {
347+
// TODO: it would be great to find the root of the problem
348+
// and implement a good fix, but at least, this prevents an expection
349+
console.error("colElements.length!=this.col.options.length");
350+
}
351+
for (var i = 0; i < colElements.length; i++) {
348352
var ele: HTMLElement = colElements[i];
349353
var opt = <any>this.col.options[i];
350354
var optTop = (i * this.optHeight);
@@ -370,7 +374,7 @@ class PickerColumnCmp {
370374
// TODO: setting by [style.transform]="o.transform" within the template is currently broke
371375
ele.style[CSS.transform] = `rotateX(${rotateX}deg) translate3d(${translateX}px,${translateY}px,${translateZ}px)`;
372376
ele.style[CSS.transitionDuration] = (duration > 0 ? duration + 'ms' : '');
373-
ele.classList[this.col.selectedIndex===i ? 'add' : 'remove']('picker-opt-selected');
377+
ele.classList[this.col.selectedIndex === i ? 'add' : 'remove']('picker-opt-selected');
374378
ele.classList[opt.disabled ? 'add' : 'remove']('picker-opt-disabled');
375379
}
376380

0 commit comments

Comments
 (0)