mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-12 20:42:21 +00:00
LibWeb: Implement the labels
attribute for all labelable elements
This returns a `NodeList` of all the labels associated with the given element.
This commit is contained in:
parent
3dc86747f0
commit
2447a25753
Notes:
sideshowbarker
2024-07-16 20:39:14 +09:00
Author: https://github.com/tcl3
Commit: 2447a25753
Pull-request: https://github.com/SerenityOS/serenity/pull/24359
11 changed files with 89 additions and 7 deletions
36
Tests/LibWeb/Text/input/HTML/HTMLElement-labels.html
Normal file
36
Tests/LibWeb/Text/input/HTML/HTMLElement-labels.html
Normal file
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
const labelableElements = ["input", "meter", "output", "progress", "select", "textarea"];
|
||||
for (const tagName of labelableElements) {
|
||||
const element = document.createElement(tagName);
|
||||
element.id = `${tagName}Id`;
|
||||
const label = document.createElement("label")
|
||||
label.htmlFor = `${tagName}Id`;
|
||||
document.body.appendChild(label);
|
||||
document.body.appendChild(element);
|
||||
const labels = element.labels;
|
||||
println(`${tagName}.labels.length: ${labels.length}`);
|
||||
println(`${tagName}.labels[0] === label: ${labels[0] === label}`);
|
||||
println(`${tagName}.labels always returns the same object: ${labels === element.labels}`);
|
||||
document.body.removeChild(label);
|
||||
document.body.removeChild(element);
|
||||
}
|
||||
|
||||
const inputElement = document.createElement("input");
|
||||
inputElement.type = "hidden";
|
||||
inputElement.id = "inputId"
|
||||
const label = document.createElement("label")
|
||||
label.htmlFor = 'inputId';
|
||||
document.body.appendChild(label);
|
||||
document.body.appendChild(inputElement);
|
||||
println(`input.labels returns null if input type is hidden: ${inputElement.labels === null}`);
|
||||
inputElement.type = "text";
|
||||
const labels = inputElement.labels;
|
||||
println(`input.labels.length after input type is changed from hidden: ${labels.length}`);
|
||||
println(`input.labels[0] === label after input type is changed from hidden: ${labels[0] === label}`);
|
||||
document.body.removeChild(label);
|
||||
document.body.removeChild(inputElement);
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue