Skip to content

Commit

Permalink
do not rely on tab value to track previous selected tab. this allows …
Browse files Browse the repository at this point in the history
…to set isSelect directly on the tab
  • Loading branch information
miguelcobain committed Dec 15, 2017
1 parent d692555 commit 630f803
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions addon/components/paper-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import layout from '../templates/components/paper-tabs';
import { ParentMixin } from 'ember-composability-tools';
import ColorMixin from 'ember-paper/mixins/color-mixin';

const { computed, Component, String: { htmlSafe }, inject } = Ember;
const { computed, Component, String: { htmlSafe }, inject, observer } = Ember;

export default Component.extend(ParentMixin, ColorMixin, {
layout,
Expand All @@ -16,12 +16,22 @@ export default Component.extend(ParentMixin, ColorMixin, {

selected: 0, // select first tab by default

_selectedTab: computed('childComponents.@each.value', 'selected', function() {
return this.get('childComponents').findBy('value', this.get('selected'));
_selectedTab: computed('childComponents.@each.isSelected', function() {
return this.get('childComponents').findBy('isSelected');
}),

_previousSelectedTab: computed('childComponents.@each.value', 'previousSelected', function() {
return this.get('childComponents').findBy('value', this.get('previousSelected'));
_selectedTabDidChange: observer('_selectedTab', function() {
let selectedTab = this.get('_selectedTab');
let previousSelectedTab = this.get('_previousSelectedTab');

if (selectedTab === previousSelectedTab) {
return;
}

this.setMovingRight();
this.fixOffsetIfNeeded();

this.set('_previousSelectedTab', selectedTab);
}),

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

didReceiveAttrs() {
this._super(...arguments);
if (this.get('selected') !== this.get('previousSelected')) {
this.setMovingRight();
this.fixOffsetIfNeeded();
this.set('previousSelected', this.get('selected'));
}
},

didInsertElement() {
this._super(...arguments);

Expand Down

0 comments on commit 630f803

Please sign in to comment.