Skip to content

Commit

Permalink
fix(front): enter key not working in <textarea> elements
Browse files Browse the repository at this point in the history
This is because forms can eat the input, really gross. Made a global
directive so this is never an issue in the future.
  • Loading branch information
tsa96 committed Jan 20, 2025
1 parent 8c1d355 commit 4a323c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions apps/frontend/src/app/directives/textarea-allow-enter.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Directive, HostListener } from '@angular/core';

@Directive({ selector: 'textarea', standalone: true })
export class TextareaAllowEnterDirective {
@HostListener('keydown', ['$event'])
onKeyDown(event: KeyboardEvent) {
if (event.key === 'Enter') {
event.stopPropagation();
}
}
}
5 changes: 3 additions & 2 deletions apps/frontend/src/app/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { CardHeaderComponent } from './components/card/card-header.component';
import { CardBodyComponent } from './components/card/card-body.component';
import { TooltipDirective } from './directives/tooltip.directive';
import { SpinnerDirective } from './directives/spinner.directive';

import { RangePipe } from './pipes/range.pipe';
import { EnumValuePipe } from './pipes/enum-value.pipe';
import { NumberWithCommasPipe } from './pipes/number-with-commas.pipe';
Expand All @@ -26,6 +25,7 @@ import { ThousandsSuffixPipe } from './pipes/thousands-suffix.pipe';
import { TimeAgoPipe } from './pipes/time-ago.pipe';
import { TimingPipe } from './pipes/timing.pipe';
import { UnsortedKeyvaluePipe } from './pipes/unsorted-keyvalue.pipe';
import { TextareaAllowEnterDirective } from './directives/textarea-allow-enter.directive';

const SHARED = [
CommonModule,
Expand All @@ -50,7 +50,8 @@ const SHARED = [
ThousandsSuffixPipe,
TimeAgoPipe,
TimingPipe,
UnsortedKeyvaluePipe
UnsortedKeyvaluePipe,
TextareaAllowEnterDirective
];

/**
Expand Down

0 comments on commit 4a323c1

Please sign in to comment.