Skip to content

Commit

Permalink
fix(expansion): add strong focus indication (#18552)
Browse files Browse the repository at this point in the history
Since the color contrast on the expansion panel focus state isn't great, it's a good candidate to have strong focus indication.
  • Loading branch information
crisbeto authored and mmalerba committed Apr 14, 2020
1 parent 0401024 commit 6feff45
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/material/expansion/expansion-panel-header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
align-items: center;
padding: 0 24px;
border-radius: inherit;
position: relative; // Necessary for the strong focus indication.

&:focus,
&:hover {
Expand Down
2 changes: 1 addition & 1 deletion src/material/expansion/expansion-panel-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {MatAccordionTogglePosition} from './accordion-base';
matExpansionAnimations.expansionHeaderHeight
],
host: {
'class': 'mat-expansion-panel-header',
'class': 'mat-expansion-panel-header mat-focus-indicator',
'role': 'button',
'[attr.id]': 'panel._headerId',
'[attr.tabindex]': 'disabled ? -1 : 0',
Expand Down
3 changes: 3 additions & 0 deletions src/material/expansion/expansion-panel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
transition: margin 225ms $mat-fast-out-slow-in-timing-function,
mat-elevation-transition-property-value();

// Required so that the `box-shadow` works after we add `position: relative` to the header.
position: relative;

.mat-accordion & {
&:not(.mat-expanded), &:not(.mat-expansion-panel-spacing) {
border-radius: 0;
Expand Down
8 changes: 8 additions & 0 deletions src/material/expansion/expansion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ describe('MatExpansionPanel', () => {
expect(headerEl.classList).toContain('mat-expanded');
}));

it('should add strong focus indication', fakeAsync(() => {
const fixture = TestBed.createComponent(PanelWithContent);
fixture.detectChanges();

expect(fixture.nativeElement.querySelector('.mat-expansion-panel-header').classList)
.toContain('mat-focus-indicator');
}));

it('should be able to render panel content lazily', fakeAsync(() => {
const fixture = TestBed.createComponent(LazyPanelWithContent);
const content = fixture.debugElement.query(
Expand Down

0 comments on commit 6feff45

Please sign in to comment.