Skip to content

Commit

Permalink
fix: allow disabling menu component
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Dec 28, 2020
1 parent 0fd4f42 commit 998ca3c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/lib/editor.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<ngx-menu
[toolbar]="toolbar"
[editorView]="view"
*ngIf="toolbar"
>
</ngx-menu>
<ngx-bubble></ngx-bubble>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class NgxEditorComponent implements ControlValueAccessor, OnInit, OnDestr
}

get toolbar(): Toolbar {
return this.config.menu.toolbar;
return this.config.menu?.toolbar;
}

writeValue(value: object | null): void {
Expand Down
26 changes: 14 additions & 12 deletions src/lib/editor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,20 @@ export class NgxEditorService {
export const provideMyServiceOptions = (config?: NgxEditorConfig): NgxEditorServiceConfig => {
let menu: Menu;

if (!config.menu) {
menu = DEFAULT_MENU;
} else if (Array.isArray(config.menu)) {
menu = {
...DEFAULT_MENU,
toolbar: config.menu,
};
} else {
menu = {
...DEFAULT_MENU,
...config.menu,
};
if (config.menu !== null) {
if (!config.menu) {
menu = DEFAULT_MENU;
} else if (Array.isArray(config.menu)) {
menu = {
...DEFAULT_MENU,
toolbar: config.menu,
};
} else {
menu = {
...DEFAULT_MENU,
...config.menu,
};
}
}

return {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ export interface NgxEditorConfig {
schema?: Schema;
plugins?: Plugin[];
nodeViews?: NodeViews;
menu?: Menu | Toolbar;
menu?: null | Menu | Toolbar;
locals?: Partial<Record<LocalsKeys, string>>;
}

0 comments on commit 998ca3c

Please sign in to comment.