Skip to content

Commit

Permalink
Have the InkBar in the Tabs component honor the value prop (#8010)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreubel authored and oliviertassinari committed Sep 2, 2017
1 parent f39ffd8 commit 2e2140d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Tabs/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,11 @@ class Tabs extends Component {
});
});

const inkBar = this.state.selectedIndex !== -1 ? (
const realSelectedIndex = valueLink.value ? this.getSelectedIndex(this.props) : this.state.selectedIndex;

const inkBar = realSelectedIndex !== -1 ? (
<InkBar
left={`${width * this.state.selectedIndex}%`}
left={`${width * realSelectedIndex}%`}
width={`${width}%`}
style={inkBarStyle}
/>
Expand Down
25 changes: 25 additions & 0 deletions src/Tabs/Tabs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ describe('<Tabs />', () => {
);

assert.strictEqual(wrapper.state().selectedIndex, 0);
assert.strictEqual(wrapper.find('Tab').at(0).prop('selected'), true);
assert.strictEqual(wrapper.find('Tab').at(1).prop('selected'), false);
assert.strictEqual(wrapper.find('InkBar').prop('left'), '0%');
});
});

Expand All @@ -34,6 +37,25 @@ describe('<Tabs />', () => {
);

assert.strictEqual(wrapper.state().selectedIndex, 1);
assert.strictEqual(wrapper.find('Tab').at(0).prop('selected'), false);
assert.strictEqual(wrapper.find('Tab').at(1).prop('selected'), true);
assert.strictEqual(wrapper.find('InkBar').prop('left'), '50%');
});

it('should still use the value prop even after another tab is selected if value stays the same', () => {
const wrapper = shallowWithContext(
<Tabs value="2">
<Tab value="1" />
<Tab value="2" />
</Tabs>
);

wrapper.setState({selectedIndex: 0});

assert.strictEqual(wrapper.state().selectedIndex, 0);
assert.strictEqual(wrapper.find('Tab').at(0).prop('selected'), false);
assert.strictEqual(wrapper.find('Tab').at(1).prop('selected'), true);
assert.strictEqual(wrapper.find('InkBar').prop('left'), '50%');
});

it('should set the right tab active when the children change', () => {
Expand All @@ -52,6 +74,9 @@ describe('<Tabs />', () => {
});

assert.strictEqual(wrapper.state().selectedIndex, 0);
assert.strictEqual(wrapper.find('Tab').at(0).prop('selected'), true);
assert.strictEqual(wrapper.find('Tab').at(1).prop('selected'), false);
assert.strictEqual(wrapper.find('InkBar').prop('left'), '0%');
});
});
});

0 comments on commit 2e2140d

Please sign in to comment.