Skip to content
Merged
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
11 changes: 10 additions & 1 deletion src/lib/slide-toggle/slide-toggle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@ describe('MatSlideToggle without forms', () => {
expect(document.activeElement).toBe(inputElement);
});

it('should focus on underlying input element when the host is focused', () => {
expect(document.activeElement).not.toBe(inputElement);

slideToggleElement.focus();
fixture.detectChanges();

expect(document.activeElement).toBe(inputElement);
});

it('should set a element class if labelPosition is set to before', () => {
expect(slideToggleElement.classList).not.toContain('mat-slide-toggle-label-before');

Expand Down Expand Up @@ -355,7 +364,7 @@ describe('MatSlideToggle without forms', () => {
fixture.detectChanges();

const slideToggle = fixture.debugElement.query(By.directive(MatSlideToggle)).nativeElement;
expect(slideToggle.getAttribute('tabindex')).toBeFalsy();
expect(slideToggle.getAttribute('tabindex')).toBe('-1');
}));
});

Expand Down
3 changes: 2 additions & 1 deletion src/lib/slide-toggle/slide-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ export const _MatSlideToggleMixinBase:
host: {
'class': 'mat-slide-toggle',
'[id]': 'id',
'[attr.tabindex]': 'null',
'[attr.tabindex]': '-1', // Needs to be `-1` so it can still receive programmatic focus.
'[class.mat-checked]': 'checked',
'[class.mat-disabled]': 'disabled',
'[class.mat-slide-toggle-label-before]': 'labelPosition == "before"',
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
'(focus)': '_inputElement.nativeElement.focus()',
},
templateUrl: 'slide-toggle.html',
styleUrls: ['slide-toggle.css'],
Expand Down