The issue of keypress events failing to register in the Quill Inline blot has surfaced

I created a custom Inline Blot in my Quill editor that I want to use to listen for the keypress event on nodes. However, I am facing a problem where the keypress event is never fired, even though the click event works perfectly fine.

Below is the code snippet:

const Inline = Quill.import('blots/inline');

class Editable extends Inline {
  static create(value: any) {
    const node = super.create();
    node.setAttribute('contenteditable', true);
    node.setAttribute('editable', value);
    node.addEventListener('keypress', (e: any) => {
      alert('pressed'); // this doesn't work
    });
    node.addEventListener('click', (e: any) => {
      alert('clicked'); // this works
    });
    return node;
  }
}

Editable.blotName = 'editable';
Editable.tagName = 'edit';
Quill.register(Editable);

What could be the issue here?

UPDATE

After some research, I discovered the Keyboard Module.

const bindings = {
  enter: {
    key: 13,
    shiftKey: null,
    handler: () => {
      const range = this.quill.getSelection(true);
      if (range && !this.editable(range.index)) {
        this.quill.insertText(range, '\n');
      }
    }
  }
};

this.quill = new Quill('#editor-container', {
  modules: {
    keyboard: {
      bindings
    },
    toolbar: '#toolbar'
  },
  theme: 'snow'
});

Answer №1

My investigation led me to the Keyboard Module

const keyBindings = {
  enter: {
    key: 13,
    shiftKey: null,
    handler: () => {
      const selectedRange = this.quill.getSelection(true);
      if (selectedRange && !this.editable(selectedRange.index)) {
        this.quill.insertText(selectedRange, '\n');
      }
    }
  }
};

this.quill = new Quill('#editor-container', {
  modules: {
    keyboard: {
      keyBindings
    },
    toolbar: '#toolbar'
  },
  theme: 'snow'
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular mat-icon can render intricate pictures

Embarking on my journey with Angular, I have recently delved into the world of mat icons. While I have managed to create simple mat icons successfully, I find myself stumped when attempting to tackle more intricate designs. Take for instance the image belo ...

Reactive sidenav in action with Angular

Exploring the creation of a reactive component for educational purposes, disregarding project structure =). My directory layout: app.component.html <app-header></app-header> <app-sidenav></app-sidenav> <app-footer></app ...

Unable to connect dynamic information in Angular 8 component

Error encountered during dynamic component loading DynamicBuilderComponent.ngfactory.js:198 ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: The expression has changed after it was checked. Previous value: 'ng-pristine: true'. Current ...

What is the best way to asynchronously refresh Angular 2 (or 4) PrimeNg Charts?

Issue: How can PrimeNg Charts be updated asynchronously? Situation: I have a dropdown menu that should trigger a chart refresh based on the user's selection. I believed I had the solution figured out, understanding Angular change detection and reali ...

Angular 7 TypeScript code not updating value

UPDATE: I'm having trouble with my code not updating the selected value with the new one entered in the input field "newVb". The error message says 'this.newVarde' is undefined when it reaches the line 'this.selectedVarde = this.newVard ...

Select all entities in TypeORM except for the ones where the id is not equal to a specific condition

In my scenario, I am dealing with two entities: @Entity() export class Point { @PrimaryGeneratedColumn('uuid') id: string; // some other stuff } @Entity() export class Product { ...

What is the best way to bypass using an if/else statement in TypeScript when dealing with mocha and returning undefined values

A unique spline able to be intertwined and produce a new version of itself, most of the time. export default class UniqueSpline { public intertwinedCount: number; constructor(parent?: UniqueSpline) { this.intertwinedCount = parent && pare ...

Performing an HTTP POST request in Angular 2

After starting my work with Angular 2 and TypeScript, everything was going great. However, I encountered an issue when working with a REST API (POST) where the console log displayed Response {_body: "", status: 204, statusText: "Ok", headers: Headers, type ...

Module ng2-img-tools encountered a metadata version mismatch error

Encountering an error while trying to utilize the ng2-img-tools package in conjunction with Angular4. The specific error message is: ERROR in Metadata version mismatch for module ~/client/node_modules/ng2-img-tools/dist/ng2-img-tools.d.ts, found version 4 ...

Angular can be used to compare two arrays and display the matching values in a table

Having two arrays of objects, I attempted to compare them and display the matching values in a table. While looping through both arrays and comparing them by Id, I was able to find three matches. However, when trying to display these values in a table, onl ...

Setting the default value for a useRef<HTMLInputElement> in ReactJs with Typescript

Is there a way to assign a number as the initial value on useRef<HTMLInputElement> without using useState<number>() since the field is a simple counter? Below is my TypeScript code: const MyComponent = () => { const productAmountRef = us ...

Display content from Angular 5 template directly in table without using parent template

Despite the fact that this question has been raised multiple times, I find myself in a slightly tricky situation. Here is the structure of my table: <table> <th>...</th> <app-custom-rows *ngFor="let t..." [customAttribute]="someval ...

Incorporate HTML output into a React component using Typescript

I am trying to create a class in React using Typescript that includes a method with HTML output. However, I keep encountering an error regarding the output type of the function. interface StateProps { page: string, } class App extends React.Component< ...

Exploring TypeScript Heartbeat functionality with Nodejs ws module

I am currently in the process of setting up a WebSocket server using NodeJs and TypeScript. The WebSocket server implementation I have chosen is from the ws package, supplemented by the @types/ws package for typings. My goal is to have the server send out ...

Uncover User Input in Angular Reactive Forms Before Value Modification

While it's common knowledge that the valueChanges observable in Angular Reactive Forms can be used to detect changes in input field values, have you ever wondered if there's a way to subscribe to an observable that triggers when a user presses a ...

Error Encountered While Executing Angular 4 Application Using `ng serve` Command

My project uses Spring Boot with Angular on the frontend. I recently upgraded from Angular 2 to Angular 4, and everything runs smoothly when bundled as a WAR file and deployed on Tomcat. However, during frontend development, running the application via ng ...

Understanding how to access an application selector's property during initialization

This is the initial page, generated on the backend (the json-configuration will replace 'propval' as a variable): <%- include('template/head'); %> <application [userdata]='"propval"'> Loading... </applicati ...

Facing an issue with displaying a component error in a mat-form-field in Angular 9

I am looking to develop a shared component for displaying errors in Angular Material. Here is my shared component pfa-share-error: <mat-error *ngIf="fieldErrors(fieldName).required && fieldErrors(fieldName)"> Required </mat-err ...

Unable to resolve all parameters for the createRouterScroller function in Angular routing

Just starting out with Angular routing and added the package to my Ionic project using npm i @angular/router Encountering some errors after adding appRoutes to app.modules.ts RouterModule.forRoot( appRoutes, { enableTracing: true } // <-- for d ...

Tips for Dynamically Deleting Components with ComponentResolveFactory

Looking at this Stackblitz demonstration on dynamically creating forms and utilizing componentFactoryResolver. I want to add a functionality where users can also remove the added form by clicking a button. For example, if a user clicks once, a form is ad ...