8000 Add Element.Matches and Element.Closest by inkeliz · Pull Request #67 · dominikh/go-js-dom · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
10 changes: 10 additions & 0 deletions dom.go
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,7 @@ type Element interface {

Attributes() map[string]string
Class() *TokenList
Closest(string) Element
ID() string
SetID(string)
TagName() string
Expand All @@ -1527,6 +1528,7 @@ type Element interface {
GetElementsByTagNameNS(ns string, name string) []Element
HasAttribute(string) bool
HasAttributeNS(ns string, name string) bool
Matches(string) bool
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding methods to an exported interface is technically a breaking API change (if anyone happened to implement this interface externally, their implementation would no longer satisfy it).

We have no choice but to allow this, because the Element interface is meant to map to the DOM Element interface, and the policy of this package allows for such API changes.

QuerySelector(string) Element
QuerySelectorAll(string) []Element
RemoveAttribute(string)
Expand Down Expand Up @@ -1719,6 +1721,10 @@ func (e *BasicElement) SetClass(s string) {
e.Set("className", s)
}

func (e *BasicElement) Closest(s string) Element {
return wrapElement(e.Call("closest", s))
}

func (e *BasicElement) ID() string {
return e.Get("id").String()
}
Expand Down Expand Up @@ -1759,6 +1765,10 @@ func (e *BasicElement) HasAttributeNS(ns string, name string) bool {
return e.Call("hasAttributeNS", ns, name).Bool()
}

func (e *BasicElement) Matches(s string) bool {
return e.Call("matches", s).Bool()
}

func (e *BasicElement) QuerySelector(s string) Element {
return wrapElement(e.Call("querySelector", s))
}
Expand Down
0