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
8 changes: 6 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 @@ -265,6 +265,10 @@ export class Checkbox implements ComponentInterface {
ev.stopPropagation();
};

private onSlotChange = () => {
forceUpdate(this);
};

private getHintTextId(): string | undefined {
const { helperText, errorText, helperTextId, errorTextId, isInvalid } = this;

Expand Down Expand Up @@ -382,7 +386,7 @@ export class Checkbox implements ComponentInterface {
id={this.inputLabelId}
onClick={this.onDivLabelClick}
>
<slot></slot>
<slot onSlotchange={this.onSlotChange}></slot>
{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 = '';

ngAfterViewInit(): void {
this.dynamicLabel = 'Dynamic Checkbox Label';
}

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