question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: Segment button checked attribute not working on initial load

See original GitHub issue

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

Stackblitz

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: one_2 2: two_2
3: two

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
intodevelopmentcommented, Sep 12, 2019

I found that omitting the value attribute from the ion-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.

<ion-segment>
  <ion-segment-button value="test" checked>
    <ion-label>Test 1</ion-label>
  </ion-segment-button>
  <ion-segment-button value="test2">
    <ion-label>Test 2</ion-label>
  </ion-segment-button>
</ion-segment>

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

0reactions
ionitron-bot[bot]commented, Feb 16, 2020

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.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found