Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit e263bd2

Browse files
authored
feat(menu): Add additional selector for menu anchor (#1339)
- Adds selector `mdc-menu-surface-anchor` - Convert directive to component <mdc-menu-surface-anchor #myAnchor> <mdc-menu [anchor]="myAnchor"> ... </mdc-menu> </mdc-menu-surface-anchor>
1 parent 7267143 commit e263bd2

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

demos/components/menu-demo/menu-demo.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ <h2>Design & API Documentation</h2>
101101
<p>
102102
<span class="docs-api-class-selector-label">Selector:</span>
103103
<span class="docs-api-class-selector-name">mdcMenuSurfaceAnchor</span>
104+
<span class="docs-api-class-selector-name">mdc-menu-surface-anchor</span>
104105
</p>
105106
<table>
106107
<tbody>
107108
<tr>
108-
<td>Use to anchor a menu to an element.</td>
109+
<td>Use to anchor menu to an element.</td>
109110
</tr>
110111
</tbody>
111112
</table>

packages/menu-surface/menu-surface.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import {
2-
Directive,
2+
Component,
33
ElementRef,
44
EventEmitter,
55
NgZone,
6-
Output
6+
Output,
7+
ViewEncapsulation
78
} from '@angular/core';
89
import { fromEvent, Subject, Subscription } from 'rxjs';
910
import { startWith, takeUntil } from 'rxjs/operators';
@@ -45,14 +46,17 @@ const ANCHOR_CORNER_MAP = {
4546
topStart: 'TOP_START'
4647
};
4748

48-
@Directive({
49-
selector: '[mdcMenuSurfaceAnchor], [mdc-menu-surface-anchor]',
49+
@Component({
50+
moduleId: module.id,
51+
selector: '[mdcMenuSurfaceAnchor], mdc-menu-surface-anchor',
5052
host: {
5153
'class': 'mdc-menu-surface--anchor'
52-
}
54+
},
55+
template: '<ng-content></ng-content>',
56+
encapsulation: ViewEncapsulation.None
5357
})
5458
export class MdcMenuSurfaceAnchor {
55-
constructor(public elementRef: ElementRef) { }
59+
constructor(public elementRef: ElementRef<HTMLElement>) { }
5660
}
5761

5862
export class MdcMenuSurfaceBase {
@@ -170,12 +174,12 @@ export class MdcMenuSurfaceBase {
170174
constructor(
171175
protected platform: Platform,
172176
protected ngZone: NgZone,
173-
protected elementRef: ElementRef) { }
177+
protected elementRef: ElementRef<HTMLElement>) { }
174178

175179
protected initMenuSurface(): void {
176180
this._loadListeners();
177181

178-
if (!this._anchorElement && this._getHostElement().parentElement) {
182+
if (this._getHostElement().parentElement) {
179183
this._anchorElement = this._getHostElement().parentElement;
180184
}
181185
}

0 commit comments

Comments
 (0)