Skip to content

chore: Move CanDisable mixin to MdExpansionPanel #6926

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

Merged
merged 1 commit into from
Sep 12, 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
21 changes: 6 additions & 15 deletions src/lib/expansion/accordion-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,26 @@ import {
} from '@angular/core';
import {UniqueSelectionDispatcher} from '../core';
import {CdkAccordion} from './accordion';
import {mixinDisabled, CanDisable} from '../core/common-behaviors/disabled';

/** Used to generate unique ID for each expansion panel. */
let nextId = 0;

// Boilerplate for applying mixins to MdSlider.
/** @docs-private */
export class AccordionItemBase { }
export const _AccordionItemMixinBase = mixinDisabled(AccordionItemBase);

/**
* An abstract class to be extended and decorated as a component. Sets up all
* events and attributes needed to be managed by a CdkAccordion parent.
*/
@Injectable()
export class AccordionItem extends _AccordionItemMixinBase implements OnDestroy, CanDisable {
/** Event emitted every time the MdAccordionChild is closed. */
export class AccordionItem implements OnDestroy {
/** Event emitted every time the AccordionItem is closed. */
@Output() closed = new EventEmitter<void>();
/** Event emitted every time the MdAccordionChild is opened. */
/** Event emitted every time the AccordionItem is opened. */
@Output() opened = new EventEmitter<void>();
/** Event emitted when the MdAccordionChild is destroyed. */
/** Event emitted when the AccordionItem is destroyed. */
@Output() destroyed = new EventEmitter<void>();
/** The unique MdAccordionChild id. */
/** The unique AccordionItem id. */
readonly id = `cdk-accordion-child-${nextId++}`;

/** Whether the MdAccordionChild is expanded. */
/** Whether the AccordionItem is expanded. */
@Input()
get expanded(): boolean { return this._expanded; }
set expanded(expanded: boolean) {
Expand Down Expand Up @@ -74,9 +68,6 @@ export class AccordionItem extends _AccordionItemMixinBase implements OnDestroy,
constructor(@Optional() public accordion: CdkAccordion,
private _changeDetectorRef: ChangeDetectorRef,
protected _expansionDispatcher: UniqueSelectionDispatcher) {

super();

this._removeUniqueSelectionListener =
_expansionDispatcher.listen((id: string, accordionId: string) => {
if (this.accordion && !this.accordion.multi &&
Expand Down
17 changes: 14 additions & 3 deletions src/lib/expansion/expansion-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,19 @@ import {
import {MdAccordion} from './accordion';
import {AccordionItem} from './accordion-item';
import {UniqueSelectionDispatcher} from '../core';
import {mixinDisabled, CanDisable} from '../core/common-behaviors/disabled';
import {Subject} from 'rxjs/Subject';

// Boilerplate for applying mixins to MdExpansionPanel.
/** @docs-private */
export class MdExpansionPanelBase extends AccordionItem {
constructor(accordion: MdAccordion,
_changeDetectorRef: ChangeDetectorRef,
_uniqueSelectionDispatcher: UniqueSelectionDispatcher) {
super(accordion, _changeDetectorRef, _uniqueSelectionDispatcher);
}
}
export const _MdExpansionPanelMixinBase = mixinDisabled(MdExpansionPanelBase);

/** MdExpansionPanel's states. */
export type MdExpansionPanelState = 'expanded' | 'collapsed';
Expand All @@ -54,7 +65,7 @@ export const EXPANSION_PANEL_ANIMATION_TIMING = '225ms cubic-bezier(0.4,0.0,0.2,
templateUrl: './expansion-panel.html',
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
inputs: ['disabled'],
inputs: ['disabled', 'expanded'],
host: {
'class': 'mat-expansion-panel',
'[class.mat-expanded]': 'expanded',
Expand All @@ -71,7 +82,8 @@ export const EXPANSION_PANEL_ANIMATION_TIMING = '225ms cubic-bezier(0.4,0.0,0.2,
]),
],
})
export class MdExpansionPanel extends AccordionItem implements OnChanges, OnDestroy {
export class MdExpansionPanel extends _MdExpansionPanelMixinBase
implements CanDisable, OnChanges, OnDestroy {
/** Whether the toggle indicator should be hidden. */
@Input() hideToggle: boolean = false;

Expand All @@ -98,7 +110,6 @@ export class MdExpansionPanel extends AccordionItem implements OnChanges, OnDest
if (this.accordion) {
return (this.expanded ? this.accordion.displayMode : this._getExpandedState()) === 'default';
}

return false;
}

Expand Down