Skip to content

Commit

Permalink
feat: support readOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Aug 1, 2024
1 parent 4d8d40c commit d70a325
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
8 changes: 8 additions & 0 deletions projects/demo/src/app/pages/starter/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[exampleText]="exampleText"
[floatingToolbar]="floating"
[formControl]="control"
[readOnly]="readOnly"
[style.max-height.px]="maxHeight"
[style.min-height.px]="minHeight"
[tools]="tools"
Expand Down Expand Up @@ -44,6 +45,13 @@ <h4>Text:</h4>
<code>formControl.disable()</code>
)
</ng-template>
<ng-template
documentationPropertyName="[readOnly]"
documentationPropertyType="boolean"
[(documentationPropertyValue)]="readOnly"
>
Readonly mode
</ng-template>
<ng-template
documentationPropertyName="[floatingToolbar]"
documentationPropertyType="boolean"
Expand Down
1 change: 1 addition & 0 deletions projects/demo/src/app/pages/starter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default class TuiEditorStarter {
];

protected tools = this.toolsVariants[0];
protected readOnly = false;
protected floating = false;
protected preview = true;

Expand Down
4 changes: 2 additions & 2 deletions projects/editor/src/components/editor/editor.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="t-toolbar-wrapper">
<tui-toolbar
*ngIf="editorLoaded && !floatingToolbar"
[disabled]="!interactive"
[disabled]="!interactive || readOnly()"
[tools]="tools"
(fileAttached)="fileAttached.emit($event)"
>
Expand Down Expand Up @@ -69,7 +69,7 @@
<div [class.t-floating]="floatingToolbar">
<tui-toolbar
*ngIf="editorLoaded && floatingToolbar"
[disabled]="!interactive"
[disabled]="!interactive || readOnly()"
[tools]="tools"
(fileAttached)="fileAttached.emit($event)"
>
Expand Down
7 changes: 6 additions & 1 deletion projects/editor/src/components/editor/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ export class TuiEditor extends TuiControl<string> implements OnDestroy {
public focused = false;
public readonly editorService = inject(TuiTiptapEditorService);

@Input('readOnly')
public set readOnlyMode(value: boolean) {
this.readOnly.set(value);
}

public get editor(): AbstractTuiEditor | null {
return this.editorService.getOriginTiptapEditor() ? this.editorService : null;
}
Expand Down Expand Up @@ -192,7 +197,7 @@ export class TuiEditor extends TuiControl<string> implements OnDestroy {
}

protected get dropdownSelectionHandler(): TuiBooleanHandler<Range> {
if (!this.focused) {
if (!this.focused || this.readOnly()) {
return TUI_FALSE_HANDLER;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import {TuiToolbarNavigationManager} from './toolbar-navigation-manager.directiv
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
role: 'toolbar',
'[class._disabled]': 'disabled',
},
})
export class TuiToolbar {
Expand Down
6 changes: 6 additions & 0 deletions projects/editor/src/components/toolbar/toolbar.style.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
@import '@taiga-ui/core/styles/taiga-ui-local.less';

:host {
&._disabled {
pointer-events: none;
}
}

.t-tools-wrapper {
.scrollbar-hidden();

Expand Down

0 comments on commit d70a325

Please sign in to comment.