From dfb72d7ea06e28d76069b23eb90c3426181b7c4c Mon Sep 17 00:00:00 2001 From: Sean Perkins <13732623+sean-perkins@users.noreply.github.com> Date: Fri, 3 May 2024 14:26:19 -0400 Subject: [PATCH] fix(angular): persist select disabled state in item (#29448) Issue number: resolves #29234 --------- ## What is the current behavior? In certain scenarios, such as in Angular where the property binding is set a few frames after the element is rendered, the `ionStyle` event from `ion-select` can be emitted before `ion-item` has registered an event listener. This results in situations like setting the `ion-select` as initially disabled can cause the item to not treat the element as not interactable (receives pointer events). ## What is the new behavior? - Emits the `ionStyle` event when the `ion-select` is rendered. - `ion-item` consistently detects the state of `ion-select` and applies the appropriate styles ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information Forked reproduction and dev-build available here: https://github.com/ionic-team/ionic-framework/issues/29234#issuecomment-2091866453 --- core/src/components/select/select.tsx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/core/src/components/select/select.tsx b/core/src/components/select/select.tsx index e20edb9c06..9245e3f9ab 100644 --- a/core/src/components/select/select.tsx +++ b/core/src/components/select/select.tsx @@ -241,10 +241,6 @@ export class Select implements ComponentInterface { this.ionChange.emit({ value }); } - componentWillLoad() { - this.inheritedAttributes = inheritAttributes(this.el, ['aria-label']); - } - async connectedCallback() { const { el } = this; @@ -270,6 +266,24 @@ export class Select implements ComponentInterface { }); } + componentWillLoad() { + this.inheritedAttributes = inheritAttributes(this.el, ['aria-label']); + } + + componentDidLoad() { + /** + * If any of the conditions that trigger the styleChanged callback + * are met on component load, it is possible the event emitted + * prior to a parent web component registering an event listener. + * + * To ensure the parent web component receives the event, we + * emit the style event again after the component has loaded. + * + * This is often seen in Angular with the `dist` output target. + */ + this.emitStyle(); + } + disconnectedCallback() { if (this.mutationO) { this.mutationO.disconnect();