Skip to content

Commit 3968918

Browse files
crisbetojelbourn
authored andcommitted
refactor(popover-edit): remove unnecessary components (#15954)
Removes a couple of components that are only being used to add a single attribute and are causing a bunch of extra generated code to be added. They aren't really necessary because we can do the same with a couple of extra lines.
1 parent cbad345 commit 3968918

File tree

4 files changed

+18
-49
lines changed

4 files changed

+18
-49
lines changed

src/cdk-experimental/popover-edit/popover-edit-module.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import {
1313
CdkPopoverEditTabOut,
1414
CdkRowHoverContent,
1515
CdkEditable,
16-
CdkEditOpen,
17-
CdkEditOpenButton
16+
CdkEditOpen
1817
} from './table-directives';
1918
import {CdkEditControl,
2019
CdkEditRevert,
@@ -34,7 +33,6 @@ const EXPORTED_DECLARATIONS = [
3433
CdkEditClose,
3534
CdkEditable,
3635
CdkEditOpen,
37-
CdkEditOpenButton,
3836
];
3937

4038
@NgModule({

src/cdk-experimental/popover-edit/table-directives.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -392,33 +392,24 @@ export class CdkRowHoverContent implements AfterViewInit, OnDestroy {
392392
* element or an ancestor element.
393393
*/
394394
@Directive({
395-
// Specify :not(button) as we only need to add type: button on actual buttons.
396-
selector: '[cdkEditOpen]:not(button)',
397-
host: {
398-
'(click)': 'openEdit($event)',
399-
}
395+
selector: '[cdkEditOpen]',
396+
host: {'(click)': 'openEdit($event)'}
400397
})
401398
export class CdkEditOpen {
402399
constructor(
403-
protected readonly elementRef: ElementRef,
404-
protected readonly editEventDispatcher: EditEventDispatcher) {}
400+
protected readonly elementRef: ElementRef<HTMLElement>,
401+
protected readonly editEventDispatcher: EditEventDispatcher) {
402+
403+
const nativeElement = elementRef.nativeElement;
404+
405+
// Prevent accidental form submits.
406+
if (nativeElement.nodeName === 'BUTTON' && !nativeElement.getAttribute('type')) {
407+
nativeElement.setAttribute('type', 'button');
408+
}
409+
}
405410

406411
openEdit(evt: Event): void {
407412
this.editEventDispatcher.editing.next(closest(this.elementRef.nativeElement!, CELL_SELECTOR));
408413
evt.stopPropagation();
409414
}
410415
}
411-
412-
/**
413-
* Opens the closest edit popover to this element, whether it's associated with this exact
414-
* element or an ancestor element.
415-
*/
416-
@Directive({
417-
// Specify button as we only need to add type: button on actual buttons.
418-
selector: 'button[cdkEditOpen]',
419-
host: {
420-
'(click)': 'openEdit($event)',
421-
'type': 'button', // Prevents accidental form submits.
422-
}
423-
})
424-
export class CdkEditOpenButton extends CdkEditOpen {}

src/material-experimental/popover-edit/popover-edit-module.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import {
1313
MatPopoverEdit,
1414
MatPopoverEditTabOut,
1515
MatRowHoverContent,
16-
MatEditOpen,
17-
MatEditOpenButton
16+
MatEditOpen
1817
} from './table-directives';
1918
import {
2019
MatEditLens,
@@ -29,8 +28,7 @@ const EXPORTED_DECLARATIONS = [
2928
MatEditLens,
3029
MatEditRevert,
3130
MatEditClose,
32-
MatEditOpen,
33-
MatEditOpenButton,
31+
MatEditOpen
3432
];
3533

3634
@NgModule({

src/material-experimental/popover-edit/table-directives.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import {
1010
CdkPopoverEdit,
1111
CdkPopoverEditTabOut,
1212
CdkRowHoverContent,
13-
CdkEditOpen,
14-
CdkEditOpenButton,
13+
CdkEditOpen
1514
} from '@angular/cdk-experimental/popover-edit';
1615

1716
const POPOVER_EDIT_HOST_BINDINGS = {
@@ -107,25 +106,8 @@ export class MatRowHoverContent extends CdkRowHoverContent {
107106
* element or an ancestor element.
108107
*/
109108
@Directive({
110-
// Specify :not(button) as we only need to add type: button on actual buttons.
111-
selector: '[matEditOpen]:not(button)',
112-
host: {
113-
'(click)': 'openEdit($event)',
114-
}
109+
selector: '[matEditOpen]',
110+
host: {'(click)': 'openEdit($event)'}
115111
})
116112
export class MatEditOpen extends CdkEditOpen {
117113
}
118-
119-
/**
120-
* Opens the closest edit popover to this element, whether it's associated with this exact
121-
* element or an ancestor element.
122-
*/
123-
@Directive({
124-
// Specify button as we only need to add type: button on actual buttons.
125-
selector: 'button[matEditOpen]',
126-
host: {
127-
'(click)': 'openEdit($event)',
128-
'type': 'button', // Prevents accidental form submits.
129-
}
130-
})
131-
export class MatEditOpenButton extends CdkEditOpenButton {}

0 commit comments

Comments
 (0)