Skip to content

Commit

Permalink
#5706 listener options: bubble
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiu committed Sep 10, 2024
1 parent 626feab commit c4ad81d
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions resources/data/deck/learnneo/pages/guides/events/DomEvents.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,51 @@ They do, when clicking on the white inner div.

Try it: In case you remove the `delegate` inside the source view,
we will get logs when clicking on the blue div too.

### bubble

We can prevent listeners from bubbling upwards:

<pre data-neo>
import Container from '../container/Base.mjs';

class MainView extends Container {
static config = {
className: 'Guides.domevents4.MainView',
layout : {ntype:'vbox', align:'start'},
style : {padding: '1em'},

items: [{
module: Container,
style : {backgroundColor: '#3E63DD', padding: '3em'},

domListeners: [
{click: 'up.onDivClick'}
],

items: [{
cls : 'inner-div',
style: {backgroundColor: '#FFF', width: '5em', height: '3em'},

domListeners: [
{click: 'up.onInnerDivClick', bubble: false}
]
}]
}]
}

onDivClick(data) {
Neo.Main.log({value: `Outer Div Click ${data.component.id}`})
}

onInnerDivClick(data) {
Neo.Main.log({value: `Inner Div Click ${data.component.id}`})
}
}
MainView = Neo.setupClass(MainView);
</pre>

Clicking on the inner (white) div will only trigger the inner listener and you will get one log.

Try it: In case you remove `bubble: false` inside the source view,
we will get 2 logs when clicking on the inner div.

0 comments on commit c4ad81d

Please sign in to comment.