Skip to content

[v12] fix(ui-checkbox): checkbox unfocuses on click#2414

Open
git-nandor wants to merge 1 commit intov12from
INSTUI-4768_checkbox_unfocuses_on_click
Open

[v12] fix(ui-checkbox): checkbox unfocuses on click#2414
git-nandor wants to merge 1 commit intov12from
INSTUI-4768_checkbox_unfocuses_on_click

Conversation

@git-nandor
Copy link
Contributor

@git-nandor git-nandor commented Feb 19, 2026

INSTUI-4768

Bug:

When a Checkbox is wrapped in a Focusable component, clicking the checkbox causes the Focusable to lose focus unexpectedly. The root cause is that the user clicks the label element (not the hidden input directly), and the browser interprets the mousedown on the label as a focus transfer — firing a blur event on the already-focused checkbox input.
Focusable's native DOM blur listener catches this immediately and sets focused: false

Fix:

Added an onMouseDown handler to the Checkbox label that calls e.preventDefault() to suppress the browser's default focus handling, then manually restores focus to the input.

Test plan:

Try this in the doc app:

function App() {
  const [isChecked, setIsChecked] = useState(false);
  const [textVal, setTextVal] = useState("");

  return (
    <>
      <Focusable>
        {({ focused }) =>
          focused ? (
            <Checkbox
              label="label"
              checked={isChecked}
              onChange={() => setIsChecked(!isChecked)}
            />
          ) : (
            <View tabIndex={0}>
              Focus for checkbox (checked: {isChecked.toString()})
            </View>
          )
        }
      </Focusable>
      <br />
      <Focusable>
        {({ focused }) =>
          focused ? (
            <TextInput
              label="label"
              value={textVal}
              onChange={(e) => {
                setTextVal(e.target.value);
              }}
            />
          ) : (
            <View tabIndex={0}>Focus for textInput (val: {textVal})</View>
          )
        }
      </Focusable>
    </>
  );
}

  render(<App />)

@git-nandor git-nandor self-assigned this Feb 19, 2026
@github-actions
Copy link

github-actions bot commented Feb 19, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://instructure.design/pr-preview/pr-2414/

Built to branch gh-pages at 2026-02-19 13:46 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@git-nandor git-nandor force-pushed the INSTUI-4768_checkbox_unfocuses_on_click branch from 6927bf1 to aa0358b Compare February 19, 2026 13:30
@git-nandor git-nandor requested review from ToMESSKa, balzss and joyenjoyer and removed request for ToMESSKa February 19, 2026 13:32
@git-nandor git-nandor force-pushed the INSTUI-4768_checkbox_unfocuses_on_click branch from aa0358b to abcdb61 Compare February 19, 2026 13:42
@git-nandor git-nandor marked this pull request as ready for review February 19, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments