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 4 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]",
aagash-ni marked this conversation as resolved.
Show resolved Hide resolved
"dependentChangeType": "patch"
}
aagash-ni marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 20 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.focusEditorInFirefoxEnv();
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.focusEditorInFirefoxEnv();
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.focusEditorInFirefoxEnv();
}

/**
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.focusEditorInFirefoxEnv();
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.focusEditorInFirefoxEnv();
}

/**
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.focusEditorInFirefoxEnv();
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.focusEditorInFirefoxEnv();
}

/**
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.focusEditorInFirefoxEnv();
return false;
}
return true;
Expand Down Expand Up @@ -347,6 +355,18 @@ 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 the any of the buttons clicked, the editor internally has its focus but the blinking caret disappears.
aagash-ni marked this conversation as resolved.
Show resolved Hide resolved
// As a workaround, manually triggering blur and setting focus on editor will hepls making the caret re-appears.
aagash-ni marked this conversation as resolved.
Show resolved Hide resolved
// It seems like this issue in not fixed in firefox browser yet, Created Issue https://github.com/ni/nimble/issues/1454 tracks removal of this workaround.
aagash-ni marked this conversation as resolved.
Show resolved Hide resolved
private focusEditorInFirefoxEnv(): void {
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