Skip to content

Commit aaf0d51

Browse files
committedAug 13, 2024
fix(material/checkbox): account for disabledInteractive in harness
Switches to using a CSS class to get the disabled state in the harness so it continues to work when `disabledInteractive` is set. (cherry picked from commit 56b977f)
1 parent 0f8b4c4 commit aaf0d51

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed
 

‎src/material/checkbox/testing/checkbox-harness.spec.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ describe('MatCheckboxHarness', () => {
167167
await disabledCheckbox.toggle();
168168
expect(await disabledCheckbox.isChecked()).toBe(false);
169169
});
170+
171+
it('should get disabled state for checkbox with disabledInteractive', async () => {
172+
fixture.componentInstance.disabled.set(false);
173+
fixture.componentInstance.disabledInteractive.set(true);
174+
175+
const checkbox = await loader.getHarness(MatCheckboxHarness.with({label: 'Second'}));
176+
expect(await checkbox.isDisabled()).toBe(false);
177+
178+
fixture.componentInstance.disabled.set(true);
179+
expect(await checkbox.isDisabled()).toBe(true);
180+
});
170181
});
171182

172183
@Component({
@@ -179,7 +190,11 @@ describe('MatCheckboxHarness', () => {
179190
aria-label="First checkbox">
180191
First
181192
</mat-checkbox>
182-
<mat-checkbox indeterminate="true" [disabled]="disabled()" aria-labelledby="second-label">
193+
<mat-checkbox
194+
indeterminate="true"
195+
[disabled]="disabled()"
196+
aria-labelledby="second-label"
197+
[disabledInteractive]="disabledInteractive()">
183198
Second
184199
</mat-checkbox>
185200
<span id="second-label">Second checkbox</span>
@@ -190,4 +205,5 @@ describe('MatCheckboxHarness', () => {
190205
class CheckboxHarnessTest {
191206
ctrl = new FormControl(true);
192207
disabled = signal(true);
208+
disabledInteractive = signal(false);
193209
}

‎src/material/checkbox/testing/checkbox-harness.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,14 @@ export class MatCheckboxHarness extends ComponentHarness {
7272

7373
/** Whether the checkbox is disabled. */
7474
async isDisabled(): Promise<boolean> {
75-
const disabled = (await this._input()).getAttribute('disabled');
76-
return coerceBooleanProperty(await disabled);
75+
const input = await this._input();
76+
const disabled = await input.getAttribute('disabled');
77+
78+
if (disabled !== null) {
79+
return coerceBooleanProperty(disabled);
80+
}
81+
82+
return (await input.getAttribute('aria-disabled')) === 'true';
7783
}
7884

7985
/** Whether the checkbox is required. */

0 commit comments

Comments
 (0)
Please sign in to comment.