Skip to content

Commit 26dc214

Browse files
Morgulmarcosmoura
authored andcommitted
add 'changed' event to mdBottomBar. (#296)
Now we fire off an event when the active item changes, just like mdTabs. Additionally, this moves activation logic to mdBottomBar, instead of each mdBottomBarItem. It made the change easier to implement, and seems a bit cleaner, though that's subjective.
1 parent d080cdd commit 26dc214

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

docs/src/pages/components/BottomBar.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@
3030
</md-table-row>
3131
</md-table-body>
3232
</md-table>
33+
34+
<md-table slot="events">
35+
<md-table-header>
36+
<md-table-row>
37+
<md-table-head>Name</md-table-head>
38+
<md-table-head>Value</md-table-head>
39+
<md-table-head>Description</md-table-head>
40+
</md-table-row>
41+
</md-table-header>
42+
43+
<md-table-body>
44+
<md-table-row>
45+
<md-table-cell>change</md-table-cell>
46+
<md-table-cell>Receive the item index</md-table-cell>
47+
<md-table-cell>Triggered when an item is activated.</md-table-cell>
48+
</md-table-row>
49+
</md-table-body>
50+
</md-table>
3351
</api-table>
3452

3553
<api-table name="md-bottom-bar-item">

src/components/mdBottomBar/mdBottomBar.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818
classes() {
1919
return this.mdShift ? 'md-shift' : 'md-fixed';
2020
}
21+
},
22+
methods: {
23+
setActive(item) {
24+
this.$children.forEach((child) => {
25+
child.active = child === item;
26+
});
27+
28+
this.$emit('change', this.$children.findIndex((i) => i === item));
29+
}
2130
}
2231
};
2332
</script>

src/components/mdBottomBar/mdBottomBarItem.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@
4747
},
4848
methods: {
4949
setActive(active) {
50-
this.$parent.$children.forEach((item) => {
51-
item.active = false;
52-
});
53-
54-
this.active = !!active;
50+
if (active) {
51+
this.$parent.setActive(this);
52+
}
5553
}
5654
},
5755
mounted() {

0 commit comments

Comments
 (0)