Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion core/src/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ const textForValue = (
compareWith?: string | SelectCompareFn | null
): string | null => {
const selectOpt = opts.find((opt) => {
return compareOptions(getOptionValue(opt), value, compareWith);
return compareOptions(value, getOptionValue(opt), compareWith);
});
return selectOpt ? selectOpt.textContent : null;
};
Expand Down
48 changes: 48 additions & 0 deletions core/src/components/select/test/compare-with/select.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,52 @@ test.describe('select: compare-with', () => {
value: '1',
});
});

test('should work with different parameter types', async ({ page }, testInfo) => {
test.skip(testInfo.project.metadata.rtl === true, 'This does not check LTR vs RTL layouts');
test.skip(testInfo.project.metadata.mode === 'md', 'This logic is the same across modes');
test.info().annotations.push({
type: 'issue',
description: 'https://github.com/ionic-team/ionic-framework/issues/25759',
});

await page.setContent(`
<ion-select value="3" placeholder="Please select"></ion-select>

<script>
const data = [
{ id: 1, name: 'Option #1' },
{ id: 2, name: 'Option #2' },
{ id: 3, name: 'Option #3' },
]
const select = document.querySelector('ion-select');
select.compareWith = (val1, val2) => {
// convert val1 to a number
return +val1 === val2;
}

data.forEach((d) => {
const el = document.createElement('ion-select-option');
el.value = d.id;
el.innerText = d.name;

select.appendChild(el);
});
</script>
`);
const ionAlertDidPresent = await page.spyOnEvent('ionAlertDidPresent');

const select = page.locator('ion-select');
const selectLabel = select.locator('[part="text"]');

await expect(selectLabel).toHaveText('Option #3');

await select.click();
await ionAlertDidPresent.next();

const selectRadios = page.locator('ion-alert button.alert-radio');
await expect(selectRadios.nth(0)).toHaveAttribute('aria-checked', 'false');
await expect(selectRadios.nth(1)).toHaveAttribute('aria-checked', 'false');
await expect(selectRadios.nth(2)).toHaveAttribute('aria-checked', 'true');
});
});