Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

454
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda