1

I am working on ReactJS web app, and I am adding specific outline style, but the outline shows up when a user clicks on it using a mouse. How can I make the outline to appear only for tabbing?

const Test = styled.div`
 &:focus {
  outline: 1px solid red;
 }
`;
Apple Pie
  • 93
  • 3
  • 13
  • Possible duplicate of [Enable :focus only on keyboard use (or tab press)](https://stackoverflow.com/questions/31402576/enable-focus-only-on-keyboard-use-or-tab-press) – joeytwiddle Apr 02 '18 at 06:17

2 Answers2

1

There is already an excellent answer to this question: Enable :focus only on keyboard use (or tab press)

Take a look, the answer is very detailed. have fun coding.

Sitian Liu
  • 1,156
  • 10
  • 14
0

Use focus-active pseudo-class. Check MDN documentation for that.

const Test = styled.div`
 &:focus-visible {        /* <--- HERE IS THE CHANGE */
  outline: 1px solid red;
 }
`;

As Sitian Liu said, check this answer for a deep answer.