Skip to content

Commit

Permalink
remove formResetCallback override for checkbox indeterminate state
Browse files Browse the repository at this point in the history
  • Loading branch information
radium-v committed Jul 2, 2024
1 parent 09850a3 commit 5024cc9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
25 changes: 21 additions & 4 deletions packages/web-components/src/checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,14 @@ test.describe('Checkbox', () => {
await expect(element).toHaveJSProperty('indeterminate', false);
});

test('should clear the `indeterminate` state when the `checked` property is true', async ({ page }) => {
test('should NOT change the `indeterminate` property when the owning form is reset', async ({ page }) => {
const element = page.locator('fluent-checkbox');
const form = page.locator('form');

await page.setContent(/* html */ `
<fluent-checkbox></fluent-checkbox>
<form>
<fluent-checkbox></fluent-checkbox>
</form>
`);

await element.evaluate((node: Checkbox) => {
Expand All @@ -252,9 +255,23 @@ test.describe('Checkbox', () => {

await expect(element).toHaveJSProperty('indeterminate', true);

await element.press(' ');
await form.evaluate((node: HTMLFormElement) => {
node.reset();
});

await expect(element).toHaveJSProperty('indeterminate', true);

await test.step('should retain the `indeterminate` property after being set to `false` via user interaction', async () => {
await element.click();

await expect(element).toHaveJSProperty('indeterminate', false);
await expect(element).toHaveJSProperty('indeterminate', false);

await form.evaluate((node: HTMLFormElement) => {
node.reset();
});

await expect(element).toHaveJSProperty('indeterminate', false);
});
});

test('should initialize to the initial value if no value property is set', async ({ page }) => {
Expand Down
10 changes: 0 additions & 10 deletions packages/web-components/src/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,16 +554,6 @@ export class Checkbox extends BaseCheckbox {
this.elementInternals.role = 'checkbox';
}

/**
* Resets the form value to its initial value when the form is reset.
*
* @internal
*/
formResetCallback(): void {
this.indeterminate = false;
super.formResetCallback();
}

/**
* Toggles the checked state of the control.
*
Expand Down

0 comments on commit 5024cc9

Please sign in to comment.