Skip to content

Commit

Permalink
Add StopPropagation for events
Browse files Browse the repository at this point in the history
  • Loading branch information
dave committed Jun 26, 2016
1 parent 28c3a9d commit a995003
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions dom.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ func (e *Element) Reconcile(oldComp Component) {
if l.callPreventDefault {
jsEvent.Call("preventDefault")
}
if l.callStopPropagation {
jsEvent.Call("stopPropagation")
}
l.Listener(&Event{Target: jsEvent.Get("target")})
}
}
Expand Down
2 changes: 1 addition & 1 deletion elem/elem.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ func TableData(markup ...vecty.Markup) *vecty.Element {
return e
}

// The HTML template element <template> is a mechanism for holding client-side content that is not to be rendered when a page is loaded but may subsequently be instantiated during runtime using JavaScript. 
// The HTML template element <template> is a mechanism for holding client-side content that is not to be rendered when a page is loaded but may subsequently be instantiated during runtime using JavaScript.
//
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template
func Template(markup ...vecty.Markup) *vecty.Element {
Expand Down
18 changes: 14 additions & 4 deletions markup.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ func Style(name string, value interface{}) Markup {
// EventListener is markup that specifies a callback function to be invoked when
// the named DOM event is fired.
type EventListener struct {
Name string
Listener func(*Event)
callPreventDefault bool
wrapper func(jsEvent *js.Object)
Name string
Listener func(*Event)
callPreventDefault bool
callStopPropagation bool
wrapper func(jsEvent *js.Object)
}

// PreventDefault prevents the default behavior of the event from occuring.
Expand All @@ -113,6 +114,15 @@ func (l *EventListener) PreventDefault() *EventListener {
return l
}

// StopPropagation prevents further propagation of the current event in the
// capturing and bubbling phases.
//
// See https://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation.
func (l *EventListener) StopPropagation() *EventListener {
l.callStopPropagation = true
return l
}

// Apply implements the Markup interface.
func (l *EventListener) Apply(element *Element) {
element.EventListeners = append(element.EventListeners, l)
Expand Down

0 comments on commit a995003

Please sign in to comment.