diff --git a/src/material/slide-toggle/slide-toggle.html b/src/material/slide-toggle/slide-toggle.html
index a48e753e1138..94cdb06e40f8 100644
--- a/src/material/slide-toggle/slide-toggle.html
+++ b/src/material/slide-toggle/slide-toggle.html
@@ -17,7 +17,7 @@
[attr.aria-describedby]="ariaDescribedby"
[attr.aria-required]="required || null"
[attr.aria-checked]="checked"
- [attr.aria-disabled]="disabledInteractive && disabledInteractive ? 'true' : null"
+ [attr.aria-disabled]="disabled && disabledInteractive ? 'true' : null"
(click)="_handleClick()"
#switch>
diff --git a/src/material/slide-toggle/testing/slide-toggle-harness.spec.ts b/src/material/slide-toggle/testing/slide-toggle-harness.spec.ts
index f8bdb1e6acb9..d1aabd8a8819 100644
--- a/src/material/slide-toggle/testing/slide-toggle-harness.spec.ts
+++ b/src/material/slide-toggle/testing/slide-toggle-harness.spec.ts
@@ -160,6 +160,17 @@ describe('MatSlideToggleHarness', () => {
await disabledToggle.toggle();
expect(await disabledToggle.isChecked()).toBe(false);
});
+
+ it('should get disabled state when disabledInteractive is enabled', async () => {
+ fixture.componentInstance.disabled.set(false);
+ fixture.componentInstance.disabledInteractive.set(true);
+
+ const toggle = await loader.getHarness(MatSlideToggleHarness.with({label: 'Second'}));
+ expect(await toggle.isDisabled()).toBe(false);
+
+ fixture.componentInstance.disabled.set(true);
+ expect(await toggle.isDisabled()).toBe(true);
+ });
});
@Component({
@@ -171,7 +182,10 @@ describe('MatSlideToggleHarness', () => {
aria-label="First slide-toggle">
First
-
+
Second
Second slide-toggle
@@ -182,4 +196,5 @@ describe('MatSlideToggleHarness', () => {
class SlideToggleHarnessTest {
ctrl = new FormControl(true);
disabled = signal(true);
+ disabledInteractive = signal(false);
}
diff --git a/src/material/slide-toggle/testing/slide-toggle-harness.ts b/src/material/slide-toggle/testing/slide-toggle-harness.ts
index ad44bfa92a52..773272b28e7f 100644
--- a/src/material/slide-toggle/testing/slide-toggle-harness.ts
+++ b/src/material/slide-toggle/testing/slide-toggle-harness.ts
@@ -70,8 +70,14 @@ export class MatSlideToggleHarness extends ComponentHarness {
/** Whether the slide-toggle is disabled. */
async isDisabled(): Promise {
- const disabled = (await this._nativeElement()).getAttribute('disabled');
- return coerceBooleanProperty(await disabled);
+ const nativeElement = await this._nativeElement();
+ const disabled = await nativeElement.getAttribute('disabled');
+
+ if (disabled !== null) {
+ return coerceBooleanProperty(disabled);
+ }
+
+ return (await nativeElement.getAttribute('aria-disabled')) === 'true';
}
/** Whether the slide-toggle is required. */