From 0847c2ac2c52b5fa6d30e381685d6cbf7a41231a Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Wed, 17 Jan 2024 16:17:54 -0500 Subject: [PATCH] fix(segment): setting value via binding updates button state (#28837) Issue number: resolves #28816 --------- ## What is the current behavior? The value is set on Segment asynchronously when binding it in Angular. However, the timing works out such that the value changes after `connectedCallback` is fired but before any Stencil Watchers are configured. As a result, our `value` property watcher does not fire which causes `ionSelect` to not be emitted. Segment Buttons rely on this event to know when to update their state (if the value changes such that a segment button is now selected). This results in a checked segment button not appearing checked. This is similar to other issues that have been fixed: https://github.com/ionic-team/ionic-framework/pull/28510 https://github.com/ionic-team/ionic-framework/pull/28488 https://github.com/ionic-team/ionic-framework/pull/28526 ## What is the new behavior? - Segment now emits `ionSelect` on `componentDidLoad` so that any descendant segment buttons can update correctly. ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information Dev build: `7.6.5-dev.11705415448.16878103` This is a timing issue with Stencil, so I am unable to write a reliable automated test. Reviewers should test the dev build in the repro provided in the linked issue. --- core/src/components/segment/segment.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/components/segment/segment.tsx b/core/src/components/segment/segment.tsx index c015d7e617..b3113c9de7 100644 --- a/core/src/components/segment/segment.tsx +++ b/core/src/components/segment/segment.tsx @@ -140,6 +140,14 @@ export class Segment implements ComponentInterface { async componentDidLoad() { this.setCheckedClasses(); + /** + * If the value changes before watchers + * are setup, then the ionSelect watch callback + * will not fire. As a result, we manually + * fire this event when Select is loaded. + */ + this.ionSelect.emit({ value: this.value }); + /** * We need to wait for the buttons to all be rendered * before we can scroll.