Skip to content

Commit 8598a2e

Browse files
committed
fix(picker): use sanitizer on translate3d css prop
1 parent 6708f95 commit 8598a2e

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

demos/datetime/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
<ion-item>
5454
<ion-label>Madison</ion-label>
55-
<ion-datetime displayFormat="h:mm A" [(ngModel)]="madisonTime"></ion-datetime>
55+
<ion-datetime displayFormat="h:mm a" [(ngModel)]="madisonTime"></ion-datetime>
5656
</ion-item>
5757

5858
</ion-list>

ionic/components/picker/picker.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Component, ElementRef, Input, Output, EventEmitter, ViewChildren, QueryList, ViewChild, Renderer, HostListener, ViewEncapsulation} from '@angular/core';
2+
import {DomSanitizationService} from '@angular/platform-browser';
23

34
import {Animation} from '../../animations/animation';
45
import {Transition, TransitionOptions} from '../../transitions/transition';
@@ -88,7 +89,7 @@ export class Picker extends ViewController {
8889
template:
8990
'<div *ngIf="col.prefix" class="picker-prefix" [style.width]="col.prefixWidth">{{col.prefix}}</div>' +
9091
'<div class="picker-opts" #colEle [style.width]="col.optionsWidth">' +
91-
'<button *ngFor="let o of col.options; let i=index;" (click)="optClick($event, i)" type="button" category="picker-opt">' +
92+
'<button *ngFor="let o of col.options; let i=index" [style.transform]="o._trans" [style.transitionDuration]="o._dur" [class.picker-opt-selected]="col.selectedIndex === i" [class.picker-opt-disabled]="o.disabled" (click)="optClick($event, i)" type="button" category="picker-opt">' +
9293
'{{o.text}}' +
9394
'</button>' +
9495
'</div>' +
@@ -123,7 +124,7 @@ class PickerColumnCmp {
123124
lastIndex: number;
124125
@Output() change: EventEmitter<any> = new EventEmitter();
125126

126-
constructor(config: Config) {
127+
constructor(config: Config, private _sanitizer: DomSanitizationService) {
127128
this.rotateFactor = config.getNumber('pickerRotateFactor', 0);
128129
}
129130

@@ -342,15 +343,7 @@ class PickerColumnCmp {
342343

343344
this.col.selectedIndex = Math.max(Math.abs(Math.round(y / this.optHeight)), 0);
344345

345-
let colElements = this.colEle.nativeElement.querySelectorAll('.picker-opt');
346-
if (colElements.length !== this.col.options.length) {
347-
// TODO: temporary until [style.transform] is fixed within ng2
348-
console.warn('colElements.length!=this.col.options.length');
349-
return;
350-
}
351-
352-
for (var i = 0; i < colElements.length; i++) {
353-
var ele: HTMLElement = colElements[i];
346+
for (var i = 0; i < this.col.options.length; i++) {
354347
var opt = <any>this.col.options[i];
355348
var optTop = (i * this.optHeight);
356349
var optOffset = (optTop + y);
@@ -372,11 +365,8 @@ class PickerColumnCmp {
372365
translateY = optOffset;
373366
}
374367

375-
// TODO: setting by [style.transform]="o.transform" within the template is currently broke
376-
ele.style[CSS.transform] = `rotateX(${rotateX}deg) translate3d(${translateX}px,${translateY}px,${translateZ}px)`;
377-
ele.style[CSS.transitionDuration] = (duration > 0 ? duration + 'ms' : '');
378-
ele.classList[this.col.selectedIndex === i ? 'add' : 'remove']('picker-opt-selected');
379-
ele.classList[opt.disabled ? 'add' : 'remove']('picker-opt-disabled');
368+
opt._trans = this._sanitizer.bypassSecurityTrustStyle(`rotateX(${rotateX}deg) translate3d(${translateX}px,${translateY}px,${translateZ}px)`);
369+
opt._dur = (duration > 0 ? duration + 'ms' : '');
380370
}
381371

382372
if (saveY) {

0 commit comments

Comments
 (0)