Skip to content

Commit 6f64485

Browse files
author
Sasha Kondrashov
committed
tab
1 parent a10d684 commit 6f64485

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

src/modules/Tab/Tab.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ export interface StrictTabProps {
3030
* Called on tab change.
3131
*
3232
* @param {SyntheticEvent} event - React's original SyntheticEvent.
33-
* @param {object} data - The proposed new Tab.Pane.
34-
* @param {object} data.activeIndex - The new proposed activeIndex.
35-
* @param {object} data.panes - Props of the new proposed active pane.
33+
* @param {object} props - The proposed new Tab.Pane.
34+
* @param {object} props.panes - Props of the new proposed active pane.
35+
* @param {number} activeIndex - The current activeIndex.
3636
*/
37-
onTabChange?: (event: React.MouseEvent<HTMLDivElement>, data: TabProps) => void
37+
onTabChange?: (
38+
event: React.MouseEvent<HTMLDivElement>,
39+
props: TabProps,
40+
activeIndex: number,
41+
) => void
3842

3943
/**
4044
* Array of objects describing each Menu.Item and Tab.Pane:

src/modules/Tab/Tab.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const Tab = React.forwardRef(function (props, ref) {
3434
})
3535

3636
const handleItemClick = (e, { index }) => {
37-
_.invoke(props, 'onTabChange', e, { ...props, activeIndex: index })
37+
_.invoke(props, 'onTabChange', e, props, index)
3838
setActiveIndex(index)
3939
}
4040

test/specs/modules/Tab/Tab-test.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ describe('Tab', () => {
154154
})
155155

156156
describe('onTabChange', () => {
157-
it('is called with (e, { ...props, activeIndex }) a menu item is clicked', () => {
157+
it('is called when a menu item is clicked', () => {
158158
const activeIndex = 1
159-
const spy = sandbox.spy()
159+
const onTabChange = sandbox.spy()
160160
const event = { fake: 'event' }
161-
const props = { onTabChange: spy, panes }
161+
const props = { onTabChange, panes }
162162

163163
mount(<Tab {...props} />)
164164
.find('MenuItem')
@@ -167,30 +167,29 @@ describe('Tab', () => {
167167

168168
// Since React will have generated a key the returned tab won't match
169169
// exactly so match on the props instead.
170-
spy.should.have.been.calledOnce()
171-
spy.firstCall.args[0].should.have.property('fake', 'event')
172-
spy.firstCall.args[1].should.have.property('activeIndex', 1)
173-
spy.firstCall.args[1].should.have.property('onTabChange', spy)
174-
spy.firstCall.args[1].should.have.property('panes', panes)
170+
onTabChange.should.have.been.calledOnce()
171+
onTabChange.should.have.been.calledWithMatch(event, props, 1)
175172
})
176173
it('is called with the new proposed activeIndex, not the current', () => {
177-
const spy = sandbox.spy()
174+
const onTabChange = sandbox.spy()
178175

179-
const items = mount(<Tab activeIndex={-1} onTabChange={spy} panes={panes} />).find('MenuItem')
176+
const items = mount(<Tab activeIndex={-1} onTabChange={onTabChange} panes={panes} />).find(
177+
'MenuItem',
178+
)
180179

181-
spy.should.have.callCount(0)
180+
onTabChange.should.have.callCount(0)
182181

183182
items.at(0).simulate('click')
184-
spy.should.have.callCount(1)
185-
spy.lastCall.args[1].should.have.property('activeIndex', 0)
183+
onTabChange.should.have.callCount(1)
184+
onTabChange.lastCall.args[2].should.equal(0)
186185

187186
items.at(1).simulate('click')
188-
spy.should.have.callCount(2)
189-
spy.lastCall.args[1].should.have.property('activeIndex', 1)
187+
onTabChange.should.have.callCount(2)
188+
onTabChange.lastCall.args[2].should.equal(1)
190189

191190
items.at(2).simulate('click')
192-
spy.should.have.callCount(3)
193-
spy.lastCall.args[1].should.have.property('activeIndex', 2)
191+
onTabChange.should.have.callCount(3)
192+
onTabChange.lastCall.args[2].should.equal(2)
194193
})
195194
})
196195

0 commit comments

Comments
 (0)