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: segment does not set active button when dynamically changing options in angular #29414

Closed
3 tasks done
jakobe opened this issue Apr 29, 2024 · 4 comments · Fixed by #29418
Closed
3 tasks done

bug: segment does not set active button when dynamically changing options in angular #29414

jakobe opened this issue Apr 29, 2024 · 4 comments · Fixed by #29418
Labels
package: angular @ionic/angular package type: bug a confirmed bug report

Comments

@jakobe
Copy link
Contributor

jakobe commented Apr 29, 2024

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

When updating the nested segment buttons of the Segment control the active segment button looses it's checked state even when the value matches the value of the containing Segment control.
The issue is similar to #28816 but for segment-button, i.e. the value changes after connectedCallback is fired but before any Stencil Watchers are configured. As a result, the value property watcher does not fire which causes updateState not to be called.
The fix in #28837 only fixes the problem on initial rendering, but not on subsequent updates to the nested segment buttons.

Expected Behavior

The active segment button should be highlighted when it's value matches the value of it's containing segment control - as was the case before standalone components.

Steps to Reproduce

  1. Go to https://stackblitz.com/edit/angular-elmzeu
  2. See the segment button "First" being highlighted
  3. Wait 2 seconds
  4. See the segment button "First" NOT being highlighted even though it's value matches the Segment control's value

Code Reproduction URL

https://stackblitz.com/edit/angular-elmzeu

Ionic Info

Ionic:

Ionic CLI : 5.4.16

Utility:

cordova-res : not installed
native-run (update available: 2.0.1) : 1.7.4

System:

NodeJS : v20.11.0
npm : 10.2.4
OS : macOS Unknown

Additional Information

In the Stackblitz reproduction example the nested segment buttons are updated with an additional button, but keeping same value for the first 2 buttons - the problem is the same though when rendering nested buttons each with a new value while updating the value of the Segment control at the same time to match one of the newly rendered buttons.

@ionitron-bot ionitron-bot bot added the triage label Apr 29, 2024
@sean-perkins sean-perkins changed the title bug: Active segment button not highlighted when updating nested segment buttons in Segment standalone component bug: segment does not set active button when dynamically changing options in angular Apr 29, 2024
@sean-perkins sean-perkins added package: angular @ionic/angular package type: bug a confirmed bug report labels Apr 29, 2024
@sean-perkins sean-perkins removed their assignment Apr 29, 2024
@ionitron-bot ionitron-bot bot removed the triage label Apr 29, 2024
@sean-perkins
Copy link
Contributor

Thank you for this issue!

I was able to confirm this issue does not reproduce in the isolated web components, but occurs when consumed in Angular.

We might be able to use onSlotchange here in ion-segment to handle the "value change" (items changing) behavior.

@sean-perkins
Copy link
Contributor

Here is a dev-build: 8.0.2-dev.11714411675.10f48160 if you would like to test and report any unexpected behaviors.

Thanks!

@mariusbolik
Copy link

This Bug also appears on ion-radio-group and maybe on other components like accordion.
Hier is the code to reproduce: https://stackblitz.com/edit/angular-vquurr-ec7ark?file=src%2Fapp%2Fexample.component.html

@jakobe
Copy link
Contributor Author

jakobe commented Apr 30, 2024

@sean-perkins Great! And thanks for the quick reply ⚡

I can confirm this fix works in my scenario as well 👌🏻

I've updated the Stackblitz reproduction example: https://stackblitz.com/edit/angular-elmzeu

github-merge-queue bot pushed a commit that referenced this issue May 1, 2024
…ms (#29418)

Issue number: resolves #29414

---------

<!-- 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. -->

In Angular when the segment buttons are dynamically rendered, the
segment will not set the active visual state for the selected segment
after the re-render.

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

- In Angular the segment will set the active item visually when the
items are dynamically changed

Previously this PR:
#28837 aimed to
resolve #28816. I
have confirmed that the modified approach in the dev-build fixes #29414
and #28816 and the previous change is no longer needed.

## 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

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

Dev-build: `8.0.2-dev.11714411675.10f48160`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: angular @ionic/angular package type: bug a confirmed bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants