To remove the outline:
This is happening because the paragraph element takes the default browser outline on focus. You can change the code to this to fix this. I have removed the outline that's being added on focus to the paragraph element:
class Hello extends React.Component {
render() {
return <div > Hello {
this.props.name
} < /div>;
}
}
ReactDOM.render( <
div >
<
p tabIndex = {-1
}
style = {
{
outline: "none"
}
}
onKeyDown = {
event => alert(event.keyCode)
} >
Click to focus, then hit a key. <
/p>
<
/div>,
document.getElementById('container')
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
Alternatively, you can add this in your css file:
p {
outline: none;
}
To change the outline color:
As @Akiba suggested, in your css file you could add border instead. Borders are much more flexible than outline (Although it is possible to just style the outline, it would not be a recommended approach for many reasons).
p {
outline: none; //Removes outline
border: 1px solid red; //Sets 1px solid red border
padding: 5px; //optionally add padding to space it out
}