Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
How can I block double space event on macOs?

I would like to block the event that occurs when the spacebar is pressed. The point is that the user should not be able to enter an empty space in input. The problem occurs in the macOs system where the double space turns into a dot. Then, despite the fact that the input in the template has (keydown.space)="$event.preventDefault()", a dot is added to the input text with a space at the end. Is there any option to block this behavior? I also tried to edit text with setValue in the valueChanges, but then the cursor changes its position and it doesn't look nice. I will be very grateful for any suggestions.

// profile.component.ts
@Component({
  selector: 'app-profile',
  templateUrl: './profile.component.html',
  styleUrls: ['./profile.component.scss'],
})
export class ProfileComponent implements OnInit, OnDestroy {
  userEmail = new FormControl('');

  destroy$ = new Subject<void>();

  ngOnInit() {
    this.observeUserEmailValue();
  }

  ngOnDestroy(): void {
    this.destroy$.next();
    this.destroy$.unsubscribe();
  }

  observeUserEmailValue(): void {
    this.userEmail.valueChanges
      .pipe(takeUntil(this.destroy$))
      .subscribe((userEmailValue: string) => {
        this.userEmail.setValue(userEmailValue.trim(), {
          emitEvent: false,
        });
      });
  }
}

// profile.component.html
<input 
  type="email" 
  [formControl]="userEmail"
  (keydown.space)="$event.preventDefault()"
>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think the behavior you want to prevent might be on keyup, not keydown.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!