fix(select): alert header defaults to label (#27034)

resolves #27028
This commit is contained in:
Liam DeBeasi
2023-03-28 11:09:42 -04:00
committed by GitHub
parent 5c0ead37bf
commit 408457aa95
2 changed files with 39 additions and 2 deletions

View File

@@ -562,8 +562,22 @@ export class Select implements ComponentInterface {
}
private async openAlert() {
const label = this.getLabel();
const labelText = label ? label.textContent : null;
/**
* TODO FW-3194
* Remove legacyFormController logic.
* Remove label and labelText vars
* Pass `this.label` instead of `labelText`
* when setting the header.
*/
let label: HTMLElement | null;
let labelText: string | null | undefined;
if (this.legacyFormController.hasLegacyControl()) {
label = this.getLabel();
labelText = label ? label.textContent : null;
} else {
labelText = this.label;
}
const interfaceOptions = this.interfaceOptions;
const inputType = this.multiple ? 'checkbox' : 'radio';
@@ -622,6 +636,7 @@ export class Select implements ComponentInterface {
return this.overlay.dismiss();
}
// TODO FW-3194 Remove this
private getLabel() {
return findItemLabel(this.el);
}

View File

@@ -248,3 +248,25 @@ test.describe('select: label', () => {
});
});
});
test.describe('select: alert label', () => {
test('should use the label to set the default header in an alert', async ({ page, skip }) => {
skip.rtl();
skip.mode('md');
await page.setContent(`
<ion-select label="My Alert" interface="alert">
<ion-select-option value="a">A</ion-select-option>
</ion-select>
`);
const select = page.locator('ion-select');
const alert = page.locator('ion-alert');
const ionAlertDidPresent = await page.spyOnEvent('ionAlertDidPresent');
await select.click();
await ionAlertDidPresent.next();
await expect(alert.locator('.alert-title')).toHaveText('My Alert');
});
});