Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Active segment button not highlighted when nested into async container #28816

Closed
3 tasks done
leomazza opened this issue Jan 11, 2024 · 3 comments · Fixed by #28837
Closed
3 tasks done

bug: Active segment button not highlighted when nested into async container #28816

leomazza opened this issue Jan 11, 2024 · 3 comments · Fixed by #28837
Labels
package: core @ionic/core package type: bug a confirmed bug report

Comments

@leomazza
Copy link

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

A segment with dynamic value does not highlight the selected button when nested into an async container.

Expected Behavior

It should be highlighted just as it is usually the case.

Steps to Reproduce

  1. Create an <ion-segment [value]="customValue"> with at least 2 <ion-segment-button>s.
  2. Nest that one into a <div *ngIf="observable$ | async">.
  3. See error

Code Reproduction URL

https://github.com/leomazza/ionic-segment-bug

Ionic Info

Ionic:

Ionic CLI : 7.2.0 (/Users/leomazza/.nvm/versions/node/v20.10.0/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 7.6.4
@angular-devkit/build-angular : 17.0.10
@angular-devkit/schematics : 17.0.10
@angular/cli : 17.0.10
@ionic/angular-toolkit : 9.0.0

Capacitor:

Capacitor CLI : 5.6.0
@capacitor/android : not installed
@capacitor/core : 5.6.0
@capacitor/ios : not installed

Utility:

cordova-res : 0.15.4
native-run : 2.0.0

System:

NodeJS : v20.10.0 (/Users/leomazza/.nvm/versions/node/v20.10.0/bin/node)
npm : 10.2.3
OS : macOS Unknown

Additional Information

image

NOTE: The issue is with the second segment block. The first segment button is the selected one but it is not shown as active/checked.

@ionitron-bot ionitron-bot bot added the triage label Jan 11, 2024
@liamdebeasi liamdebeasi self-assigned this Jan 16, 2024
@liamdebeasi liamdebeasi added package: core @ionic/core package type: bug a confirmed bug report labels Jan 16, 2024
@liamdebeasi
Copy link
Member

Thanks, I can reproduce this. Here is a dev build if you are interested in testing a proposed fix:

npm install @ionic/angular@7.6.5-dev.11705415448.16878103

@liamdebeasi liamdebeasi removed their assignment Jan 16, 2024
github-merge-queue bot pushed a commit that referenced this issue Jan 17, 2024
Issue number: resolves #28816

---------

<!-- 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?
<!-- Please describe the current behavior that you are modifying. -->

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:

#28510
#28488
#28526

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Segment now emits `ionSelect` on `componentDidLoad` so that any
descendant segment buttons can update correctly.

## 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/.github/CONTRIBUTING.md#footer
for more information.
-->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

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.
@liamdebeasi
Copy link
Member

Thanks for the issue. This has been resolved via #28837, and a fix will be available in an upcoming release of Ionic Framework. Feel free to keep testing the dev build, and let me know if you run into any issues.

Copy link

ionitron-bot bot commented Feb 16, 2024

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Feb 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: core @ionic/core package type: bug a confirmed bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants