Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
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 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda