Skip to content

Commit

Permalink
Merge pull request #1383 from odanado/fix/1124
Browse files Browse the repository at this point in the history
feat: [#1124] Implement inert attribute
  • Loading branch information
capricorn86 committed Apr 5, 2024
2 parents a026261 + 837d53d commit 5c745d4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/happy-dom/src/nodes/html-element/HTMLElement.ts
Expand Up @@ -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.
*
Expand Down
18 changes: 18 additions & 0 deletions packages/happy-dom/test/nodes/html-element/HTMLElement.test.ts
Expand Up @@ -361,6 +361,24 @@ describe('HTMLElement', () => {
});
});

describe('get inert()', () => {
it('Returns the attribute "inert".', () => {
const div = <HTMLElement>document.createElement('div');
div.setAttribute('inert', '');
expect(div.inert).toBe(true);
});
});

describe('set inert()', () => {
it('Sets the attribute "inert".', () => {
const div = <HTMLElement>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}".`, () => {
Expand Down

0 comments on commit 5c745d4

Please sign in to comment.