Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I hide the border around Blueprint.js switch component?

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:

switch with bounding box

switch with bounding box

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?

like image 903
mahonya Avatar asked Oct 15 '18 10:10

mahonya


People also ask

How to use blueprint switch component in ReactJS?

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.

What is @blueprintjs?

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.

How do I hide the bottom border of an input element?

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.

How can I remove the default borders on certain sides?

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!


1 Answers

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();
like image 103
mahonya Avatar answered Oct 13 '22 20:10

mahonya