diff --git a/packages/happy-dom/src/nodes/html-element/HTMLElementUtility.ts b/packages/happy-dom/src/nodes/html-element/HTMLElementUtility.ts
index 4d564aaf..3fb9ce16 100644
--- a/packages/happy-dom/src/nodes/html-element/HTMLElementUtility.ts
+++ b/packages/happy-dom/src/nodes/html-element/HTMLElementUtility.ts
@@ -16,7 +16,11 @@ export default class HTMLElementUtility {
const target = element[PropertySymbol.proxy] || element;
const document = target[PropertySymbol.ownerDocument];
- if (document[PropertySymbol.activeElement] !== target || !target[PropertySymbol.isConnected]) {
+ if (
+ document[PropertySymbol.activeElement] !== target ||
+ !target[PropertySymbol.isConnected] ||
+ target.disabled
+ ) {
return;
}
@@ -53,7 +57,11 @@ export default class HTMLElementUtility {
const target = element[PropertySymbol.proxy] || element;
const document = target[PropertySymbol.ownerDocument];
- if (document[PropertySymbol.activeElement] === target || !target[PropertySymbol.isConnected]) {
+ if (
+ document[PropertySymbol.activeElement] === target ||
+ !target[PropertySymbol.isConnected] ||
+ target.disabled
+ ) {
return;
}
diff --git a/packages/happy-dom/test/nodes/html-input-element/HTMLInputElement.test.ts b/packages/happy-dom/test/nodes/html-input-element/HTMLInputElement.test.ts
index d2011c1d..450e3dbe 100644
--- a/packages/happy-dom/test/nodes/html-input-element/HTMLInputElement.test.ts
+++ b/packages/happy-dom/test/nodes/html-input-element/HTMLInputElement.test.ts
@@ -1180,6 +1180,30 @@ describe('HTMLInputElement', () => {
});
});
+ describe('disabled input', () => {
+ it("doesn't focus the input when it's disabled", () => {
+ document.body.appendChild(element);
+ element.focus();
+ expect(element).toBe(document.activeElement);
+ element.blur();
+ expect(element).not.toBe(document.activeElement);
+ element.disabled = true;
+ element.focus();
+ expect(element).not.toBe(document.activeElement);
+ });
+
+ it("doesn't blur the input when it's disabled", () => {
+ document.body.appendChild(element);
+ element.focus();
+ expect(element).toBe(document.activeElement);
+ element.blur();
+ expect(element).not.toBe(document.activeElement);
+ element.disabled = true;
+ element.blur();
+ expect(element).not.toBe(document.activeElement);
+ });
+ });
+
describe('setRangeText()', () => {
it('Sets a range text with selection mode set to "preserve".', () => {
element.value = 'TEST_VALUE';