mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 16:21:29 +00:00
LibWeb: Add HTMLOptionsCollection selected index property
This commit is contained in:
parent
5c277144d8
commit
5decf4b33c
Notes:
sideshowbarker
2024-07-16 19:42:24 +09:00
Author: https://github.com/bplaat Commit: https://github.com/SerenityOS/serenity/commit/5decf4b33c Pull-request: https://github.com/SerenityOS/serenity/pull/23895 Reviewed-by: https://github.com/shannonbooth
|
@ -11,3 +11,4 @@
|
|||
11. 999
|
||||
12. 10
|
||||
13. 10
|
||||
14. "5 5"
|
||||
|
|
|
@ -135,5 +135,16 @@
|
|||
select.length = -10;
|
||||
return select.length;
|
||||
});
|
||||
|
||||
// 14. OptionsCollection selectedIndex is the same as select selectedIndex
|
||||
testPart(() => {
|
||||
const select = document.createElement('select');
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const option = document.createElement('option');
|
||||
if (i == 5) option.selected = true;
|
||||
select.appendChild(option);
|
||||
}
|
||||
return `${select.options.selectedIndex} ${select.selectedIndex}`;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -111,4 +111,17 @@ WebIDL::ExceptionOr<void> HTMLOptionsCollection::add(HTMLOptionOrOptGroupElement
|
|||
return {};
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#dom-htmloptionscollection-selectedindex
|
||||
WebIDL::Long HTMLOptionsCollection::selected_index() const
|
||||
{
|
||||
// The selectedIndex IDL attribute must act like the identically named attribute
|
||||
// on the select element on which the HTMLOptionsCollection is rooted.
|
||||
return verify_cast<HTMLSelectElement>(*root()).selected_index();
|
||||
}
|
||||
|
||||
void HTMLOptionsCollection::set_selected_index(WebIDL::Long index)
|
||||
{
|
||||
verify_cast<HTMLSelectElement>(*root()).set_selected_index(index);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,9 @@ public:
|
|||
|
||||
WebIDL::ExceptionOr<void> add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before = {});
|
||||
|
||||
WebIDL::Long selected_index() const;
|
||||
void set_selected_index(WebIDL::Long);
|
||||
|
||||
private:
|
||||
HTMLOptionsCollection(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter);
|
||||
|
||||
|
|
|
@ -9,5 +9,5 @@ interface HTMLOptionsCollection : HTMLCollection {
|
|||
// [CEReactions] setter undefined (unsigned long index, HTMLOptionElement? option);
|
||||
[CEReactions] undefined add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);
|
||||
// [CEReactions] undefined remove(long index);
|
||||
// attribute long selectedIndex;
|
||||
attribute long selectedIndex;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue