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
30 changes: 30 additions & 0 deletions packages/pharos/src/components/checkbox/pharos-checkbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,36 @@ describe('pharos-checkbox', () => {
expect(getComputedStyle(component).width).to.not.equal('400px');
});

it('keeps the native input in sync when checked is set programmatically after a click', async () => {
component['_checkbox'].click();
await component.updateComplete;
expect(component.checked).to.be.true;

component.checked = false;
await component.updateComplete;
expect(component['_checkbox'].checked).to.be.false;
});

it('re-checks on the next click after being unchecked programmatically', async () => {
let lastChecked: boolean | null = null;
component.addEventListener('change', () => {
lastChecked = component.checked;
});

component['_checkbox'].click();
await component.updateComplete;
expect(component.checked).to.be.true;

component.checked = false;
await component.updateComplete;

component['_checkbox'].click();
await component.updateComplete;

expect(component.checked).to.be.true;
expect(lastChecked).to.be.true;
});

it('resets checked when the form is reset', async () => {
const parentNode = document.createElement('form');
parentNode.setAttribute('name', 'my-form');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { html } from 'lit';
import { property, query } from 'lit/decorators.js';
import type { TemplateResult, CSSResultArray } from 'lit';
import { ifDefined } from 'lit/directives/if-defined.js';
import { live } from 'lit/directives/live.js';
import { checkboxStyles } from './pharos-checkbox.css';
import { unsafeSVG } from 'lit/directives/unsafe-svg.js';
import { classMap } from 'lit/directives/class-map.js';
Expand Down Expand Up @@ -146,7 +147,7 @@ export class PharosCheckbox extends FormMixin(FormElement) {
type="checkbox"
.value=${this.value}
.indeterminate=${this.indeterminate}
?checked=${this.checked}
.checked=${live(this.checked)}
?required=${this.required}
?disabled=${this.disabled}
aria-required=${this.required}
Expand Down
Loading