Skip to content

Instantly share code, notes, and snippets.

@riapacheco
Created July 20, 2022 18:37
Show Gist options
  • Save riapacheco/4b9fc59a98fb99e5732c0e8c60e8e760 to your computer and use it in GitHub Desktop.
Save riapacheco/4b9fc59a98fb99e5732c0e8c60e8e760 to your computer and use it in GitHub Desktop.
Keydown Method that Enables Tabbing in Textarea Elements
<textarea
(keydown)="enableTabbing($event)">
</textarea>
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
enableTabbing(event: any): any {
console.log(event);
if (event.key == 'Tab') {
event.preventDefault();
const start = event.target.selectionStart;
const end = event.target.selectionEnd;
event.target.value =
event.target.value.substring(0, start) +
' ' +
' ' +
event.target.value.substring(end);
event.target.selectionStart = event.target.selectionEnd = start + 1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment