Skip to content
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

fix(material-experimental/mdc-menu): ensure mat-mdc- prefix on all classes #23559

Merged
merged 4 commits into from Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/material-experimental/mdc-menu/directives.ts
@@ -0,0 +1,33 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {Directive} from '@angular/core';
import {_MatMenuContentBase, _MatMenuTriggerBase, MAT_MENU_CONTENT} from '@angular/material/menu';

/** Directive applied to an element that should trigger a `mat-menu`. */
@Directive({
selector: `[mat-menu-trigger-for], [matMenuTriggerFor]`,
host: {
'class': 'mat-mdc-menu-trigger',
'aria-haspopup': 'true',
'[attr.aria-expanded]': 'menuOpen || null',
'[attr.aria-controls]': 'menuOpen ? menu.panelId : null',
'(mousedown)': '_handleMousedown($event)',
'(keydown)': '_handleKeydown($event)',
'(click)': '_handleClick($event)',
mmalerba marked this conversation as resolved.
Show resolved Hide resolved
},
exportAs: 'matMenuTrigger'
})
export class MatMenuTrigger extends _MatMenuTriggerBase {}

/** Menu content that will be rendered lazily once the menu is opened. */
@Directive({
selector: 'ng-template[matMenuContent]',
providers: [{provide: MAT_MENU_CONTENT, useExisting: MatMenuContent}],
})
export class MatMenuContent extends _MatMenuContentBase {}
16 changes: 11 additions & 5 deletions src/material-experimental/mdc-menu/module.ts
Expand Up @@ -10,21 +10,27 @@ import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {MatCommonModule, MatRippleModule} from '@angular/material-experimental/mdc-core';
import {OverlayModule} from '@angular/cdk/overlay';
import {_MatMenuDirectivesModule} from '@angular/material/menu';
import {CdkScrollableModule} from '@angular/cdk/scrolling';
import {MatMenu, MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER} from './menu';
import {MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER, MatMenu} from './menu';
import {MatMenuItem} from './menu-item';
import {MatMenuContent, MatMenuTrigger} from './directives';

@NgModule({
imports: [
CommonModule,
MatRippleModule,
MatCommonModule,
OverlayModule,
_MatMenuDirectivesModule
],
exports: [CdkScrollableModule, MatMenu, MatCommonModule, MatMenuItem, _MatMenuDirectivesModule],
declarations: [MatMenu, MatMenuItem],
exports: [
CdkScrollableModule,
MatMenu,
MatCommonModule,
MatMenuItem,
MatMenuContent,
MatMenuTrigger
],
declarations: [MatMenu, MatMenuItem, MatMenuContent, MatMenuTrigger],
providers: [MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER]
})
export class MatMenuModule {}
4 changes: 1 addition & 3 deletions src/material-experimental/mdc-menu/public-api.ts
Expand Up @@ -8,19 +8,17 @@

export {MatMenu} from './menu';
export {MatMenuItem} from './menu-item';
export {MatMenuTrigger, MatMenuContent} from './directives';
export * from './module';

