Skip to content

Commit 1295ced

Browse files
authored
fix(alert): do not overwrite id set in htmlAttributes (#29708)
Issue number: resolves #29704 --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? Setting the id of an alert via htmlAttributes doesn't work due to it being overwritten by the overlay id. ## What is the new behavior? Setting the id of an alert via htmlAttributes works. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> ## Other information First time PR, long time fan. Please let me know if I missed any of the contributing guidelines, happy to change anything!
1 parent d30afa5 commit 1295ced

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

core/src/components/alert/alert.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,9 @@ export class Alert implements ComponentInterface, OverlayInterface {
341341
}
342342

343343
componentWillLoad() {
344-
setOverlayId(this.el);
344+
if (!this.htmlAttributes?.id) {
345+
setOverlayId(this.el);
346+
}
345347
this.inputsChanged();
346348
this.buttonsChanged();
347349
}

core/src/components/alert/test/alert.spec.ts renamed to core/src/components/alert/test/alert.spec.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { newSpecPage } from '@stencil/core/testing';
22

33
import { config } from '../../../global/config';
44
import { Alert } from '../alert';
5+
import { h } from '@stencil/core';
56

67
describe('alert: custom html', () => {
78
it('should not allow for custom html by default', async () => {
@@ -38,4 +39,15 @@ describe('alert: custom html', () => {
3839
expect(content.textContent).toContain('Custom Text');
3940
expect(content.querySelector('button.custom-html')).toBe(null);
4041
});
42+
43+
it('should not overwrite the id set in htmlAttributes', async () => {
44+
const id = 'custom-id';
45+
const page = await newSpecPage({
46+
components: [Alert],
47+
template: () => <ion-alert htmlAttributes={{ id }} overlayIndex={-1}></ion-alert>,
48+
});
49+
50+
const alert = page.body.querySelector('ion-alert')!;
51+
expect(alert.id).toBe(id);
52+
});
4153
});

0 commit comments

Comments
 (0)