@@ -22,12 +22,20 @@ import {CDK_ACCORDION, CdkAccordion} from './accordion';
2222import { BooleanInput , coerceBooleanProperty } from '@angular/cdk/coercion' ;
2323import { Subscription } from 'rxjs' ;
2424
25- /** Used to generate unique ID for each accordion item. */
25+ /**
26+ * Used to generate unique ID for each accordion item.
27+ *
28+ * 用来为每个手风琴条目生成唯一的 ID。
29+ *
30+ */
2631let nextId = 0 ;
2732
2833/**
2934 * An basic directive expected to be extended and decorated as a component. Sets up all
3035 * events and attributes needed to be managed by a CdkAccordion parent.
36+ *
37+ * 一个基本指令,供使用者扩展并改成组件装饰器。设置所有要由 CdkAccordion 的父指令管理的事件和属性。
38+ *
3139 */
3240@Directive ( {
3341 selector : 'cdk-accordion-item, [cdkAccordionItem]' ,
@@ -39,26 +47,59 @@ let nextId = 0;
3947 ] ,
4048} )
4149export class CdkAccordionItem implements OnDestroy {
42- /** Subscription to openAll/closeAll events. */
50+ /**
51+ * Subscription to openAll/closeAll events.
52+ *
53+ * 订阅 openAll / closeAll 事件。
54+ *
55+ */
4356 private _openCloseAllSubscription = Subscription . EMPTY ;
44- /** Event emitted every time the AccordionItem is closed. */
57+ /**
58+ * Event emitted every time the AccordionItem is closed.
59+ *
60+ * 每次关闭此条目时都会发出本事件。
61+ *
62+ */
4563 @Output ( ) closed : EventEmitter < void > = new EventEmitter < void > ( ) ;
46- /** Event emitted every time the AccordionItem is opened. */
64+ /**
65+ * Event emitted every time the AccordionItem is opened.
66+ *
67+ * 每次打开此条目时都会发出本事件。
68+ *
69+ */
4770 @Output ( ) opened : EventEmitter < void > = new EventEmitter < void > ( ) ;
48- /** Event emitted when the AccordionItem is destroyed. */
71+ /**
72+ * Event emitted when the AccordionItem is destroyed.
73+ *
74+ * 当此条目被销毁时会发出本事件。
75+ *
76+ */
4977 @Output ( ) destroyed : EventEmitter < void > = new EventEmitter < void > ( ) ;
5078
5179 /**
5280 * Emits whenever the expanded state of the accordion changes.
5381 * Primarily used to facilitate two-way binding.
82+ *
83+ * 每当手风琴展开状态发生变化时,就会触发。主要是为了方便进行双向绑定。
84+ *
5485 * @docs -private
5586 */
5687 @Output ( ) expandedChange : EventEmitter < boolean > = new EventEmitter < boolean > ( ) ;
5788
58- /** The unique AccordionItem id. */
89+ /**
90+ * The unique AccordionItem id.
91+ *
92+ * AccordionItem 的唯一 id。
93+ *
94+ */
5995 readonly id : string = `cdk-accordion-child-${ nextId ++ } ` ;
6096
61- /** Whether the AccordionItem is expanded. */
97+ /**
98+ * Whether the AccordionItem is expanded.
99+ *
100+ * 此条目是否已经展开了。
101+ *
102+ */
62103 @Input ( )
63104 get expanded ( ) : any { return this . _expanded ; }
64105 set expanded ( expanded : any ) {
@@ -74,6 +115,9 @@ export class CdkAccordionItem implements OnDestroy {
74115 /**
75116 * In the unique selection dispatcher, the id parameter is the id of the CdkAccordionItem,
76117 * the name value is the id of the accordion.
118+ *
119+ * 在唯一选项派发器中,其 id 参数是 CdkAccordionItem 的 id,其 name 的值是这个手风琴的 id。
120+ *
77121 */
78122 const accordionId = this . accordion ? this . accordion . id : this . id ;
79123 this . _expansionDispatcher . notify ( this . id , accordionId ) ;
@@ -88,13 +132,23 @@ export class CdkAccordionItem implements OnDestroy {
88132 }
89133 private _expanded = false ;
90134
91- /** Whether the AccordionItem is disabled. */
135+ /**
136+ * Whether the AccordionItem is disabled.
137+ *
138+ * 此条目是否被禁用了。
139+ *
140+ */
92141 @Input ( )
93142 get disabled ( ) { return this . _disabled ; }
94143 set disabled ( disabled : any ) { this . _disabled = coerceBooleanProperty ( disabled ) ; }
95144 private _disabled : boolean = false ;
96145
97- /** Unregister function for _expansionDispatcher. */
146+ /**
147+ * Unregister function for \_expansionDispatcher.
148+ *
149+ * 取消注册 \_expansionDispatcher 的函数。
150+ *
151+ */
98152 private _removeUniqueSelectionListener : ( ) => void = ( ) => { } ;
99153
100154 constructor ( @Optional ( ) @Inject ( CDK_ACCORDION ) @SkipSelf ( ) public accordion : CdkAccordion ,
@@ -114,7 +168,12 @@ export class CdkAccordionItem implements OnDestroy {
114168 }
115169 }
116170
117- /** Emits an event for the accordion item being destroyed. */
171+ /**
172+ * Emits an event for the accordion item being destroyed.
173+ *
174+ * 发出此条目被销毁的事件。
175+ *
176+ */
118177 ngOnDestroy ( ) {
119178 this . opened . complete ( ) ;
120179 this . closed . complete ( ) ;
@@ -124,21 +183,36 @@ export class CdkAccordionItem implements OnDestroy {
124183 this . _openCloseAllSubscription . unsubscribe ( ) ;
125184 }
126185
127- /** Toggles the expanded state of the accordion item. */
186+ /**
187+ * Toggles the expanded state of the accordion item.
188+ *
189+ * 切换此条目的展开状态。
190+ *
191+ */
128192 toggle ( ) : void {
129193 if ( ! this . disabled ) {
130194 this . expanded = ! this . expanded ;
131195 }
132196 }
133197
134- /** Sets the expanded state of the accordion item to false. */
198+ /**
199+ * Sets the expanded state of the accordion item to false.
200+ *
201+ * 把此条目的展开状态设置为 false。
202+ *
203+ */
135204 close ( ) : void {
136205 if ( ! this . disabled ) {
137206 this . expanded = false ;
138207 }
139208 }
140209
141- /** Sets the expanded state of the accordion item to true. */
210+ /**
211+ * Sets the expanded state of the accordion item to true.
212+ *
213+ * 把此条目的展开状态设置为 true。
214+ *
215+ */
142216 open ( ) : void {
143217 if ( ! this . disabled ) {
144218 this . expanded = true ;
0 commit comments