-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Open
Description
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
- Create a disabled input element
- Attach a
focusevent handler on the input using jQuery - Trigger a
focusevent 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