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 b6de548 commit 4f6aed9
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/ToggleButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,9 @@ const ToggleButton = React.forwardRef(
) => {
const [focused, setFocused] = useState(false);

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

const handleBlur = e => {
if (e.target.tagName === 'INPUT') setFocused(false);
};
const toggleFocus = useCallback(e => {
if (e.target.tagName === 'INPUT') setFocused(!focused);
}, []);

return (
<Button
Expand All @@ -94,8 +90,8 @@ const ToggleButton = React.forwardRef(
autoComplete="off"
checked={!!checked}
disabled={!!disabled}
onFocus={handleFocus}
onBlur={handleBlur}
onFocus={toggleFocus}
onBlur={toggleFocus}
onChange={onChange || noop}
/>

Expand Down

0 comments on commit 4f6aed9

Please sign in to comment.