Skip to content

Commit

Permalink
[react-bootstrap#4194] - Remove extra handlers in favor of usestate
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuber committed Oct 12, 2019
1 parent 35a1cff commit f627ede
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/ToggleButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,12 @@ const propTypes = {
*/
disabled: PropTypes.bool,

/**
* The focused state of the input
*/
focused: PropTypes.bool,

/**
* A callback fired when the underlying input element changes. This is passed
* directly to the `<input>` so shares the same signature as a native `onChange` event.
*/
onChange: PropTypes.func,

/**
* A callback fired when the underlying input element is focused or blurred.
*/
toggleFocus: PropTypes.func,

/**
* The value of the input, should be unique amongst it's siblings when nested in a
* `ToggleButtonGroup`.
Expand All @@ -66,22 +56,21 @@ const ToggleButton = React.forwardRef(
checked,
type,
onChange,
toggleFocus,
value,
disabled,
focused,
inputRef,
...props
},
ref,
) => {
const [focused, setFocus] = useState(false);

const handleFocus = e => {
if (e.target.tagName === 'INPUT') toggleFocus(true);
if (e.target.tagName === 'INPUT') setFocus(true);
};

const handleBlur = e => {
if (e.target.tagName === 'INPUT') toggleFocus(false);
if (e.target.tagName === 'INPUT') setFocus(false);
};

return (
Expand Down

0 comments on commit f627ede

Please sign in to comment.