export {
_MatMenuDirectivesModule,
fadeInItems,
MAT_MENU_DEFAULT_OPTIONS,
MAT_MENU_PANEL,
MAT_MENU_SCROLL_STRATEGY,
matMenuAnimations,
MatMenuContent,
MatMenuDefaultOptions,
MatMenuPanel,
MatMenuTrigger,
MenuPositionX,
MenuPositionY,
transformMenu,
Expand Down
2 changes: 1 addition & 1 deletion src/material-experimental/mdc-menu/testing/menu-harness.ts
Expand Up @@ -18,7 +18,7 @@ import {
export class MatMenuHarness extends _MatMenuHarnessBase<
typeof MatMenuItemHarness, MatMenuItemHarness, MenuItemHarnessFilters> {
/** The selector for the host element of a `MatMenu` instance. */
static hostSelector = '.mat-menu-trigger';
static hostSelector = '.mat-mdc-menu-trigger';
protected _itemClass = MatMenuItemHarness;

/**
Expand Down
19 changes: 11 additions & 8 deletions src/material/menu/menu-content.ts
Expand Up @@ -29,14 +29,8 @@ import {Subject} from 'rxjs';
*/
export const MAT_MENU_CONTENT = new InjectionToken<MatMenuContent>('MatMenuContent');

/**
* Menu content that will be rendered lazily once the menu is opened.
*/
@Directive({
selector: 'ng-template[matMenuContent]',
providers: [{provide: MAT_MENU_CONTENT, useExisting: MatMenuContent}],
})
export class MatMenuContent implements OnDestroy {
@Directive()
export class _MatMenuContentBase implements OnDestroy {
private _portal: TemplatePortal<any>;
private _outlet: DomPortalOutlet;

Expand Down Expand Up @@ -105,3 +99,12 @@ export class MatMenuContent implements OnDestroy {
}
}
}

/**
* Menu content that will be rendered lazily once the menu is opened.
*/
@Directive({
selector: 'ng-template[matMenuContent]',
providers: [{provide: MAT_MENU_CONTENT, useExisting: MatMenuContent}],
})
export class MatMenuContent extends _MatMenuContentBase {}
26 changes: 9 additions & 17 deletions src/material/menu/menu-module.ts
Expand Up @@ -16,30 +16,22 @@ import {MatMenuContent} from './menu-content';
import {MatMenuItem} from './menu-item';
import {MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER, MatMenuTrigger} from './menu-trigger';

/**
* Used by both the current `MatMenuModule` and the MDC `MatMenuModule`
* to declare the menu-related directives.
*/
@NgModule({
exports: [MatMenuTrigger, MatMenuContent, MatCommonModule],
declarations: [
MatMenuTrigger,
MatMenuContent,
],
providers: [MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER]
})
export class _MatMenuDirectivesModule {}

@NgModule({
imports: [
CommonModule,
MatCommonModule,
MatRippleModule,
OverlayModule,
_MatMenuDirectivesModule,
],
exports: [CdkScrollableModule, MatCommonModule, MatMenu, MatMenuItem, _MatMenuDirectivesModule],
declarations: [MatMenu, MatMenuItem],
exports: [
CdkScrollableModule,
MatCommonModule,
MatMenu,
MatMenuItem,
MatMenuTrigger,
MatMenuContent
],
declarations: [MatMenu, MatMenuItem, MatMenuTrigger, MatMenuContent],
providers: [MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER]
})
export class MatMenuModule {}
33 changes: 18 additions & 15 deletions src/material/menu/menu-trigger.ts
Expand Up @@ -71,21 +71,8 @@ const passiveEventListenerOptions = normalizePassiveListenerOptions({passive: tr

// TODO(andrewseguin): Remove the kebab versions in favor of camelCased attribute selectors

/** Directive applied to an element that should trigger a `mat-menu`. */
@Directive({
selector: `[mat-menu-trigger-for], [matMenuTriggerFor]`,
host: {
'class': 'mat-menu-trigger',
'aria-haspopup': 'true',
'[attr.aria-expanded]': 'menuOpen || null',
'[attr.aria-controls]': 'menuOpen ? menu.panelId : null',
'(mousedown)': '_handleMousedown($event)',
'(keydown)': '_handleKeydown($event)',
'(click)': '_handleClick($event)',
},
exportAs: 'matMenuTrigger'
})
export class MatMenuTrigger implements AfterContentInit, OnDestroy {
@Directive()
export class _MatMenuTriggerBase implements AfterContentInit, OnDestroy {
private _portal: TemplatePortal;
private _overlayRef: OverlayRef | null = null;
private _menuOpen: boolean = false;
Expand Down Expand Up @@ -597,3 +584,19 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
}

}

/** Directive applied to an element that should trigger a `mat-menu`. */
@Directive({
selector: `[mat-menu-trigger-for], [matMenuTriggerFor]`,
host: {
'class': 'mat-menu-trigger',
'aria-haspopup': 'true',
'[attr.aria-expanded]': 'menuOpen || null',
'[attr.aria-controls]': 'menuOpen ? menu.panelId : null',
'(mousedown)': '_handleMousedown($event)',
'(keydown)': '_handleKeydown($event)',
'(click)': '_handleClick($event)',
},
exportAs: 'matMenuTrigger'
})
export class MatMenuTrigger extends _MatMenuTriggerBase {}
2 changes: 1 addition & 1 deletion src/material/menu/public-api.ts
Expand Up @@ -13,7 +13,7 @@ export {
_MatMenuBase,
} from './menu';
export {MatMenuItem} from './menu-item';
export {MatMenuTrigger, MAT_MENU_SCROLL_STRATEGY} from './menu-trigger';
export {MatMenuTrigger, MAT_MENU_SCROLL_STRATEGY, _MatMenuTriggerBase} from './menu-trigger';
export {MatMenuPanel, MAT_MENU_PANEL} from './menu-panel';
export * from './menu-module';
export * from './menu-animations';
Expand Down
44 changes: 25 additions & 19 deletions tools/public_api_guard/material/menu.md
Expand Up @@ -24,8 +24,8 @@ import { FocusableOption } from '@angular/cdk/a11y';
import { FocusMonitor } from '@angular/cdk/a11y';
import { FocusOrigin } from '@angular/cdk/a11y';
import * as i0 from '@angular/core';
import * as i3 from '@angular/material/core';
import * as i6 from '@angular/common';
import * as i5 from '@angular/common';
import * as i6 from '@angular/material/core';
import * as i7 from '@angular/cdk/overlay';
import * as i8 from '@angular/cdk/scrolling';
import { InjectionToken } from '@angular/core';
Expand Down Expand Up @@ -162,17 +162,25 @@ export class _MatMenuBase implements AfterContentInit, MatMenuPanel<MatMenuItem>
}

// @public
export class MatMenuContent implements OnDestroy {
export class MatMenuContent extends _MatMenuContentBase {
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<MatMenuContent, "ng-template[matMenuContent]", never, {}, {}, never>;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<MatMenuContent, never>;
}

// @public (undocumented)
export class _MatMenuContentBase implements OnDestroy {
constructor(_template: TemplateRef<any>, _componentFactoryResolver: ComponentFactoryResolver, _appRef: ApplicationRef, _injector: Injector, _viewContainerRef: ViewContainerRef, _document: any, _changeDetectorRef?: ChangeDetectorRef | undefined);
attach(context?: any): void;
readonly _attached: Subject<void>;
detach(): void;
// (undocumented)
ngOnDestroy(): void;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<MatMenuContent, "ng-template[matMenuContent]", never, {}, {}, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<_MatMenuContentBase, never, never, {}, {}, never>;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<MatMenuContent, never>;
static ɵfac: i0.ɵɵFactoryDeclaration<_MatMenuContentBase, never>;
}

// @public
Expand All @@ -185,16 +193,6 @@ export interface MatMenuDefaultOptions {
yPosition: MenuPositionY;
}

// @public
export class _MatMenuDirectivesModule {
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<_MatMenuDirectivesModule, never>;
// (undocumented)
static ɵinj: i0.ɵɵInjectorDeclaration<_MatMenuDirectivesModule>;
// (undocumented)
static ɵmod: i0.ɵɵNgModuleDeclaration<_MatMenuDirectivesModule, [typeof i1.MatMenuTrigger, typeof i2.MatMenuContent], never, [typeof i1.MatMenuTrigger, typeof i2.MatMenuContent, typeof i3.MatCommonModule]>;
}

// @public
export class MatMenuItem extends _MatMenuItemBase implements FocusableOption, CanDisable, CanDisableRipple, AfterViewInit, OnDestroy {
constructor(_elementRef: ElementRef<HTMLElement>,
Expand Down Expand Up @@ -236,7 +234,7 @@ export class MatMenuModule {
// (undocumented)
static ɵinj: i0.ɵɵInjectorDeclaration<MatMenuModule>;
// (undocumented)
static ɵmod: i0.ɵɵNgModuleDeclaration<MatMenuModule, [typeof i4.MatMenu, typeof i5.MatMenuItem], [typeof i6.CommonModule, typeof i3.MatCommonModule, typeof i3.MatRippleModule, typeof i7.OverlayModule, typeof _MatMenuDirectivesModule], [typeof i8.CdkScrollableModule, typeof i3.MatCommonModule, typeof i4.MatMenu, typeof i5.MatMenuItem, typeof _MatMenuDirectivesModule]>;
static ɵmod: i0.ɵɵNgModuleDeclaration<MatMenuModule, [typeof i1.MatMenu, typeof i2.MatMenuItem, typeof i3.MatMenuTrigger, typeof i4.MatMenuContent], [typeof i5.CommonModule, typeof i6.MatCommonModule, typeof i6.MatRippleModule, typeof i7.OverlayModule], [typeof i8.CdkScrollableModule, typeof i6.MatCommonModule, typeof i1.MatMenu, typeof i2.MatMenuItem, typeof i3.MatMenuTrigger, typeof i4.MatMenuContent]>;
}

// @public
Expand Down Expand Up @@ -280,7 +278,15 @@ export interface MatMenuPanel<T = any> {
}

// @public
export class MatMenuTrigger implements AfterContentInit, OnDestroy {
export class MatMenuTrigger extends _MatMenuTriggerBase {
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<MatMenuTrigger, "[mat-menu-trigger-for], [matMenuTriggerFor]", ["matMenuTrigger"], {}, {}, never>;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<MatMenuTrigger, never>;
}

// @public (undocumented)
export class _MatMenuTriggerBase implements AfterContentInit, OnDestroy {
constructor(_overlay: Overlay, _element: ElementRef<HTMLElement>, _viewContainerRef: ViewContainerRef, scrollStrategy: any, parentMenu: MatMenuPanel, _menuItemInstance: MatMenuItem, _dir: Directionality, _focusMonitor?: FocusMonitor | undefined);
closeMenu(): void;
// @deprecated (undocumented)
Expand Down Expand Up @@ -313,9 +319,9 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
triggersSubmenu(): boolean;
updatePosition(): void;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<MatMenuTrigger, "[mat-menu-trigger-for], [matMenuTriggerFor]", ["matMenuTrigger"], { "_deprecatedMatMenuTriggerFor": "mat-menu-trigger-for"; "menu": "matMenuTriggerFor"; "menuData": "matMenuTriggerData"; "restoreFocus": "matMenuTriggerRestoreFocus"; }, { "menuOpened": "menuOpened"; "onMenuOpen": "onMenuOpen"; "menuClosed": "menuClosed"; "onMenuClose": "onMenuClose"; }, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<_MatMenuTriggerBase, never, never, { "_deprecatedMatMenuTriggerFor": "mat-menu-trigger-for"; "menu": "matMenuTriggerFor"; "menuData": "matMenuTriggerData"; "restoreFocus": "matMenuTriggerRestoreFocus"; }, { "menuOpened": "menuOpened"; "onMenuOpen": "onMenuOpen"; "menuClosed": "menuClosed"; "onMenuClose": "onMenuClose"; }, never>;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<MatMenuTrigger, [null, null, null, null, { optional: true; }, { optional: true; self: true; }, { optional: true; }, null]>;
static ɵfac: i0.ɵɵFactoryDeclaration<_MatMenuTriggerBase, [null, null, null, null, { optional: true; }, { optional: true; self: true; }, { optional: true; }, null]>;
}

// @public
Expand Down