Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StopPropagation for events #45

Merged
merged 1 commit into from
Jun 26, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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