ionic-framework: PickerController doesn't show correctly
Bug Report
Ionic version:
[x] 4.x
Current behavior:
The second time the PickerController shows the options are not showing correctly.
Expected behavior:
It should show always the right options

Steps to reproduce:
Related code:
Other information:
Ionic info:
Ionic:
ionic (Ionic CLI) : 4.10.3 (/usr/local/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 4.0.2
@angular-devkit/build-angular : 0.13.4
@angular-devkit/schematics : 7.3.4
@angular/cli : 7.3.4
@ionic/angular-toolkit : 1.4.0
System:
NodeJS : v10.15.1 (/usr/local/bin/node)
npm : 6.8.0
OS : macOS Mojave
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 47 (4 by maintainers)
@michaelins
it is the problem of changed columns.options with dynamically set options, when click the picker without changing the selectedIndex twice, the columns.options will add three attribute of selected/duration/transform, just delete it. columns.options.forEach(element => { delete element.selected; delete element.duration; delete element.transform; });
I have the same issue.
It looks like the same
PickerOptionsobject must not be reused for several pickers. I. e. if you store options in component instance, do a copy before passing topickerController.create():Experiencing the same issue… Running ionic latest(5.x.)
what solved the issue was declaring
function removeAllAddedAttributesToArray() { data.forEach(data => { delete data.transform; delete data.duration; delete data.selected; }); }and calling it above the
const picker = await pickerController.create({@nurizzatiabdharis Very strange, here’s how I solved it:
Hi there, I think we are dealing with two separate problems here:
1- If you get all your options stacked once you reopen the picker, then the solution suggested by @MengLu2016 should solve your problem
2- If you are working with dynamic options, in my case I have 2 columns where the options in column B depends on the value selected by column A. You need to make sure that options in column B always have the same length. Otherwise, you might see stacked options if the number of the new options is greater than the number of the old options as @zwlccc said. So what I did, is to make sure that all possible options have the same length by adding disabled options by the end of the smaller one.
For example:
I had the exact same problem and was able to fix it using the techniques from this thread. THANK YOU everyone! I’m doing this on picker dismissal. Changed it to work for multi-column pickers as well:
You can test it using the following methods: Modify the picker-column.tsx file: 1.modify this function: ` private update(y: number, duration: number, saveY: boolean) { if (!this.optsEl) { return; } let translateY = 0; let translateZ = 0; const { col, rotateFactor } = this; const selectedIndex = col.selectedIndex = this.indexForY(-y); const durationStr = (duration === 0) ? ‘’ : duration + ‘ms’; const scaleStr = ‘scale(${this.scaleFactor})’;
}
2.modify this function:render() { const col = this.col; const Button = ‘button’ as any; return [ col.prefix && ( <div class=“picker-prefix” style={{ width: col.prefixWidth! }}> {col.prefix} </div> ), <div class=“picker-opts” style={{ maxWidth: col.optionsWidth! }} ref={el => this.optsEl = el} > { col.options.map((o, index) => <Button type=“button” class={{ ‘picker-opt’: true, ‘picker-opt-disabled’: !!o.disabled, ‘picker-opt-selected’: o.selected }} style={{ transform: o.transform ? o.transform : ‘translate3d(0px, -9999px, 90px)’, ‘transition-duration’: o.duration ? o.duration: TRANSITION_DURATION + ‘ms’ }} opt-index={index} > {o.text} </Button> )} </div>, col.suffix && ( <div class=“picker-suffix” style={{ width: col.suffixWidth! }}> {col.suffix} </div> ) ]; }`For those having issue with using IonPicker component in React. Here’s my solution:
Place sortOptions inside the render() or if using functional component then place it inside the function declaration like below:
And in your IonPicker it stays the same
It re-creates sortOptions on every render (not optimal but it is what it is until the “real” fix)
@gusterwoei FYI
@liamdebeasi hi. i am using Chrome 72.
Here are the step that I got the issue: The first time you select the controller it shows correctly. Then pick an option say “value 3” and click Ok. Then the second time you show the picker the options don’t show correctly if the selectedIndex is set.
I hope this helps