Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/components/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ComponentInterface, EventEmitter } from '@stencil/core';
import { Build, Component, Element, Event, Host, Method, Prop, State, h } from '@stencil/core';
import { Build, Component, Element, Event, Host, Method, Prop, State, h, forceUpdate } from '@stencil/core';
import { checkInvalidState } from '@utils/forms';
import type { Attributes } from '@utils/helpers';
import { inheritAriaAttributes, renderHiddenInput } from '@utils/helpers';
Expand Down Expand Up @@ -382,7 +382,7 @@ export class Checkbox implements ComponentInterface {
id={this.inputLabelId}
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.

{this.renderHintText()}
</div>
<div class="native-wrapper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ test.describe('Value Accessors', () => {

test('should update the form value', async ({ page }) => {
await expect(page.locator('#formValue')).toHaveText(JSON.stringify({ checkbox: false }, null, 2));
await expect(page.locator('ion-checkbox')).toHaveClass(/ion-pristine/);
await expect(page.getByRole('checkbox', { name: 'Static Checkbox Label' })).toHaveClass(/ion-pristine/);

await page.locator('ion-checkbox').click();
await page.getByRole('checkbox', { name: 'Static Checkbox Label' }).click();

await expect(page.locator('#formValue')).toHaveText(JSON.stringify({ checkbox: true }, null, 2));
await expect(page.locator('ion-checkbox')).toHaveClass(/ion-dirty/);
await expect(page.locator('ion-checkbox')).toHaveClass(/ion-valid/);
await expect(page.getByRole('checkbox', { name: 'Static Checkbox Label' })).toHaveClass(/ion-dirty/);
await expect(page.getByRole('checkbox', { name: 'Static Checkbox Label' })).toHaveClass(/ion-valid/);

await expect(page.getByRole('checkbox', { name: 'Static Checkbox Label' })).toBeVisible();
});

test('should display dynamically set label', async ({ page }) => {
await expect(page.getByRole('checkbox', { name: 'Dynamic Checkbox Label' })).toBeVisible();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ <h1>IonCheckbox Value Accessors</h1>
</p>

<app-value-accessor-test [formGroup]="form">
<ion-checkbox formControlName="checkbox">Checkbox</ion-checkbox>
<ion-checkbox formControlName="checkbox">Static Checkbox Label</ion-checkbox>
</app-value-accessor-test>
<ion-checkbox>{{dynamicLabel}}</ion-checkbox>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import { ValueAccessorTestComponent } from "../value-accessor-test/value-accesso
]
})
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.

this.dynamicLabel = 'Dynamic Checkbox Label';
}

form = this.fb.group({
checkbox: [false, Validators.required],
Expand Down
Loading