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

458
Visualizações
Programmatically hover Material Form Field in Angular

I have an outline MatFormField like this:

<mat-form-field appearance="outline">
  <input matInput ...>
</mat-form-field>

It shows a nice outline when hovered.

I want to create the same hovering outline effect on this element but programmatically while the user hovers another element on the page.

Is it possible to create the hover effect without actually hovering the element?

What I tried:

  • I know how to programmtically focus() the input. That is however not what I want.
  • I tried to trigger a built-in mouseenter/mouseover-event. That seemed not to work however.
  • Re-applying the styles used by angular (e.g. with ng-deep or similar) is not an option as these might change with updates.
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

One simple approach is to capture the mouseover event on the "another element on the page" and change the target's element style

html

<input (mouseover)="hover(true)" (mouseout)="hover(false)" />

<mat-form-field appearance="outline">
  <input matInput id="myInput" />
</mat-form-field>

and using a simple function

  hover(hover) {
    document.getElementById('myInput').style['border-color'] = hover
      ? 'red'
      : 'black';
  }
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