Skip to content

focus event fires on disabled inputs #5620

@bobanjongis

Description

@bobanjongis

Problem Description

Triggering focus on an input element causes a focus event to be emitted even when the input element is disabled.
This is a regression introduced with jQuery 3.7 - the bug is reproducible on v3.7.0 and v3.7.1.

Steps to reproduce the problem

  1. Create a disabled input element
  2. Attach a focus event handler on the input using jQuery
  3. Trigger a focus event on the input using jQuery

This can be observed with the following code snippet, where clicking the button triggers the focus event on the disabled input, and hence the assertion fails.

<input id="theDisabledInput" disabled />
<button onclick="focusTheDisabledInput()">Focus the disabled input</button>

<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script>
    $("#theDisabledInput").on("focus", (event) => {
        console.assert(!event.target.disabled, "'focus' event fired on a disabled input element!");
    });

    function focusTheDisabledInput() {
        $("#theDisabledInput").focus();
    }
</script>

Note: it is important to both attach the event listener and trigger the event using jQuery, in order to be able to reproduce the issue

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions