I want to capture the TAB key pressed inside a text-area, which works to indent the text when the user presses
Asked
Active
Viewed 334 times
0
-
Use `tab` key code which is 9 on keypress or keydown event – Sivakumar Tadisetti Jul 16 '20 at 17:40
-
Hope below link helps [Tab capture inside input](https://stackoverflow.com/questions/3362/capturing-tab-key-in-text-box) – user3802184 Jul 16 '20 at 17:44
2 Answers
0
<textarea (keydown.Tab)="onKey($event)">
...
</textarea>
.ts
onKey(e){
console.log(e); // key tab event
}

micronyks
- 54,797
- 15
- 112
- 146
0
<textarea (keydown)="onTab($event)"></textarea>
If you want to prevent to loose focus from the text area on tab you can use below code in you ts.
onTab(event) {
console.log(event);
if (event.key === 'Tab') {
event.preventDefault();
}
}

Vivek Jain
- 2,730
- 6
- 12
- 27