Skip to content

Commit 630f803

Browse files
committed
do not rely on tab value to track previous selected tab. this allows to set isSelect directly on the tab
1 parent d692555 commit 630f803

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

addon/components/paper-tabs.js

+15-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import layout from '../templates/components/paper-tabs';
33
import { ParentMixin } from 'ember-composability-tools';
44
import ColorMixin from 'ember-paper/mixins/color-mixin';
55

6-
const { computed, Component, String: { htmlSafe }, inject } = Ember;
6+
const { computed, Component, String: { htmlSafe }, inject, observer } = Ember;
77

88
export default Component.extend(ParentMixin, ColorMixin, {
99
layout,
@@ -16,12 +16,22 @@ export default Component.extend(ParentMixin, ColorMixin, {
1616

1717
selected: 0, // select first tab by default
1818

19-
_selectedTab: computed('childComponents.@each.value', 'selected', function() {
20-
return this.get('childComponents').findBy('value', this.get('selected'));
19+
_selectedTab: computed('childComponents.@each.isSelected', function() {
20+
return this.get('childComponents').findBy('isSelected');
2121
}),
2222

23-
_previousSelectedTab: computed('[email protected]', 'previousSelected', function() {
24-
return this.get('childComponents').findBy('value', this.get('previousSelected'));
23+
_selectedTabDidChange: observer('_selectedTab', function() {
24+
let selectedTab = this.get('_selectedTab');
25+
let previousSelectedTab = this.get('_previousSelectedTab');
26+
27+
if (selectedTab === previousSelectedTab) {
28+
return;
29+
}
30+
31+
this.setMovingRight();
32+
this.fixOffsetIfNeeded();
33+
34+
this.set('_previousSelectedTab', selectedTab);
2535
}),
2636

2737
noInkBar: false,
@@ -54,15 +64,6 @@ export default Component.extend(ParentMixin, ColorMixin, {
5464
return !this.get('shouldPaginate') && this.get('currentStretch');
5565
}),
5666

57-
didReceiveAttrs() {
58-
this._super(...arguments);
59-
if (this.get('selected') !== this.get('previousSelected')) {
60-
this.setMovingRight();
61-
this.fixOffsetIfNeeded();
62-
this.set('previousSelected', this.get('selected'));
63-
}
64-
},
65-
6667
didInsertElement() {
6768
this._super(...arguments);
6869

0 commit comments

Comments
 (0)