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

456
Views
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 answers
Answer question

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 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!