Skip to content

Commit

Permalink
Merge pull request #987 from joshkel/task/530-label-controls
Browse files Browse the repository at this point in the history
#530@minor: Broader support for HTMLLabelElement `control`.
  • Loading branch information
capricorn86 committed Aug 2, 2023
2 parents c89516a + e7c48a7 commit 5acbab1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Expand Up @@ -42,12 +42,9 @@ export default class HTMLLabelElement extends HTMLElement implements IHTMLLabelE
if (htmlFor) {
return <IHTMLElement>this.ownerDocument.getElementById(htmlFor);
}
for (const child of this.children) {
if (child.tagName === 'INPUT') {
return <IHTMLElement>child;
}
}
return null;
return <IHTMLElement>(
this.querySelector('button,input:not([type="hidden"]),meter,output,progress,select,textarea')
);
}

/**
Expand Down
Expand Up @@ -50,6 +50,21 @@ describe('HTMLLabelElement', () => {
element.appendChild(input);
expect(element.control === input).toBe(true);
});

it('Returns a descendent input if "for" attribute is not defined.', () => {
const input = document.createElement('input');
const span = document.createElement('span');
span.appendChild(input);
element.appendChild(span);
expect(element.control === input).toBe(true);
});

it('Does not return hidden inputs.', () => {
const input = document.createElement('input');
input.setAttribute('type', 'hidden');
element.appendChild(input);
expect(element.control).toBe(null);
});
});

describe('get form()', () => {
Expand Down

0 comments on commit 5acbab1

Please sign in to comment.