Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(select): ensure popover options with number values are searched for correctly #23998

Merged
merged 5 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions core/src/components/select-popover/select-popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@ export class SelectPopover implements ComponentInterface {
this.callOptionHandler(ev);
}

private findOptionFromEvent(ev: any) {
const { options } = this;
return options.find(o => this.getValue(o.value) === this.getValue(ev.target.value));
liamdebeasi marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* When an option is selected we need to get the value(s)
* of the selected option(s) and return it in the option
* handler
*/
private callOptionHandler(ev: any) {
const { options } = this;
const option = options.find(o => this.getValue(o.value) === ev.target.value);

const option = this.findOptionFromEvent(ev);
const values = this.getValues(ev);

if (option && option.handler) {
Expand All @@ -74,8 +77,8 @@ export class SelectPopover implements ComponentInterface {
}

private setChecked(ev: any): void {
const { multiple, options } = this;
const option = options.find(o => this.getValue(o.value) === ev.target.value);
const { multiple } = this;
const option = this.findOptionFromEvent(ev);

// this is a popover with checkboxes (multiple value select)
// we need to set the checked value for this option
Expand All @@ -95,7 +98,7 @@ export class SelectPopover implements ComponentInterface {

// this is a popover with radio buttons (single value select)
// return the value that was clicked, otherwise undefined
const option = options.find(o => this.getValue(o.value) === ev.target.value);
const option = this.findOptionFromEvent(ev);
return option ? option.value : undefined;
}

Expand Down
9 changes: 9 additions & 0 deletions core/src/components/select/test/basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@
</ion-select>
</ion-item>

<ion-item>
liamdebeasi marked this conversation as resolved.
Show resolved Hide resolved
<ion-label>Numbers</ion-label>
<ion-select interface="popover">
<ion-select-option value="5">5</ion-select-option>
<ion-select-option value="10">10</ion-select-option>
<ion-select-option value="15">15</ion-select-option>
</ion-select>
</ion-item>

</ion-list>

<ion-list>
Expand Down