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

feat(menu): Add selected property to menu items #665

Merged
merged 2 commits into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lib/menu/menu-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
MdcMenuItems,
} from './menu';

const MENU_COMPONENTS = [
const MENU_DECLARATIONS = [
MdcMenu,
MdcMenuAnchor,
MdcMenuDivider,
Expand All @@ -19,7 +19,7 @@ const MENU_COMPONENTS = [

@NgModule({
imports: [CommonModule],
exports: [MENU_COMPONENTS],
declarations: [MENU_COMPONENTS],
exports: [MENU_DECLARATIONS],
declarations: [MENU_DECLARATIONS],
})
export class MdcMenuModule { }
33 changes: 32 additions & 1 deletion src/lib/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,21 @@ export class MdcMenu implements AfterViewInit, OnChanges, OnDestroy {
position.top ? this._setStyle(position.top, 'top') : this._removeStyle('top');
position.bottom ? this._setStyle(position.bottom, 'bottom') : this._removeStyle('bottom');
},
setMaxHeight: (height) => {
setMaxHeight: (height: string) => {
this._renderer.setStyle(this.elementRef.nativeElement, 'maxHeight', height);
},
setAttrForOptionAtIndex: (index: number, attr: string, value: string) => {
this._renderer.setAttribute(this.options.toArray()[index].elementRef.nativeElement, attr, value);
},
rmAttrForOptionAtIndex: (index: number, attr: string) => {
this._renderer.removeAttribute(this.options.toArray()[index].elementRef.nativeElement, attr);
},
addClassForOptionAtIndex: (index: number, className: string) => {
this._renderer.addClass(this.options.toArray()[index].elementRef.nativeElement, className);
},
rmClassForOptionAtIndex: (index: number, className: string) => {
this._renderer.removeClass(this.options.toArray()[index].elementRef.nativeElement, className);
}
};

private _foundation: {
Expand All @@ -233,6 +245,9 @@ export class MdcMenu implements AfterViewInit, OnChanges, OnDestroy {
setAnchorCorner(corner: Corner): void,
setAnchorMargin(): void,
setQuickOpen(quickOpen: boolean): void,
setRememberSelection(rememberSelection: boolean): void,
setSelectedIndex(index: number): void,
getSelectedIndex(): number
} = new MDCMenuFoundation(this._mdcAdapter);

constructor(
Expand All @@ -256,6 +271,18 @@ export class MdcMenu implements AfterViewInit, OnChanges, OnDestroy {
}
}

setRememberSelection(rememberSelection: boolean): void {
this._foundation.setRememberSelection(rememberSelection);
}

setSelectedIndex(index: number): void {
this._foundation.setSelectedIndex(index);
}

getSelectedIndex(): number {
return this._foundation.getSelectedIndex();
}

private _setStyle(position: string, anchorPoint: string): void {
this._renderer.setStyle(this.elementRef.nativeElement, anchorPoint, position);
}
Expand Down Expand Up @@ -322,4 +349,8 @@ export class MdcMenu implements AfterViewInit, OnChanges, OnDestroy {
setQuickOpen(quickOpen: boolean): void {
this._foundation.setQuickOpen(quickOpen);
}

setMaxHeight(height: string): void {
this._mdcAdapter.setMaxHeight(height);
}
}
3 changes: 2 additions & 1 deletion src/lib/menu/tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"strictMetadataEmit": true,
"flatModuleOutFile": "index.js",
"flatModuleId": "@angular-mdc/web/menu",
"skipTemplateCodegen": true
"skipTemplateCodegen": true,
"fullTemplateTypeCheck": true
}
}
6 changes: 6 additions & 0 deletions test/unit/menu/menu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ describe('MdcMenu', () => {
testDebugElement.nativeElement.click();
fixture.detectChanges();
});

it('#should get selected index', () => {
testInstance.setSelectedIndex(2);
fixture.detectChanges();
expect(testInstance.getSelectedIndex()).toBe(2);
});
});
});

Expand Down