Repository navigation
fix(select): value is selected when given array - #24687
Conversation
This commit fixes an issue that caused selected options to not be selected when using the `multiple` option.
|
@adamduren thanks for the PR! With all PRs, we require an issue and reproduction app. Could you please create an issue with a reproduction app that demonstrates the issue? We require this for a few reasons:
Thanks! |
|
@sean-perkins here is a reproduction. Just need to ionic-select-bug.mov |
|
@sean-perkins any updates on this one? Happy to help in any way I can. |
|
@adamduren thanks for the reproduction. I can verify that this is an issue with the This issue is not directly resolving #24584, is it? If not, we can quickly split out a new issue to attach to this PR to help with future issues that may arise (having the ability to search for the issue when reporting new ones). I'd like to write a test around this behavior. Let's run the Github actions and make sure all existing behavior passes and then I can follow-up with what a test may look like to cover this change (may be as simple as a new test with compareWith and capturing a screenshot when it's opened). Appreciate the work here. |
|
@sean-perkins Thanks for the follow-up. This PR does not resolve #24584. I more digging into that one and commented on what I observed in that issue separately. Unfortunately it is beyond the scope of my expertise but believe it is related to React seeing IonSelect as a custom component and manually calling |
|
@adamduren awesome, thanks for the follow-up. We'll create a new issue to track this specific issue then. Can you please add the following test to your PR? In Inside that directory, create two files, The contents of the HTML file: <!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Select - compareWith</title>
<meta name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link href="../../../../../css/ionic.bundle.css" rel="stylesheet">
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet">
<script src="../../../../../scripts/testing/scripts.js"></script>
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
</head>
<body>
<ion-app>
<ion-header>
<ion-toolbar>
<ion-title>Select - compareWith</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item>
<ion-label>Select multiple using objects and compareWith</ion-label>
<ion-select id="multiple"></ion-select>
</ion-item>
<ion-item>
<ion-label>Select using objects and compareWith</ion-label>
<ion-select id="single" multiple="true"></ion-select>
</ion-item>
</ion-list>
</ion-content>
<script>
function compareWithFn(a, b) {
return a.value === b.value;
}
let objectOptions = [{
label: 'selected by default', value: '1'
}, {
label: 'not selected by default', value: '2'
}];
document.querySelectorAll('ion-select').forEach(select => {
select.compareWith = compareWithFn;
objectOptions.forEach((option) => {
let selectOption = document.createElement('ion-select-option');
selectOption.value = option;
selectOption.textContent = option.label;
select.appendChild(selectOption)
});
});
let objectSelectMultipleElement = document.getElementById('multiple');
objectSelectMultipleElement.value = [objectOptions[0]];
let objectSelectElement = document.getElementById('single');
objectSelectElement.value = objectOptions[0];
</script>
</ion-app>
</body>
</html>The contents of the e2e.ts: import { newE2EPage } from '@stencil/core/testing';
test('select: compareWith', async () => {
const page = await newE2EPage({
url: '/src/components/select/test/compare-with?ionic:_testing=true'
});
const compares = [];
compares.push(await page.compareScreenshot());
const selectMultiple = await page.find('#multiple');
await selectMultiple.click();
let alert = await page.find('ion-alert');
await alert.waitForVisible();
await page.waitForTimeout(250);
compares.push(await page.compareScreenshot('should open select[multiple] with option selected'));
await alert.callMethod('dismiss');
const selectSingle = await page.find('#single');
await selectSingle.click();
alert = await page.find('ion-alert');
await alert.waitForVisible();
await page.waitForTimeout(250);
compares.push(await page.compareScreenshot('should open select with option selected'));
await alert.callMethod('dismiss');
for (const compare of compares) {
expect(compare).toMatchScreenshot();
}
}); |
sean-perkins
left a comment
There was a problem hiding this comment.
Looks good comparing against the reproduction and locally with running the test file and verifying before/after behavior.
I'll add the team for review.
|
Merged in, will be available in the 6.0.6 release. Thank you for the contribution! |
|
Thanks team and @sean-perkins! |
This commit fixes an issue that caused selected options to not be selected when using the
multipleoption.Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build) was run locally and any changes were pushednpm run lint) has passed locally and any fixes were made for failuresPull request type
Please check the type of change your PR introduces:
What is the current behavior?
Matching options are not selected by default if an array
valueis passed withmultipleset totrue.Issue Number: #24742
What is the new behavior?
Matching options are selected by default if an array
valueis passed withmultipleset totrue.Does this introduce a breaking change?
Other information
The first two argument names and their argument types for
isOptionSelected(currentValue: any | any[], compareValue: any, compareWith) was the main indicator aside from the apparent bug that the parameters were out of order.