Skip to content

Commit

Permalink
[react-bootstrap#4194] - ToggleButton explicit handlers for blur and …
Browse files Browse the repository at this point in the history
…focus
  • Loading branch information
zhuber committed Oct 14, 2019
1 parent f7a7aaf commit f0af7bc
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/ToggleButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ const ToggleButton = React.forwardRef(
) => {
const [focused, setFocused] = useState(false);

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

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

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

Expand Down

0 comments on commit f0af7bc

Please sign in to comment.