Created
          July 20, 2022 18:37 
        
      - 
      
 - 
        
Save riapacheco/4b9fc59a98fb99e5732c0e8c60e8e760 to your computer and use it in GitHub Desktop.  
    Keydown Method that Enables Tabbing in Textarea Elements
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <textarea | |
| (keydown)="enableTabbing($event)"> | |
| </textarea> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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