Articles in this section
Category / Section

How to Enable Toolbar Using Tab Key in JavaScript Rich Text Editor?

2 mins read

The default behavior of the JavaScript Rich Text Editor from Syncfusion allows users to focus on the toolbar using the ALT+F10 keyboard shortcut. However, for enhanced accessibility, it may be necessary to enable focus on the toolbar using the Tab key as well. This article outlines a custom solution to achieve this functionality.

Rich Text Editor Implementation Steps

To allow the toolbar to be focused using the Tab key, you can implement the following code snippet in your application:

HTML Structure

First, ensure you have a target element in your HTML, such as a <div>, which will serve as the container for the Rich Text Editor:

<div id="defaultRTE">
</div>

Import and Inject Required Modules

Import the necessary modules from Syncfusion and inject them into the Rich Text Editor to enable various features and functionalities.

 import {
  RichTextEditor,
  Toolbar,
  Link,
  Image,
  HtmlEditor,
  QuickToolbar,
  Table,
  Video,
  Audio,
  PasteCleanup,
} from '@syncfusion/ej2-richtexteditor';
RichTextEditor.Inject(
  Toolbar,
  Link,
  Image,
  HtmlEditor,
  QuickToolbar,
  Table,
  Video,
  Audio,
  PasteCleanup,
);

Initialize the Editor

A new instance of the Rich Text Editor is created and appended to the DOM.

// Initialize the Rich Text Editor
let defaultRTE = new RichTextEditor({});
defaultRTE.appendTo('#defaultRTE');

Keydown Event Listener

An event listener is added to the document to listen for keydown events. When the Tab key is pressed, the first button in the toolbar is focused, and the default Tab behavior is prevented.

// Add event listener for keydown events
document.addEventListener('keydown', function (e) {
  if (e.key === 'Tab') {
    // When Tab is pressed, focus the first toolbar item
    let toolbarElement = defaultRTE.element.querySelector('.e-rte-toolbar');
    if (toolbarElement) {
      let firstToolbarItem = toolbarElement.querySelector('button');
      if (firstToolbarItem) {
        firstToolbarItem.focus();
        e.preventDefault();
      }
    }
  }
});

Additional References

Conclusion

I hope you enjoyed learning how to enable toolbar using tab key in JavaScript Rich Text Editor.

You can refer to our JavaScript Rich Text Editor Feature Tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

You can also explore our JavaScript Rich Text Editor Example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page.

If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied