bug: Segment button checked attribute not working on initial load
See original GitHub issueBug Report
Ionic version: [x] 4.9.0
Current behavior: Segment button is not checked initially when attribute “checked” is set
Expected behavior: Segment button is checked initially
Related code:
<ion-segment>
<ion-segment-button checked>
<ion-label>Test 1</ion-label>
</ion-segment-button>
<ion-segment-button>
<ion-label>Test 2</ion-label>
</ion-segment-button>
</ion-segment>
Other information: Now and then it is checked on page reload (at least on Stackblitz using Chrome, never worked on local installation). I added two additional segments and reloaded the page lots of times and I got all possible combinations of checked buttons or none at all.
Just some examples:
1:
2:
3:
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:12 (3 by maintainers)
Top Results From Across the Web
ion-segment-button: dynamically checked not working
In my angular application I tried to dynamically generate ion-segment-buttons for each day of the week and then check today initially.
Read more >LWC update toggle checked/unchecked attribute from JS
The current Idea is to put an Id on the toggle and change their checked/unchecked attributes when any of the other is changed....
Read more >HTML 5.2: 4.10. Forms - W3C
To make the radio buttons work as a group, they are given a common name using the name attribute. To group a batch...
Read more >Known issues and workarounds (Dynamics 365 Marketing)
This article documents known issues and workarounds for Dynamics 365 ... Marketing pages and forms; Reusable content blocks; Segmentation ...
Read more >Release Notes | Wordfast
Implemented selected term in source segment to different color. Fixed Issues. Fixed issue with jumping to random segments when scrolling on touchscreen devices ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found that omitting the
value
attribute from theion-segment-button
appears to be causing this issue. If you, for instance, replace your code with this, it works as expected and the first SegmentButton is selected upon page load.This is because the Segment uses the
value
to determine which of the SegmentButtons should be selected. See for instance: https://github.com/ionic-team/ionic/blob/aec293672565591299606f1534603c976024e59c/core/src/components/segment/segment.tsx#L75Thanks 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.