cbutler
cbutler

Reputation: 1525

React Remove Bootstrap button outline

I have a react component where I am using a span with a role="button" for a checkbox and want to remove the outline that happens when you focus on the button. Does anyone know how to do this? My checkbox code is here:

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import CheckedIcon from 'react-icons/lib/md/check-box';
import UncheckedIcon from 'react-icons/lib/md/check-box-outline-blank';

const styles = {
  defaultButtonStyle: {
  backgroundColor: 'rgba(0,0,0,0)',
  },
};

export default class CheckboxBootstrap extends Component {
  render() {
    const { disabled, style, tabIndex, onChange, name, checked, size, color, value } = this.props;

return (
  <span
    className={['checkbox', disabled && 'disabled'].join(' ')}
    style={[styles.defaultButtonStyle, style]}
    role="button"
    tabIndex={disabled ? '' : tabIndex}
    onClick={() => !disabled && onChange({
      name,
      checked: !checked,
      value: checked && value,
    })}
  >
    { checked && <CheckedIcon size={size} color={color} />}
    { checked === false && (
      <UncheckedIcon size={size} color={color} />
    )}
    {this.props.children}
  </span>
);
}}

I have tried adding a style and className both as defaults and props. Does anyone have any suggestions?

Upvotes: 1

Views: 594

Answers (1)

Ross Mackay
Ross Mackay

Reputation: 972

Have you explicitly set outline: 'none' in defaultButtonStyles?

Also:

You might also want to change disabled && 'disabled' to disabled ? 'disabled' : '' to stop it adding a "false" className

In a similar vein :

{ checked && <CheckedIcon size={size} color={color} />}
{ checked === false && (<UncheckedIcon size={size} color={color} />)}

Can become:

{checked
    ? <CheckedIcon size={size} color={color} />
    : <UncheckedIcon size={size} color={color} />
}

Upvotes: 1

Related Questions