Skip to content

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

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

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

Conversation

@git-nandor
Copy link
Contributor

@git-nandor git-nandor commented Mar 9, 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 Mar 9, 2026
@git-nandor git-nandor requested review from balzss and joyenjoyer March 9, 2026 07:47
@git-nandor git-nandor marked this pull request as ready for review March 9, 2026 07:47
@github-actions
Copy link

github-actions bot commented Mar 9, 2026

PR Preview Action v1.8.1

QR code for preview link

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

Built to branch gh-pages at 2026-03-09 07:50 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@git-nandor git-nandor changed the title fix(ui-checkbox): prevent blur on checkbox label mousedown by manuall… [v12] fix(ui-checkbox): checkbox unfocuses on click - new v12 Mar 9, 2026
@git-nandor git-nandor requested review from HerrTopi and removed request for joyenjoyer March 9, 2026 10:39
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