@@ -13,7 +13,6 @@ import {
13
13
Directive ,
14
14
ElementRef ,
15
15
EmbeddedViewRef ,
16
- Input ,
17
16
NgZone ,
18
17
OnDestroy ,
19
18
TemplateRef ,
@@ -110,34 +109,42 @@ export class CdkEditable implements AfterViewInit, OnDestroy {
110
109
}
111
110
}
112
111
112
+ const POPOVER_EDIT_HOST_BINDINGS = {
113
+ 'tabIndex' : '0' ,
114
+ 'class' : 'cdk-popover-edit-cell' ,
115
+ '[attr.aria-haspopup]' : 'true' ,
116
+ } ;
117
+
118
+ const POPOVER_EDIT_INPUTS = [
119
+ 'template: cdkPopoverEdit' ,
120
+ 'context: cdkPopoverEditContext' ,
121
+ 'colspan: cdkPopoverEditColspan' ,
122
+ ] ;
123
+
113
124
/**
114
125
* Attaches an ng-template to a cell and shows it when instructed to by the
115
126
* EditEventDispatcher service.
116
127
* Makes the cell focusable.
117
128
*/
118
129
@Directive ( {
119
130
selector : '[cdkPopoverEdit]:not([cdkPopoverEditTabOut])' ,
120
- host : {
121
- 'tabIndex' : '0' ,
122
- 'class' : 'cdk-popover-edit-cell' ,
123
- '[attr.aria-haspopup]' : 'true' ,
124
- }
131
+ host : POPOVER_EDIT_HOST_BINDINGS ,
132
+ inputs : POPOVER_EDIT_INPUTS ,
125
133
} )
126
134
export class CdkPopoverEdit < C > implements AfterViewInit , OnDestroy {
127
135
/** The edit lens template shown over the cell on edit. */
128
- @ Input ( 'cdkPopoverEdit' ) template : TemplateRef < any > | null = null ;
136
+ template : TemplateRef < any > | null = null ;
129
137
130
138
/**
131
139
* Implicit context to pass along to the template. Can be omitted if the template
132
140
* is defined within the cell.
133
141
*/
134
- @ Input ( 'cdkPopoverEditContext' ) context ?: C ;
142
+ context ?: C ;
135
143
136
144
/**
137
145
* Specifies that the popup should cover additional table cells before and/or after
138
146
* this one.
139
147
*/
140
- @Input ( 'cdkPopoverEditColspan' )
141
148
get colspan ( ) : CdkPopoverEditColspan {
142
149
return this . _colspan ;
143
150
}
@@ -184,6 +191,10 @@ export class CdkPopoverEdit<C> implements AfterViewInit, OnDestroy {
184
191
this . services . editEventDispatcher . doneEditingCell ( this . elementRef . nativeElement ! ) ;
185
192
}
186
193
194
+ protected panelClass ( ) : string {
195
+ return EDIT_PANE_CLASS ;
196
+ }
197
+
187
198
private _startListeningToEditEvents ( ) : void {
188
199
this . services . editEventDispatcher . editingCell ( this . elementRef . nativeElement ! )
189
200
. pipe ( takeUntil ( this . destroyed ) )
@@ -207,7 +218,7 @@ export class CdkPopoverEdit<C> implements AfterViewInit, OnDestroy {
207
218
private _createEditOverlay ( ) : void {
208
219
this . overlayRef = this . services . overlay . create ( {
209
220
disposeOnNavigation : true ,
210
- panelClass : EDIT_PANE_CLASS ,
221
+ panelClass : this . panelClass ( ) ,
211
222
positionStrategy : this . _getPositionStrategy ( ) ,
212
223
scrollStrategy : this . services . overlay . scrollStrategies . reposition ( ) ,
213
224
} ) ;
@@ -276,12 +287,9 @@ export class CdkPopoverEdit<C> implements AfterViewInit, OnDestroy {
276
287
* Makes the cell focusable.
277
288
*/
278
289
@Directive ( {
279
- selector : '[cdkPopoverEdit] [cdkPopoverEditTabOut]' ,
280
- host : {
281
- 'tabIndex' : '0' ,
282
- 'class' : 'cdk-popover-edit-cell' ,
283
- '[attr.aria-haspopup]' : 'true' ,
284
- }
290
+ selector : '[cdkPopoverEdit][cdkPopoverEditTabOut]' ,
291
+ host : POPOVER_EDIT_HOST_BINDINGS ,
292
+ inputs : POPOVER_EDIT_INPUTS ,
285
293
} )
286
294
export class CdkPopoverEditTabOut < C > extends CdkPopoverEdit < C > {
287
295
protected focusTrap ?: FocusEscapeNotifier ;
@@ -324,9 +332,6 @@ export class CdkPopoverEditTabOut<C> extends CdkPopoverEdit<C> {
324
332
*/
325
333
@Directive ( {
326
334
selector : '[cdkRowHoverContent]' ,
327
- host : {
328
- '[attr.aria-hidden]' : 'true' ,
329
- }
330
335
} )
331
336
export class CdkRowHoverContent implements AfterViewInit , OnDestroy {
332
337
protected readonly destroyed = new ReplaySubject < void > ( ) ;
@@ -350,6 +355,14 @@ export class CdkRowHoverContent implements AfterViewInit, OnDestroy {
350
355
}
351
356
}
352
357
358
+ protected initElement ( element : HTMLElement ) : void ;
359
+ protected initElement ( ) : void {
360
+ }
361
+
362
+ protected prepareElement ( element : HTMLElement ) : void ;
363
+ protected prepareElement ( ) : void {
364
+ }
365
+
353
366
private _listenForHoverEvents ( ) : void {
354
367
this . services . editEventDispatcher . hoveringOnRow ( this . elementRef . nativeElement ! )
355
368
. pipe ( takeUntil ( this . destroyed ) )
@@ -360,9 +373,11 @@ export class CdkRowHoverContent implements AfterViewInit, OnDestroy {
360
373
// Not doing any positioning in CDK version. Material version
361
374
// will absolutely position on right edge of cell.
362
375
this . viewRef = this . viewContainerRef . createEmbeddedView ( this . templateRef , { } ) ;
376
+ this . initElement ( this . elementRef . nativeElement ! . nextSibling as HTMLElement ) ;
363
377
} else {
364
378
this . viewContainerRef . insert ( this . viewRef ) ;
365
379
}
380
+ this . prepareElement ( this . elementRef . nativeElement ! . nextSibling as HTMLElement ) ;
366
381
} else if ( this . viewRef ) {
367
382
this . viewContainerRef . detach ( this . viewContainerRef . indexOf ( this . viewRef ) ) ;
368
383
}
0 commit comments