Skip to content

Commit

Permalink
fix(text-editor): move delegate logic to prosemirror adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
LucyChyzhova authored and civing committed Dec 2, 2024
1 parent fcd8d44 commit 9765130
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions etc/lime-elements.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ export namespace Components {
"contentType": 'markdown' | 'html';
// @alpha
"customElements": CustomElementDefinition[];
"disabled"?: boolean;
"language": Languages;
// @alpha
"triggerCharacters": TriggerCharacter[];
Expand Down Expand Up @@ -1631,6 +1632,7 @@ namespace JSX_2 {
"contentType"?: 'markdown' | 'html';
// @alpha
"customElements"?: CustomElementDefinition[];
"disabled"?: boolean;
"language"?: Languages;
"onChange"?: (event: LimelProsemirrorAdapterCustomEvent<string>) => void;
// @alpha
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ export class ProsemirrorAdapter {
@Prop({ reflect: true })
public language: Languages;

/**
* Set to `true` to disable the field.
* Use `disabled` to indicate that the field can normally be interacted
* with, but is currently disabled. This tells the user that if certain
* requirements are met, the field may become enabled again.
*/
@Prop({ reflect: true })
public disabled?: boolean = false;

/**
* set to private to avoid usage while under development
*
Expand Down Expand Up @@ -456,7 +465,9 @@ export class ProsemirrorAdapter {
};

private handleFocus = () => {
this.view?.focus();
if (!this.disabled) {
this.view?.focus();
}
};

private handleNewLinkSelection = (text: string, href: string) => {
Expand Down
6 changes: 3 additions & 3 deletions src/components/text-editor/text-editor.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('limel-text-editor', () => {
<span class="leading-outline"></span>
<span class="trailing-outline"></span>
</span>
<limel-prosemirror-adapter aria-controls=${ariaControls[0]} contenttype="markdown" id=${ids[0]} language="en" tabindex="0"></limel-prosemirror-adapter>
<limel-prosemirror-adapter aria-controls=${ariaControls[0]} contenttype="markdown" id=${ids[0]} language="en"></limel-prosemirror-adapter>
</mock:shadow-root>
</limel-text-editor>`);
});
Expand Down Expand Up @@ -74,14 +74,14 @@ describe('limel-text-editor', () => {
value: { attribute: 'value', value: 'test' },
disabled: { attribute: 'tabindex', value: false },
},
['test', '0'],
['test', null],
],
[
{
value: { attribute: 'value', value: 'test' },
disabled: { attribute: 'tabindex', value: true },
},
['test', '-1'],
['test', null],
],
])(
'Props get passed down into the adapter',
Expand Down
2 changes: 1 addition & 1 deletion src/components/text-editor/text-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ export class TextEditor implements FormComponent<string> {
value={this.value}
aria-controls={this.helperTextId}
id={this.editorId}
tabindex={this.disabled ? -1 : 0}
aria-disabled={this.disabled}
language={this.language}
triggerCharacters={this.triggers}
disabled={this.disabled}
/>,
this.renderPlaceholder(),
this.renderHelperLine(),
Expand Down

0 comments on commit 9765130

Please sign in to comment.