Skip to content

Commit

Permalink
feat(tabs): Always callback setSelected. (#195)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The `onSelect` callback will now also be called when clicking on the currently active tab.
  • Loading branch information
exabugs authored and danez committed Sep 5, 2017
1 parent dc94bad commit bc1910a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
2 changes: 0 additions & 2 deletions dist/react-tabs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/react-tabs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/react-tabs.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/react-tabs.min.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/components/UncontrolledTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export default class UncontrolledTabs extends Component {
tabNodes = [];

setSelected(index, event) {
// Don't do anything if nothing has changed
if (index === this.props.selectedIndex) return;
// Check index boundary
if (index < 0 || index >= this.getTabsCount()) return;

Expand Down
34 changes: 34 additions & 0 deletions src/components/__tests__/Tabs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,40 @@ describe('<Tabs />', () => {
assertTabSelected(wrapper, 0);
});

test('should trigger onSelect handler when clicking', () => {
let wasClicked = false;
const wrapper = mount(
createTabs({
onSelect: () => {
wasClicked = true;
},
}),
);

assertTabSelected(wrapper, 0);

wrapper.childAt(0).childAt(1).simulate('click');
assertTabSelected(wrapper, 1);
expect(wasClicked).toBe(true);
});

test('should trigger onSelect handler when clicking on open tab', () => {
let wasClicked = false;
const wrapper = mount(
createTabs({
onSelect: () => {
wasClicked = true;
},
}),
);

assertTabSelected(wrapper, 0);

wrapper.childAt(0).childAt(0).simulate('click');
assertTabSelected(wrapper, 0);
expect(wasClicked).toBe(true);
});

test('should switch tabs if setState is called within onSelect', () => {
class Wrap extends React.Component {
handleSelect = () => this.setState({ foo: 'bar' });
Expand Down

0 comments on commit bc1910a

Please sign in to comment.