Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(expansion-panel): remove closed panel contents from tab order #5441

Merged
merged 1 commit into from
Jul 9, 2017
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
4 changes: 2 additions & 2 deletions src/lib/expansion/expansion-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export const EXPANSION_PANEL_ANIMATION_TIMING = '225ms cubic-bezier(0.4,0.0,0.2,
],
animations: [
trigger('bodyExpansion', [
state('collapsed', style({height: '0px'})),
state('expanded', style({height: '*'})),
state('collapsed', style({height: '0px', visibility: 'hidden'})),
state('expanded', style({height: '*', visibility: 'visible'})),
transition('expanded <=> collapsed', animate(EXPANSION_PANEL_ANIMATION_TIMING)),
]),
trigger('displayMode', [
Expand Down
47 changes: 34 additions & 13 deletions src/lib/expansion/expansion.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {async, TestBed} from '@angular/core/testing';
import {async, TestBed, fakeAsync, tick} from '@angular/core/testing';
import {Component} from '@angular/core';
import {By} from '@angular/platform-browser';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {MdExpansionModule} from './index';


describe('MdExpansionPanel', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
BrowserAnimationsModule,
NoopAnimationsModule,
MdExpansionModule
],
declarations: [
Expand All @@ -20,9 +20,9 @@ describe('MdExpansionPanel', () => {
}));

it('should expanded and collapse the panel', () => {
let fixture = TestBed.createComponent(PanelWithContent);
let contentEl = fixture.debugElement.query(By.css('.mat-expansion-panel-content'));
let headerEl = fixture.debugElement.query(By.css('.mat-expansion-panel-header'));
const fixture = TestBed.createComponent(PanelWithContent);
const contentEl = fixture.debugElement.query(By.css('.mat-expansion-panel-content'));
const headerEl = fixture.debugElement.query(By.css('.mat-expansion-panel-header'));
fixture.detectChanges();
expect(headerEl.classes['mat-expanded']).toBeFalsy();
expect(contentEl.classes['mat-expanded']).toBeFalsy();
Expand All @@ -34,7 +34,7 @@ describe('MdExpansionPanel', () => {
});

it('emit correct events for change in panel expanded state', () => {
let fixture = TestBed.createComponent(PanelWithContent);
const fixture = TestBed.createComponent(PanelWithContent);
fixture.componentInstance.expanded = true;
fixture.detectChanges();
expect(fixture.componentInstance.openCallback).toHaveBeenCalled();
Expand All @@ -45,17 +45,37 @@ describe('MdExpansionPanel', () => {
});

it('creates a unique panel id for each panel', () => {
let fixtureOne = TestBed.createComponent(PanelWithContent);
let headerElOne = fixtureOne.nativeElement.querySelector('.mat-expansion-panel-header');
let fixtureTwo = TestBed.createComponent(PanelWithContent);
let headerElTwo = fixtureTwo.nativeElement.querySelector('.mat-expansion-panel-header');
const fixtureOne = TestBed.createComponent(PanelWithContent);
const headerElOne = fixtureOne.nativeElement.querySelector('.mat-expansion-panel-header');
const fixtureTwo = TestBed.createComponent(PanelWithContent);
const headerElTwo = fixtureTwo.nativeElement.querySelector('.mat-expansion-panel-header');
fixtureOne.detectChanges();
fixtureTwo.detectChanges();

let panelIdOne = headerElOne.getAttribute('aria-controls');
let panelIdTwo = headerElTwo.getAttribute('aria-controls');
const panelIdOne = headerElOne.getAttribute('aria-controls');
const panelIdTwo = headerElTwo.getAttribute('aria-controls');
expect(panelIdOne).not.toBe(panelIdTwo);
});

it('should not be able to focus content while closed', fakeAsync(() => {
const fixture = TestBed.createComponent(PanelWithContent);
const button = fixture.debugElement.query(By.css('button')).nativeElement;

fixture.componentInstance.expanded = true;
fixture.detectChanges();
tick(250);

button.focus();
expect(document.activeElement).toBe(button, 'Expected button to start off focusable.');

button.blur();
fixture.componentInstance.expanded = false;
fixture.detectChanges();
tick(250);

button.focus();
expect(document.activeElement).not.toBe(button, 'Expected button to no longer be focusable.');
}));
});


Expand All @@ -65,6 +85,7 @@ describe('MdExpansionPanel', () => {
(closed)="closeCallback()">
<md-expansion-panel-header>Panel Title</md-expansion-panel-header>
<p>Some content</p>
<button>I am a button</button>
</md-expansion-panel>`})
class PanelWithContent {
expanded: boolean = false;
Expand Down