Skip to content

fix(checkbox): re-evaluate label visibility when label is updated#30980

Open
OS-jacobbell wants to merge 1 commit intomainfrom
FW-6752
Open

fix(checkbox): re-evaluate label visibility when label is updated#30980
OS-jacobbell wants to merge 1 commit intomainfrom
FW-6752

Conversation

@OS-jacobbell
Copy link
Contributor

What is the current behavior?

Checkbox's render function applies the label-text-wrapper-hidden css class when there is no label text to prevent extra margin from being added. The render function is not re-evaluated if the label is updated. This causes a problem in Angular where dynamic variables get applied after the page is loaded, and a checkbox using a variable as a label gets stuck with its label hidden until something else triggers a re-render, e.g. ticking the box.

What is the new behavior?

  • The checkbox will be re-rendered, and css classes will be updated, when the label text is changed.
  • Updated tests to check that the label is visible after changing from blank to having content.

Does this introduce a breaking change?

  • Yes
  • No

@OS-jacobbell OS-jacobbell requested a review from a team as a code owner February 27, 2026 17:19
@OS-jacobbell OS-jacobbell requested a review from ShaneK February 27, 2026 17:19
@vercel
Copy link

vercel bot commented Feb 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ionic-framework Ready Ready Preview, Comment Feb 27, 2026 5:19pm

Request Review

@github-actions github-actions bot added package: core @ionic/core package package: angular @ionic/angular package labels Feb 27, 2026
Copy link
Member

@ShaneK ShaneK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Just a couple of change requests

onClick={this.onDivLabelClick}
>
<slot></slot>
<slot onSlotchange={() => forceUpdate(this)}></slot>
Copy link
Member

@ShaneK ShaneK Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, we should avoid using inline anonymous functions in templates. Doing this both creates a new anonymous function on every render and can make debugging trickier (anonymous functions are harder to find in stack traces than named functions).

It would be better to declare an onSlotChange function in the component and use it here.

export class CheckboxComponent {
dynamicLabel = '';

ngAfterViewChecked(): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ngAfterViewChecked(): void {
ngAfterViewInit(): void {

This is a test and normally I wouldn't make change requests to tests that are just kinda minor architecture changes, but ngAfterViewChecked runs after every change detection cycle and is meant for reading, not writing. I'm concerned this test may be a bad example for our users to follow if they reference it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: angular @ionic/angular package package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants