From 22ee66a19a8a6db602aae8c345a4f5bebb0cae36 Mon Sep 17 00:00:00 2001 From: odan Date: Sat, 6 Apr 2024 01:15:02 +0900 Subject: [PATCH] feat: [#1124] Implement inert attribute --- .../src/nodes/html-element/HTMLElement.ts | 22 +++++++++++++++++++ .../nodes/html-element/HTMLElement.test.ts | 18 +++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/packages/happy-dom/src/nodes/html-element/HTMLElement.ts b/packages/happy-dom/src/nodes/html-element/HTMLElement.ts index 0ef464a7..b553de17 100644 --- a/packages/happy-dom/src/nodes/html-element/HTMLElement.ts +++ b/packages/happy-dom/src/nodes/html-element/HTMLElement.ts @@ -398,6 +398,28 @@ export default class HTMLElement extends Element { } } + /** + * Returns inert. + * + * @returns Inert. + */ + public get inert(): boolean { + return this.getAttribute('inert') !== null; + } + + /** + * Returns inert. + * + * @param inert Inert. + */ + public set inert(inert: boolean) { + if (!inert) { + this.removeAttribute('inert'); + } else { + this.setAttribute('inert', ''); + } + } + /** * Returns language. * diff --git a/packages/happy-dom/test/nodes/html-element/HTMLElement.test.ts b/packages/happy-dom/test/nodes/html-element/HTMLElement.test.ts index 6e59ccb6..7c232458 100644 --- a/packages/happy-dom/test/nodes/html-element/HTMLElement.test.ts +++ b/packages/happy-dom/test/nodes/html-element/HTMLElement.test.ts @@ -361,6 +361,24 @@ describe('HTMLElement', () => { }); }); + describe('get inert()', () => { + it('Returns the attribute "inert".', () => { + const div = document.createElement('div'); + div.setAttribute('inert', ''); + expect(div.inert).toBe(true); + }); + }); + + describe('set inert()', () => { + it('Sets the attribute "inert".', () => { + const div = document.createElement('div'); + div.inert = true; + expect(div.getAttribute('inert')).toBe(''); + div.inert = false; + expect(div.getAttribute('inert')).toBe(null); + }); + }); + for (const property of ['lang', 'title']) { describe(`get ${property}`, () => { it(`Returns the attribute "${property}".`, () => {