Skip to content

Commit f9f1775

Browse files
liamdebeasijthoms1
authored andcommitted
fix(select): Account for when options are not loaded immediately (#17405)
* Added logging to begin debugging issue * identify potential fix, add test * fix(select): render when options are loaded after a delay * fix linter issues * fix e2e test * fix edge case with if statement
1 parent 39fbc32 commit f9f1775

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

core/src/components/select/select.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,21 @@ export class Select implements ComponentInterface {
133133
@Listen('ionSelectOptionDidUnload')
134134
async selectOptionChanged() {
135135
await this.loadOptions();
136+
136137
if (this.didInit) {
137138
this.updateOptions();
139+
140+
/**
141+
* In the event that options
142+
* are not loaded at component load
143+
* this ensures that any value that is
144+
* set is properly rendered once
145+
* options have been loaded
146+
*/
147+
if (this.value !== undefined) {
148+
this.el.forceUpdate();
149+
}
150+
138151
}
139152
}
140153

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { newE2EPage } from '@stencil/core/testing';
2+
3+
test('select: async', async () => {
4+
const page = await newE2EPage({
5+
url: '/src/components/select/test/async?ionic:_testing=true'
6+
});
7+
8+
const compare = await page.compareScreenshot();
9+
expect(compare).toMatchScreenshot();
10+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<html dir="ltr">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>Select - Async</title>
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
8+
<link href="../../../../../css/core.css" rel="stylesheet">
9+
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet">
10+
<script src="../../../../../scripts/testing/scripts.js"></script>
11+
<script src="../../../../../dist/ionic.js"></script>
12+
</head>
13+
14+
<body>
15+
<ion-select id="animals" placeholder="Select One"></ion-select>
16+
17+
<script>
18+
let select = document.getElementById('animals');
19+
const options = ['bird', 'dog', 'shark', 'lizard'];
20+
21+
setTimeout(() => {
22+
23+
options.forEach(option => {
24+
let o = document.createElement('ion-select-option');
25+
o.value = option;
26+
o.textContent = option;
27+
28+
select.appendChild(o);
29+
});
30+
31+
select.value = options[0];
32+
33+
}, 500);
34+
35+
</script>
36+
</body>
37+
</html>

0 commit comments

Comments
 (0)