title: How can I block double space event on macOs?
body: <p>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 <code>(keydown.space)=&quot;$event.preventDefault()&quot;</code>, 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 <code>setValue</code> in the <code>valueChanges</code>, but then the cursor changes its position and it doesn't look nice. I will be very grateful for any suggestions.</p>
  <pre><code>// 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&lt;void&gt;();
  
    ngOnInit() {
      this.observeUserEmailValue();
    }
  
    ngOnDestroy(): void {
      this.destroy$.next();
      this.destroy$.unsubscribe();
    }
  
    observeUserEmailValue(): void {
      this.userEmail.valueChanges
        .pipe(takeUntil(this.destroy$))
        .subscribe((userEmailValue: string) =&gt; {
          this.userEmail.setValue(userEmailValue.trim(), {
            emitEvent: false,
          });
        });
    }
  }
  
  // profile.component.html
  &lt;input 
    type=&quot;email&quot; 
    [formControl]=&quot;userEmail&quot;
    (keydown.space)=&quot;$event.preventDefault()&quot;
  &gt;
  </code></pre>