Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bridge/core/dom/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ struct DowncastTraits<Element> {
}
};

inline Element* Node::parentElement() const {
return DynamicTo<Element>(parentNode());
}

} // namespace webf

#endif // BRIDGE_ELEMENT_H
4 changes: 0 additions & 4 deletions bridge/core/dom/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ ContainerNode* Node::parentNode() const {
return ParentOrShadowHostNode();
}

Element* Node::parentElement() const {
return nullptr;
}

NodeList* Node::childNodes() {
auto* this_node = DynamicTo<ContainerNode>(this);
if (this_node)
Expand Down
14 changes: 14 additions & 0 deletions integration_tests/specs/dom/nodes/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* - Element.prototype.toBlob
* - Element.prototype.firstElementChild
* - Element.prototype.lastElementChild
* - Element.prototype.parentElement
*/
describe('DOM Element API', () => {
it('should work', () => {
Expand Down Expand Up @@ -166,6 +167,19 @@ describe('DOM Element API', () => {
expect(isObject(div)).toBe(false);
expect(Object.prototype.toString.call(div)).toBe('[object HTMLDivElement]');
});

it('should work with parentElement', () => {
const el = document.createElement('div');
document.body.appendChild(el);
el.appendChild(document.createElement('span'));
var target = el.lastElementChild?.parentElement;
expect(target.tagName).toEqual('DIV');

let childDiv = document.createDocumentFragment().appendChild(document.createElement('div'));
expect(childDiv.parentElement).toEqual(null);

expect(document.documentElement.parentElement).toEqual(null);
});
});

describe('children', () => {
Expand Down