Skip to content

Commit

Permalink
fix: disable menu when content is not editable
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Dec 30, 2020
1 parent 29cbaf7 commit b7eca21
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/lib/editor.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[toolbar]="toolbar"
[editorView]="view"
*ngIf="toolbar"
[disabled]="!editable"
>
</ngx-menu>
<ngx-bubble></ngx-bubble>
Expand Down
5 changes: 5 additions & 0 deletions src/lib/editor.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ $light-gray: #f1f1f1;
}
}

.NgxEditor__Content--Disabled {
user-select: none;
pointer-events: none;
}

.NgxEditor__ImageWrapper {
position: relative;
display: inline-block;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/modules/menu/menu.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="NgxEditor__MenuBar">
<div class="NgxEditor__MenuBar" [ngClass]="{'NgxEditor--Disabled': disabled}">

<ng-container *ngFor="let toolbarItem of toolbar; let lastToolbarItem = last">
<ng-container *ngFor="let item of toolbarItem; let lastItem = last">
Expand Down
1 change: 1 addition & 0 deletions src/lib/modules/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { SharedService } from '../../services/shared/shared.service';
export class MenuComponent implements OnDestroy {
@Input() toolbar: any;
@Input() editorView: EditorView;
@Input() disabled = false;

customMenuRef: TemplateRef<any> = null;
customMenuRefSubscription: Subscription;
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/editable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ const editablePlugin = (editable = true) => {
props: {
editable(state: EditorState): boolean {
return this.getState(state);
},
attributes(state: EditorState): Record<string, string> | null {
const isEnabled = this.getState(state);

if (isEnabled) {
return null;
}

return {
class: 'NgxEditor__Content--Disabled'
};
}
}
});
Expand Down

0 comments on commit b7eca21

Please sign in to comment.