Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove outline in focus in Joy UI?

Tags:

reactjs

joy-ui

I'm having issues removing the outline from the Textarea component, but it does not work.
This is what it looks like:

Text area with outline

I tried:

<Textarea className={style.textarea} 
sx={{outline:'none', border:'none',
'&:focus':{outline:'none', border:'none'}}}/>

// From CSS file
.textarea:focus {
  outline:none,
  border:none
}
like image 388
Reuven Ostrofsky Avatar asked Oct 25 '25 16:10

Reuven Ostrofsky


2 Answers

You can override the CSS variables --Textarea-focusedHighlight in the sx prop:

<Textarea
  placeholder="Type in here…"
  defaultValue="Try to put text longer than 4 lines."
  minRows={2}
  maxRows={4}
  sx={{
    "--Textarea-focusedHighlight": "transparent"
  }}
/>

Or in a CSS file:

.MuiTextarea-root {
  --Textarea-focusedHighlight: transparent;
}

See: https://codesandbox.io/s/stoic-sunset-gyw4k2?file=/demo.tsx

I will add it to the docs.

like image 52
siriwatknp Avatar answered Oct 27 '25 05:10

siriwatknp


I realized that, there is a "Joy-focused" class that is added to the className of the root div when it's textArea child is focused. Now the next thing of course is to be able to stop the "Joy-focused" class to be added to the root div. The class could have been added via an onFocus event on the child textArea. So i tried to override the focus event handler of the textArea joy component via its onFocus prop. It didn't prevent the "Joy-focused" class to be added to the root div of the textArea component anyway.

This is a capture of the component and its corresponding classnames when textArea is not given focus

This is a capture of the component and its corresponding classnames when textArea is given focus

You will notice the the presence of "Joy-focused" in the classname of the root div of the textArea joy component when it is given focus.

like image 40
Alex Christian Takam Avatar answered Oct 27 '25 05:10

Alex Christian Takam