Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rich Text Editor | Fix for Editor's blinking caret disappearing issue in Firefox browser #1455

Merged
merged 16 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
aagash-ni marked this conversation as resolved.
Show resolved Hide resolved
"type": "patch",
"comment": "Fix for Firefox caret disappearing issue",
"packageName": "@ni/nimble-components",
"email": "[email protected]",
"dependentChangeType": "patch"
}
aagash-ni marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 19 additions & 0 deletions packages/nimble-components/src/rich-text-editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class RichTextEditor extends FoundationElement {
*/
public boldButtonClick(): void {
this.tiptapEditor.chain().focus().toggleBold().run();
this.focusEditorInFirefox();
aagash-ni marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -110,6 +111,7 @@ export class RichTextEditor extends FoundationElement {
public boldButtonKeyDown(event: KeyboardEvent): boolean {
if (this.keyActivatesButton(event)) {
this.tiptapEditor.chain().focus().toggleBold().run();
this.focusEditorInFirefox();
return false;
}
return true;
Expand All @@ -121,6 +123,7 @@ export class RichTextEditor extends FoundationElement {
*/
public italicsButtonClick(): void {
this.tiptapEditor.chain().focus().toggleItalic().run();
this.focusEditorInFirefox();
}

/**
Expand All @@ -130,6 +133,7 @@ export class RichTextEditor extends FoundationElement {
public italicsButtonKeyDown(event: KeyboardEvent): boolean {
if (this.keyActivatesButton(event)) {
this.tiptapEditor.chain().focus().toggleItalic().run();
this.focusEditorInFirefox();
return false;
}
return true;
Expand All @@ -141,6 +145,7 @@ export class RichTextEditor extends FoundationElement {
*/
public bulletListButtonClick(): void {
this.tiptapEditor.chain().focus().toggleBulletList().run();
this.focusEditorInFirefox();
}

/**
Expand All @@ -150,6 +155,7 @@ export class RichTextEditor extends FoundationElement {
public bulletListButtonKeyDown(event: KeyboardEvent): boolean {
if (this.keyActivatesButton(event)) {
this.tiptapEditor.chain().focus().toggleBulletList().run();
this.focusEditorInFirefox();
return false;
}
return true;
Expand All @@ -161,6 +167,7 @@ export class RichTextEditor extends FoundationElement {
*/
public numberedListButtonClick(): void {
this.tiptapEditor.chain().focus().toggleOrderedList().run();
this.focusEditorInFirefox();
}

/**
Expand All @@ -170,6 +177,7 @@ export class RichTextEditor extends FoundationElement {
public numberedListButtonKeyDown(event: KeyboardEvent): boolean {
if (this.keyActivatesButton(event)) {
this.tiptapEditor.chain().focus().toggleOrderedList().run();
this.focusEditorInFirefox();
return false;
}
return true;
Expand Down Expand Up @@ -347,6 +355,17 @@ export class RichTextEditor extends FoundationElement {
return false;
}
}

// In Firefox browser, Once the editor gets focused, the blinking caret will be visible until we click format buttons (Bold, Italic ...) in the Firefox browser (Changing focus).
aagash-ni marked this conversation as resolved.
Show resolved Hide resolved
// But once any of the toolbar button is clicked, editor internally has its focus but the blinking caret disappears.
// As a workaround, manually triggering blur and setting focus on editor makes the blinking caret to re-appear.
private focusEditorInFirefox(): void {
aagash-ni marked this conversation as resolved.
Show resolved Hide resolved
const browserInfo = navigator.userAgent;
if (browserInfo.includes('Firefox')) {
aagash-ni marked this conversation as resolved.
Show resolved Hide resolved
this.tiptapEditor.commands.blur();
this.tiptapEditor.commands.focus();
}
}
}

const nimbleRichTextEditor = RichTextEditor.compose({
Expand Down