The switch component Blueprint (demo and documentation here) displays no border when selected/unselected. I included this component in a React component as follows:
import {Component} from "react";
import {Switch} from "@blueprintjs/core";
import React from "react";
class BPrintMain extends Component{
render(){
return (
<Switch id="switch-input-3" label="Public" disabled={false} />
)
}
}
export {BPrintMain};
When I click the switch component, it displays a border as follows:
The border remains until the focus is lost, that is, I click on something else on the page.
I am including the Blueprint css files from the css of my main componeent as follows:
@import "~@blueprintjs/core/lib/css/blueprint.css";
@import "~normalize.css";
@import "~@blueprintjs/icons/lib/css/blueprint-icons.css";
The css appears to be working for buttons, input controls etc. What am I missing? Why is the switch displaying that focus/bounding box on focus?
We can use the following approach in ReactJS to use the ReactJS Blueprint Switch Component. alignIndicator: It is used for the alignment of the indicator within the container. checked: It is used to indicate whether the control is checked or not.
Blueprint is a React-based UI toolkit for the web. It is optimized for building complex data-dense interfaces for desktop applications. Blueprint v3 releases new versions regularly. Blueprint v4.0 is coming soon! @blueprintjs/core is the primary Blueprint package on NPM and home to over 40 components.
Set the border-top-style, border-right-style, border-left-style properties of the <input> element to "hidden". To have only the bottom border, set the border-bottom-style to "groove" and then, add a background-color.
Also, you can remove the default borders on certain sides by setting them to "transparent". See another example where the outline: none; is set for <input>, <textarea> and <select> fields. How can we improve it? Thanks for your feedback!
Ok, I found the answer. Leaving it here in case someone else gets bitten by this and uses my choice of words for expressing the problem.
As explained in this github issue this is expected behaviour of browsers: display the element with focus. As the answer in the issue says, simply adding the following two lines to your app (I did it in index.js, the root of my React app) solves the problem:
import { FocusStyleManager } from "@blueprintjs/core";
FocusStyleManager.onlyShowFocusOnTabs();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With