@targetprocess/tabs 12.20.1-alpha.4 → 12.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -45
- package/README.md +15 -15
- package/ShowMore.jsx +152 -152
- package/TabInner.jsx +90 -90
- package/TabPanel.jsx +27 -27
- package/Tabs.jsx +499 -499
- package/TabsPrint.jsx +95 -95
- package/__tests__/Tabs.tests.jsx +263 -263
- package/dist/tabs.es.js +36 -22
- package/dist/tabs.js +36 -22
- package/index.js +4 -1
- package/package.json +5 -5
- package/shared-proptype.js +10 -7
- package/style/index.css +145 -142
package/__tests__/Tabs.tests.jsx
CHANGED
|
@@ -1,263 +1,263 @@
|
|
|
1
|
-
/* eslint-env jest */
|
|
2
|
-
import React, {useLayoutEffect} from 'react'
|
|
3
|
-
import {mount} from 'enzyme'
|
|
4
|
-
import {Tabs} from '../Tabs'
|
|
5
|
-
import {TabPanel} from '../TabPanel'
|
|
6
|
-
|
|
7
|
-
describe('Tabs', () => {
|
|
8
|
-
beforeAll(() => {
|
|
9
|
-
window.ResizeObserver = class ResizeObserver {
|
|
10
|
-
observe() {}
|
|
11
|
-
unobserve() {}
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
it('should render tabs and only render content of an active tab', () => {
|
|
16
|
-
const wrapper = mount(
|
|
17
|
-
<Tabs activeTabId="2">
|
|
18
|
-
<Tabs.Tab header="fooTab" id="1">
|
|
19
|
-
foo
|
|
20
|
-
</Tabs.Tab>
|
|
21
|
-
<Tabs.Tab header="barTab" id="2">
|
|
22
|
-
bar
|
|
23
|
-
</Tabs.Tab>
|
|
24
|
-
</Tabs>
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
const tabItems = wrapper.find('.tabs__header__tab-item')
|
|
28
|
-
expect(tabItems).toHaveLength(2)
|
|
29
|
-
expect(tabItems.at(0).text()).toBe('fooTab')
|
|
30
|
-
expect(tabItems.at(1).text()).toBe('barTab')
|
|
31
|
-
expect(tabItems.at(1).hasClass('tabs__header__tab-item--active')).toBeTruthy()
|
|
32
|
-
|
|
33
|
-
const tabsContent = wrapper.find('.tabs__body')
|
|
34
|
-
expect(tabsContent.text()).toEqual('bar')
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it('should trigger onActiveTabChanged on click but only for non-disabled tabs', () => {
|
|
38
|
-
const onActiveTabChangedMock = jest.fn()
|
|
39
|
-
|
|
40
|
-
const wrapper = mount(
|
|
41
|
-
<Tabs activeTabId="1" onActiveTabChanged={onActiveTabChangedMock}>
|
|
42
|
-
<Tabs.Tab header="fooTab" id="1">
|
|
43
|
-
foo
|
|
44
|
-
</Tabs.Tab>
|
|
45
|
-
<Tabs.Tab header="barTab" id="2">
|
|
46
|
-
bar
|
|
47
|
-
</Tabs.Tab>
|
|
48
|
-
<Tabs.Tab header="barTab" id="3" disabled>
|
|
49
|
-
bar
|
|
50
|
-
</Tabs.Tab>
|
|
51
|
-
</Tabs>
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
const tabs = wrapper.find('.tabs__header__tab-item')
|
|
55
|
-
tabs.at(1).simulate('click')
|
|
56
|
-
expect(onActiveTabChangedMock).toHaveBeenCalledWith('2')
|
|
57
|
-
|
|
58
|
-
onActiveTabChangedMock.mockClear()
|
|
59
|
-
tabs.at(2).simulate('click')
|
|
60
|
-
expect(onActiveTabChangedMock).not.toHaveBeenCalled()
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('should handle header as render prop', () => {
|
|
64
|
-
const renderHeader = ({onResize}) => {
|
|
65
|
-
expect(typeof onResize).toBe('function')
|
|
66
|
-
return 'testTab'
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const wrapper = mount(
|
|
70
|
-
<Tabs activeTabId="1">
|
|
71
|
-
<Tabs.Tab header={renderHeader} id="1">
|
|
72
|
-
foo
|
|
73
|
-
</Tabs.Tab>
|
|
74
|
-
</Tabs>
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
const tabItems = wrapper.find('.tabs__header__tab-item')
|
|
78
|
-
expect(tabItems.at(0).text()).toBe('testTab')
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
it('should use provided `activeTabId` in controlled model as `activeTabId`', () => {
|
|
82
|
-
const onActiveTabChangedMock = jest.fn()
|
|
83
|
-
|
|
84
|
-
const wrapper = mount(
|
|
85
|
-
<Tabs activeTabId="2" onActiveTabChanged={onActiveTabChangedMock}>
|
|
86
|
-
<Tabs.Tab header="fooTab" id="1">
|
|
87
|
-
foo
|
|
88
|
-
</Tabs.Tab>
|
|
89
|
-
<Tabs.Tab header="barTab" id="2">
|
|
90
|
-
bar
|
|
91
|
-
</Tabs.Tab>
|
|
92
|
-
<Tabs.Tab header="bazTab" id="3" disabled>
|
|
93
|
-
baz
|
|
94
|
-
</Tabs.Tab>
|
|
95
|
-
</Tabs>
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
const tabPanel = wrapper.find(TabPanel)
|
|
99
|
-
expect(tabPanel).toHaveLength(1)
|
|
100
|
-
expect(tabPanel.text()).toEqual('bar')
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('should open first tab in controlled mode if `activeTabId` is not provided', () => {
|
|
104
|
-
const onActiveTabChangedMock = jest.fn()
|
|
105
|
-
|
|
106
|
-
const wrapper = mount(
|
|
107
|
-
<Tabs activeTabId={null} onActiveTabChanged={onActiveTabChangedMock}>
|
|
108
|
-
<Tabs.Tab header="fooTab" id="1">
|
|
109
|
-
foo
|
|
110
|
-
</Tabs.Tab>
|
|
111
|
-
<Tabs.Tab header="barTab" id="2">
|
|
112
|
-
bar
|
|
113
|
-
</Tabs.Tab>
|
|
114
|
-
<Tabs.Tab header="bazTab" id="3" disabled>
|
|
115
|
-
baz
|
|
116
|
-
</Tabs.Tab>
|
|
117
|
-
</Tabs>
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
const tabPanel = wrapper.find(TabPanel)
|
|
121
|
-
expect(tabPanel).toHaveLength(1)
|
|
122
|
-
expect(tabPanel.text()).toEqual('foo')
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
it('should open first tab if provided `activeTabId` does not exists', () => {
|
|
126
|
-
const onActiveTabChangedMock = jest.fn()
|
|
127
|
-
|
|
128
|
-
const wrapper = mount(
|
|
129
|
-
<Tabs activeTabId="4" onActiveTabChanged={onActiveTabChangedMock}>
|
|
130
|
-
<Tabs.Tab header="fooTab" id="1">
|
|
131
|
-
foo
|
|
132
|
-
</Tabs.Tab>
|
|
133
|
-
<Tabs.Tab header="barTab" id="2">
|
|
134
|
-
bar
|
|
135
|
-
</Tabs.Tab>
|
|
136
|
-
<Tabs.Tab header="bazTab" id="3">
|
|
137
|
-
baz
|
|
138
|
-
</Tabs.Tab>
|
|
139
|
-
</Tabs>
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
const tabPanel = wrapper.find(TabPanel)
|
|
143
|
-
expect(tabPanel).toHaveLength(1)
|
|
144
|
-
expect(tabPanel.text()).toEqual('foo')
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
it('should open first tab if `activeTabId` is not provided', () => {
|
|
148
|
-
const onActiveTabChangedMock = jest.fn()
|
|
149
|
-
|
|
150
|
-
const wrapper = mount(
|
|
151
|
-
<Tabs onActiveTabChanged={onActiveTabChangedMock}>
|
|
152
|
-
<Tabs.Tab header="fooTab" id="1">
|
|
153
|
-
foo
|
|
154
|
-
</Tabs.Tab>
|
|
155
|
-
<Tabs.Tab header="barTab" id="2">
|
|
156
|
-
bar
|
|
157
|
-
</Tabs.Tab>
|
|
158
|
-
<Tabs.Tab header="bazTab" id="3">
|
|
159
|
-
baz
|
|
160
|
-
</Tabs.Tab>
|
|
161
|
-
</Tabs>
|
|
162
|
-
)
|
|
163
|
-
|
|
164
|
-
const tabPanel = wrapper.find(TabPanel)
|
|
165
|
-
expect(tabPanel).toHaveLength(1)
|
|
166
|
-
expect(tabPanel.text()).toEqual('foo')
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
const MountedCallbackComponent = props => {
|
|
170
|
-
useLayoutEffect(() => {
|
|
171
|
-
props.mounted()
|
|
172
|
-
return () => props.unmounted()
|
|
173
|
-
}, [])
|
|
174
|
-
|
|
175
|
-
return <div />
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
it('should correctly work with cacheOpenedTabs in uncontrolled mode', () => {
|
|
179
|
-
const mounted1 = jest.fn()
|
|
180
|
-
const unmounted1 = jest.fn()
|
|
181
|
-
const mounted2 = jest.fn()
|
|
182
|
-
const unmounted2 = jest.fn()
|
|
183
|
-
const mounted3 = jest.fn()
|
|
184
|
-
const unmounted3 = jest.fn()
|
|
185
|
-
|
|
186
|
-
const wrapper = mount(
|
|
187
|
-
// negative showMoreWidthBuffer makes sure that all tab headers remain mounted
|
|
188
|
-
<Tabs cacheOpenedTabs showMoreWidthBuffer={-9999}>
|
|
189
|
-
<Tabs.Tab header="1" id="1">
|
|
190
|
-
<div>
|
|
191
|
-
<MountedCallbackComponent mounted={mounted1} unmounted={unmounted1} />
|
|
192
|
-
</div>
|
|
193
|
-
</Tabs.Tab>
|
|
194
|
-
<Tabs.Tab header="2" id="2">
|
|
195
|
-
<div>
|
|
196
|
-
<MountedCallbackComponent mounted={mounted2} unmounted={unmounted2} />
|
|
197
|
-
</div>
|
|
198
|
-
</Tabs.Tab>
|
|
199
|
-
<Tabs.Tab header="3" id="3">
|
|
200
|
-
<div>
|
|
201
|
-
<MountedCallbackComponent mounted={mounted3} unmounted={unmounted3} />
|
|
202
|
-
</div>
|
|
203
|
-
</Tabs.Tab>
|
|
204
|
-
</Tabs>
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
expect(mounted1).toHaveBeenCalledTimes(1)
|
|
208
|
-
|
|
209
|
-
wrapper.find('#tab-2.tabs__header__tab-item').simulate('click')
|
|
210
|
-
|
|
211
|
-
expect(mounted2).toHaveBeenCalled()
|
|
212
|
-
expect(unmounted1).not.toHaveBeenCalled()
|
|
213
|
-
|
|
214
|
-
wrapper.find('#tab-1.tabs__header__tab-item').simulate('click')
|
|
215
|
-
|
|
216
|
-
expect(mounted1).toHaveBeenCalledTimes(1)
|
|
217
|
-
expect(unmounted2).not.toHaveBeenCalled()
|
|
218
|
-
|
|
219
|
-
expect(mounted3).not.toHaveBeenCalled()
|
|
220
|
-
expect(unmounted3).not.toHaveBeenCalled()
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
it('should correctly cache tabs in controlled mode', () => {
|
|
224
|
-
const mounted1 = jest.fn()
|
|
225
|
-
const unmounted1 = jest.fn()
|
|
226
|
-
const mounted2 = jest.fn()
|
|
227
|
-
const unmounted2 = jest.fn()
|
|
228
|
-
const mounted3 = jest.fn()
|
|
229
|
-
const unmounted3 = jest.fn()
|
|
230
|
-
|
|
231
|
-
const wrapper = mount(
|
|
232
|
-
<Tabs cacheOpenedTabs activeTabId="1">
|
|
233
|
-
<Tabs.Tab header="1" id="1">
|
|
234
|
-
<div>
|
|
235
|
-
<MountedCallbackComponent mounted={mounted1} unmounted={unmounted1} />
|
|
236
|
-
</div>
|
|
237
|
-
</Tabs.Tab>
|
|
238
|
-
<Tabs.Tab header="2" id="2">
|
|
239
|
-
<div>
|
|
240
|
-
<MountedCallbackComponent mounted={mounted2} unmounted={unmounted2} />
|
|
241
|
-
</div>
|
|
242
|
-
</Tabs.Tab>
|
|
243
|
-
<Tabs.Tab header="3" id="3">
|
|
244
|
-
<div>
|
|
245
|
-
<MountedCallbackComponent mounted={mounted3} unmounted={unmounted3} />
|
|
246
|
-
</div>
|
|
247
|
-
</Tabs.Tab>
|
|
248
|
-
</Tabs>
|
|
249
|
-
)
|
|
250
|
-
|
|
251
|
-
expect(mounted1).toHaveBeenCalledTimes(1)
|
|
252
|
-
|
|
253
|
-
wrapper.setProps({activeTabId: '2'})
|
|
254
|
-
|
|
255
|
-
expect(mounted2).toHaveBeenCalled()
|
|
256
|
-
expect(unmounted1).not.toHaveBeenCalled()
|
|
257
|
-
|
|
258
|
-
wrapper.setProps({activeTabId: '1'})
|
|
259
|
-
|
|
260
|
-
expect(mounted1).toHaveBeenCalledTimes(1)
|
|
261
|
-
expect(unmounted2).not.toHaveBeenCalled()
|
|
262
|
-
})
|
|
263
|
-
})
|
|
1
|
+
/* eslint-env jest */
|
|
2
|
+
import React, {useLayoutEffect} from 'react'
|
|
3
|
+
import {mount} from 'enzyme'
|
|
4
|
+
import {Tabs} from '../Tabs'
|
|
5
|
+
import {TabPanel} from '../TabPanel'
|
|
6
|
+
|
|
7
|
+
describe('Tabs', () => {
|
|
8
|
+
beforeAll(() => {
|
|
9
|
+
window.ResizeObserver = class ResizeObserver {
|
|
10
|
+
observe() {}
|
|
11
|
+
unobserve() {}
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('should render tabs and only render content of an active tab', () => {
|
|
16
|
+
const wrapper = mount(
|
|
17
|
+
<Tabs activeTabId="2">
|
|
18
|
+
<Tabs.Tab header="fooTab" id="1">
|
|
19
|
+
foo
|
|
20
|
+
</Tabs.Tab>
|
|
21
|
+
<Tabs.Tab header="barTab" id="2">
|
|
22
|
+
bar
|
|
23
|
+
</Tabs.Tab>
|
|
24
|
+
</Tabs>
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
const tabItems = wrapper.find('.tabs__header__tab-item')
|
|
28
|
+
expect(tabItems).toHaveLength(2)
|
|
29
|
+
expect(tabItems.at(0).text()).toBe('fooTab')
|
|
30
|
+
expect(tabItems.at(1).text()).toBe('barTab')
|
|
31
|
+
expect(tabItems.at(1).hasClass('tabs__header__tab-item--active')).toBeTruthy()
|
|
32
|
+
|
|
33
|
+
const tabsContent = wrapper.find('.tabs__body')
|
|
34
|
+
expect(tabsContent.text()).toEqual('bar')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('should trigger onActiveTabChanged on click but only for non-disabled tabs', () => {
|
|
38
|
+
const onActiveTabChangedMock = jest.fn()
|
|
39
|
+
|
|
40
|
+
const wrapper = mount(
|
|
41
|
+
<Tabs activeTabId="1" onActiveTabChanged={onActiveTabChangedMock}>
|
|
42
|
+
<Tabs.Tab header="fooTab" id="1">
|
|
43
|
+
foo
|
|
44
|
+
</Tabs.Tab>
|
|
45
|
+
<Tabs.Tab header="barTab" id="2">
|
|
46
|
+
bar
|
|
47
|
+
</Tabs.Tab>
|
|
48
|
+
<Tabs.Tab header="barTab" id="3" disabled>
|
|
49
|
+
bar
|
|
50
|
+
</Tabs.Tab>
|
|
51
|
+
</Tabs>
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
const tabs = wrapper.find('.tabs__header__tab-item')
|
|
55
|
+
tabs.at(1).simulate('click')
|
|
56
|
+
expect(onActiveTabChangedMock).toHaveBeenCalledWith('2')
|
|
57
|
+
|
|
58
|
+
onActiveTabChangedMock.mockClear()
|
|
59
|
+
tabs.at(2).simulate('click')
|
|
60
|
+
expect(onActiveTabChangedMock).not.toHaveBeenCalled()
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('should handle header as render prop', () => {
|
|
64
|
+
const renderHeader = ({onResize}) => {
|
|
65
|
+
expect(typeof onResize).toBe('function')
|
|
66
|
+
return 'testTab'
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const wrapper = mount(
|
|
70
|
+
<Tabs activeTabId="1">
|
|
71
|
+
<Tabs.Tab header={renderHeader} id="1">
|
|
72
|
+
foo
|
|
73
|
+
</Tabs.Tab>
|
|
74
|
+
</Tabs>
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
const tabItems = wrapper.find('.tabs__header__tab-item')
|
|
78
|
+
expect(tabItems.at(0).text()).toBe('testTab')
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('should use provided `activeTabId` in controlled model as `activeTabId`', () => {
|
|
82
|
+
const onActiveTabChangedMock = jest.fn()
|
|
83
|
+
|
|
84
|
+
const wrapper = mount(
|
|
85
|
+
<Tabs activeTabId="2" onActiveTabChanged={onActiveTabChangedMock}>
|
|
86
|
+
<Tabs.Tab header="fooTab" id="1">
|
|
87
|
+
foo
|
|
88
|
+
</Tabs.Tab>
|
|
89
|
+
<Tabs.Tab header="barTab" id="2">
|
|
90
|
+
bar
|
|
91
|
+
</Tabs.Tab>
|
|
92
|
+
<Tabs.Tab header="bazTab" id="3" disabled>
|
|
93
|
+
baz
|
|
94
|
+
</Tabs.Tab>
|
|
95
|
+
</Tabs>
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
const tabPanel = wrapper.find(TabPanel)
|
|
99
|
+
expect(tabPanel).toHaveLength(1)
|
|
100
|
+
expect(tabPanel.text()).toEqual('bar')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('should open first tab in controlled mode if `activeTabId` is not provided', () => {
|
|
104
|
+
const onActiveTabChangedMock = jest.fn()
|
|
105
|
+
|
|
106
|
+
const wrapper = mount(
|
|
107
|
+
<Tabs activeTabId={null} onActiveTabChanged={onActiveTabChangedMock}>
|
|
108
|
+
<Tabs.Tab header="fooTab" id="1">
|
|
109
|
+
foo
|
|
110
|
+
</Tabs.Tab>
|
|
111
|
+
<Tabs.Tab header="barTab" id="2">
|
|
112
|
+
bar
|
|
113
|
+
</Tabs.Tab>
|
|
114
|
+
<Tabs.Tab header="bazTab" id="3" disabled>
|
|
115
|
+
baz
|
|
116
|
+
</Tabs.Tab>
|
|
117
|
+
</Tabs>
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
const tabPanel = wrapper.find(TabPanel)
|
|
121
|
+
expect(tabPanel).toHaveLength(1)
|
|
122
|
+
expect(tabPanel.text()).toEqual('foo')
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it('should open first tab if provided `activeTabId` does not exists', () => {
|
|
126
|
+
const onActiveTabChangedMock = jest.fn()
|
|
127
|
+
|
|
128
|
+
const wrapper = mount(
|
|
129
|
+
<Tabs activeTabId="4" onActiveTabChanged={onActiveTabChangedMock}>
|
|
130
|
+
<Tabs.Tab header="fooTab" id="1">
|
|
131
|
+
foo
|
|
132
|
+
</Tabs.Tab>
|
|
133
|
+
<Tabs.Tab header="barTab" id="2">
|
|
134
|
+
bar
|
|
135
|
+
</Tabs.Tab>
|
|
136
|
+
<Tabs.Tab header="bazTab" id="3">
|
|
137
|
+
baz
|
|
138
|
+
</Tabs.Tab>
|
|
139
|
+
</Tabs>
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
const tabPanel = wrapper.find(TabPanel)
|
|
143
|
+
expect(tabPanel).toHaveLength(1)
|
|
144
|
+
expect(tabPanel.text()).toEqual('foo')
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it('should open first tab if `activeTabId` is not provided', () => {
|
|
148
|
+
const onActiveTabChangedMock = jest.fn()
|
|
149
|
+
|
|
150
|
+
const wrapper = mount(
|
|
151
|
+
<Tabs onActiveTabChanged={onActiveTabChangedMock}>
|
|
152
|
+
<Tabs.Tab header="fooTab" id="1">
|
|
153
|
+
foo
|
|
154
|
+
</Tabs.Tab>
|
|
155
|
+
<Tabs.Tab header="barTab" id="2">
|
|
156
|
+
bar
|
|
157
|
+
</Tabs.Tab>
|
|
158
|
+
<Tabs.Tab header="bazTab" id="3">
|
|
159
|
+
baz
|
|
160
|
+
</Tabs.Tab>
|
|
161
|
+
</Tabs>
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
const tabPanel = wrapper.find(TabPanel)
|
|
165
|
+
expect(tabPanel).toHaveLength(1)
|
|
166
|
+
expect(tabPanel.text()).toEqual('foo')
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
const MountedCallbackComponent = props => {
|
|
170
|
+
useLayoutEffect(() => {
|
|
171
|
+
props.mounted()
|
|
172
|
+
return () => props.unmounted()
|
|
173
|
+
}, [])
|
|
174
|
+
|
|
175
|
+
return <div />
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
it('should correctly work with cacheOpenedTabs in uncontrolled mode', () => {
|
|
179
|
+
const mounted1 = jest.fn()
|
|
180
|
+
const unmounted1 = jest.fn()
|
|
181
|
+
const mounted2 = jest.fn()
|
|
182
|
+
const unmounted2 = jest.fn()
|
|
183
|
+
const mounted3 = jest.fn()
|
|
184
|
+
const unmounted3 = jest.fn()
|
|
185
|
+
|
|
186
|
+
const wrapper = mount(
|
|
187
|
+
// negative showMoreWidthBuffer makes sure that all tab headers remain mounted
|
|
188
|
+
<Tabs cacheOpenedTabs showMoreWidthBuffer={-9999}>
|
|
189
|
+
<Tabs.Tab header="1" id="1">
|
|
190
|
+
<div>
|
|
191
|
+
<MountedCallbackComponent mounted={mounted1} unmounted={unmounted1} />
|
|
192
|
+
</div>
|
|
193
|
+
</Tabs.Tab>
|
|
194
|
+
<Tabs.Tab header="2" id="2">
|
|
195
|
+
<div>
|
|
196
|
+
<MountedCallbackComponent mounted={mounted2} unmounted={unmounted2} />
|
|
197
|
+
</div>
|
|
198
|
+
</Tabs.Tab>
|
|
199
|
+
<Tabs.Tab header="3" id="3">
|
|
200
|
+
<div>
|
|
201
|
+
<MountedCallbackComponent mounted={mounted3} unmounted={unmounted3} />
|
|
202
|
+
</div>
|
|
203
|
+
</Tabs.Tab>
|
|
204
|
+
</Tabs>
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
expect(mounted1).toHaveBeenCalledTimes(1)
|
|
208
|
+
|
|
209
|
+
wrapper.find('#tab-2.tabs__header__tab-item').simulate('click')
|
|
210
|
+
|
|
211
|
+
expect(mounted2).toHaveBeenCalled()
|
|
212
|
+
expect(unmounted1).not.toHaveBeenCalled()
|
|
213
|
+
|
|
214
|
+
wrapper.find('#tab-1.tabs__header__tab-item').simulate('click')
|
|
215
|
+
|
|
216
|
+
expect(mounted1).toHaveBeenCalledTimes(1)
|
|
217
|
+
expect(unmounted2).not.toHaveBeenCalled()
|
|
218
|
+
|
|
219
|
+
expect(mounted3).not.toHaveBeenCalled()
|
|
220
|
+
expect(unmounted3).not.toHaveBeenCalled()
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
it('should correctly cache tabs in controlled mode', () => {
|
|
224
|
+
const mounted1 = jest.fn()
|
|
225
|
+
const unmounted1 = jest.fn()
|
|
226
|
+
const mounted2 = jest.fn()
|
|
227
|
+
const unmounted2 = jest.fn()
|
|
228
|
+
const mounted3 = jest.fn()
|
|
229
|
+
const unmounted3 = jest.fn()
|
|
230
|
+
|
|
231
|
+
const wrapper = mount(
|
|
232
|
+
<Tabs cacheOpenedTabs activeTabId="1">
|
|
233
|
+
<Tabs.Tab header="1" id="1">
|
|
234
|
+
<div>
|
|
235
|
+
<MountedCallbackComponent mounted={mounted1} unmounted={unmounted1} />
|
|
236
|
+
</div>
|
|
237
|
+
</Tabs.Tab>
|
|
238
|
+
<Tabs.Tab header="2" id="2">
|
|
239
|
+
<div>
|
|
240
|
+
<MountedCallbackComponent mounted={mounted2} unmounted={unmounted2} />
|
|
241
|
+
</div>
|
|
242
|
+
</Tabs.Tab>
|
|
243
|
+
<Tabs.Tab header="3" id="3">
|
|
244
|
+
<div>
|
|
245
|
+
<MountedCallbackComponent mounted={mounted3} unmounted={unmounted3} />
|
|
246
|
+
</div>
|
|
247
|
+
</Tabs.Tab>
|
|
248
|
+
</Tabs>
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
expect(mounted1).toHaveBeenCalledTimes(1)
|
|
252
|
+
|
|
253
|
+
wrapper.setProps({activeTabId: '2'})
|
|
254
|
+
|
|
255
|
+
expect(mounted2).toHaveBeenCalled()
|
|
256
|
+
expect(unmounted1).not.toHaveBeenCalled()
|
|
257
|
+
|
|
258
|
+
wrapper.setProps({activeTabId: '1'})
|
|
259
|
+
|
|
260
|
+
expect(mounted1).toHaveBeenCalledTimes(1)
|
|
261
|
+
expect(unmounted2).not.toHaveBeenCalled()
|
|
262
|
+
})
|
|
263
|
+
})
|
package/dist/tabs.es.js
CHANGED
|
@@ -190,10 +190,14 @@ function styleInject(css, ref) {
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
var css = ".tabs__header__tabs__12-
|
|
194
|
-
var styles = {"tabs__header":"tabs__header__tabs__12-
|
|
193
|
+
var css = "/*********************************************************************\n* © Copyright IBM Corp. 2024\n*********************************************************************/\n.tabs__header__tabs__12-21-0 {\n font-size: var(--FontSizeDefault, 13px);\n line-height: 1.23;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-orient: vertical;\n -webkit-box-direction: normal;\n -ms-flex-direction: column;\n flex-direction: column;\n }\n.tabs__header__title__tabs__12-21-0 {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n padding-right: var(--SpaceSM, 12px);\n }\n.tabs__header__container__tabs__12-21-0 {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n position: relative;\n }\n.tabs__header__line__tabs__12-21-0 {\n height: 1px;\n position: relative;\n background-color: var(--ControlBorderColorDefault, rgba(64, 66, 73, 0.2));\n }\n.tabs__header__line__slider__tabs__12-21-0 {\n height: 1px;\n position: absolute;\n background-color: var(--DrBlack, #000000);\n -webkit-transition: left 0.3s, width 0.3s, right 0.3s, width 0.3s;\n transition: left 0.3s, width 0.3s, right 0.3s, width 0.3s;\n }\n.tabs__header__tab-item__tabs__12-21-0 {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n font-weight: var(--FontWeightSemibold, 600);\n color: var(--FontColorLightGray, rgba(0, 0, 0, 0.45));\n cursor: pointer;\n outline: none;\n white-space: nowrap;\n padding: var(--SpaceS, 8px);\n }\n.tabs__header__tab-item__tabs__12-21-0:first-child {\n padding-left: 0;\n }\n.tabs__header__tab-item__tabs__12-21-0:not(:first-child) {\n padding-left: var(--SpaceSM, 12px);\n }\n.tabs__header__tab-item__tabs__12-21-0:not(:last-child) {\n padding-right: var(--SpaceSM, 12px);\n }\n.tabs__header__tab-item__tabs__12-21-0:hover,\n .tabs__header__tab-item--active__tabs__12-21-0 {\n color: var(--DrBlack, #000000);\n }\n.tabs__header__tab-item__tabs__12-21-0:focus {\n outline: 0;\n border-radius: 1px;\n -webkit-box-shadow: var(--ControlBoxShadowFocusDefault, 0 0 0 3px rgba(0, 126, 255, 0.2));\n box-shadow: var(--ControlBoxShadowFocusDefault, 0 0 0 3px rgba(0, 126, 255, 0.2));\n }\n.tabs__header__tab-item--disabled__tabs__12-21-0 {\n color: var(--FontColorLightGray, rgba(0, 0, 0, 0.45));\n cursor: default;\n }\n.tabs__header__tabs__showmore__wrapper__tabs__12-21-0 {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n width: 100%;\n height: 100%;\n }\n.tabs__header__tabs__showmore__tabs__12-21-0 {\n padding: 0;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n outline: none;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n cursor: pointer;\n white-space: nowrap;\n position: relative;\n width: var(--ControlHeightLarge, 28px);\n }\n.tabs__header__tabs__showmore__label__tabs__12-21-0 {\n border-radius: var(--BorderRadiusDefault, 3px);\n width: var(--ControlHeightLarge, 28px);\n height: var(--ControlHeightLarge, 28px);\n z-index: 1;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-flex: 1;\n -ms-flex: 1 0 auto;\n flex: 1 0 auto;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n }\n.tabs__header__tabs__showmore__label__tabs__12-21-0:hover {\n background-color: var(--ButtonBackgroundHover, #ECECED);\n }\n.tabs__header__tabs__showmore__label--selected__tabs__12-21-0 svg * {\n fill: var(--DrBlack, #000000);\n }\n.tabs__header__tabs__showmore-menu__tabs__12-21-0 {\n outline: none;\n -webkit-box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\n box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\n border-radius: var(--BorderRadiusL, 4px);\n position: absolute;\n right: 0;\n padding: var(--SpaceXS, 4px) 0;\n left: auto;\n top: calc(100% + var(--SpaceXS, 4px)/2);\n bottom: auto;\n z-index: 11;\n background: var(--MrWhite, #FFFFFF);\n display: none;\n }\n.tabs__header__tabs__showmore-menu--opened__tabs__12-21-0 {\n display: block;\n }\n.tabs__header__tabs__showmore-menu__tabs__12-21-0 .tabs__header__tab-item__tabs__12-21-0 {\n padding: var(--SpaceS, 8px) var(--SpaceSM, 12px);\n }\n.tabs__header__tabs__showmore-menu__tabs__12-21-0 .tabs__header__tab-item__tabs__12-21-0:hover:not(.tabs__header__tab-item--active__tabs__12-21-0) {\n background: var(--Active100, #FCF5DB);\n }\n.tabs__header__tabs__showmore-menu__tabs__12-21-0 .tabs__header__tab-item--active__tabs__12-21-0 {\n background: var(--Active300, #F7E292);\n }\n";
|
|
194
|
+
var styles = {"tabs__header":"tabs__header__tabs__12-21-0","tabs__header__title":"tabs__header__title__tabs__12-21-0","tabs__header__container":"tabs__header__container__tabs__12-21-0","tabs__header__line":"tabs__header__line__tabs__12-21-0","tabs__header__line__slider":"tabs__header__line__slider__tabs__12-21-0","tabs__header__tab-item":"tabs__header__tab-item__tabs__12-21-0","tabs__header__tab-item--active":"tabs__header__tab-item--active__tabs__12-21-0","tabs__header__tab-item--disabled":"tabs__header__tab-item--disabled__tabs__12-21-0","tabs__header__tabs__showmore__wrapper":"tabs__header__tabs__showmore__wrapper__tabs__12-21-0","tabs__header__tabs__showmore":"tabs__header__tabs__showmore__tabs__12-21-0","tabs__header__tabs__showmore__label":"tabs__header__tabs__showmore__label__tabs__12-21-0","tabs__header__tabs__showmore__label--selected":"tabs__header__tabs__showmore__label--selected__tabs__12-21-0","tabs__header__tabs__showmore-menu":"tabs__header__tabs__showmore-menu__tabs__12-21-0","tabs__header__tabs__showmore-menu--opened":"tabs__header__tabs__showmore-menu--opened__tabs__12-21-0"};
|
|
195
195
|
styleInject(css);
|
|
196
196
|
|
|
197
|
+
/*********************************************************************
|
|
198
|
+
* © Copyright IBM Corp. 2024
|
|
199
|
+
*********************************************************************/
|
|
200
|
+
|
|
197
201
|
/* should be the same for Popover, all props are cut after build, so we needed to copy them */
|
|
198
202
|
var showMorePopoverProps = PropTypes.shape({
|
|
199
203
|
trackScroll: PropTypes.bool,
|
|
@@ -444,6 +448,9 @@ _defineProperty(TabInner, "defaultProps", {
|
|
|
444
448
|
disabled: false
|
|
445
449
|
});
|
|
446
450
|
|
|
451
|
+
/*********************************************************************
|
|
452
|
+
* © Copyright IBM Corp. 2024
|
|
453
|
+
*********************************************************************/
|
|
447
454
|
var debounce = function debounce(callback, time) {
|
|
448
455
|
var interval = null;
|
|
449
456
|
return function () {
|
|
@@ -552,6 +559,9 @@ var TabsPrint = function TabsPrint(props) {
|
|
|
552
559
|
}));
|
|
553
560
|
};
|
|
554
561
|
|
|
562
|
+
/*********************************************************************
|
|
563
|
+
* © Copyright IBM Corp. 2024
|
|
564
|
+
*********************************************************************/
|
|
555
565
|
var generateId = function generateId(prefix) {
|
|
556
566
|
return "".concat(prefix).concat(Math.random().toString(36).substring(7));
|
|
557
567
|
};
|
|
@@ -572,26 +582,26 @@ Tab.propTypes = {
|
|
|
572
582
|
disabled: PropTypes.bool
|
|
573
583
|
};
|
|
574
584
|
|
|
575
|
-
/**
|
|
576
|
-
* Tabs component is an aggregate root for several content panes
|
|
577
|
-
* (via Tabs.Tab component), each with its own children, and a header
|
|
578
|
-
* to switch between them.
|
|
579
|
-
*
|
|
580
|
-
* Each `<Tab />` must have a `header` (that can be arbitary react element but
|
|
581
|
-
* is most commonly just a string), `id` and regular children.
|
|
582
|
-
*
|
|
583
|
-
* Top-level `<Tabs />` can work in either controlled or uncontrolled mode.
|
|
584
|
-
* In controlled mode, it uses `initialActiveTabId` to determine which
|
|
585
|
-
* tab is open by default, and then manually manageschanging tabs
|
|
586
|
-
* on appropriate header clicks.
|
|
587
|
-
* In uncontrolled mode, it uses `activeTabId` prop to determine which tab
|
|
588
|
-
* is open and exposes `onActiveTabChanged` callback that is invoked each time
|
|
589
|
-
* a user clicks on a tab.
|
|
590
|
-
*
|
|
591
|
-
* By default, `<Tabs />` will shrink its tab headers to fit the parent element. Tab
|
|
592
|
-
* headers which don't fit into the parent are rendered inside Show More popover.
|
|
593
|
-
* In order to disable this behavior and allow `<Tabs/>` to occupy as much space as it needs
|
|
594
|
-
* to render all tab headers, set `shrinkToParent` prop to `false`
|
|
585
|
+
/**
|
|
586
|
+
* Tabs component is an aggregate root for several content panes
|
|
587
|
+
* (via Tabs.Tab component), each with its own children, and a header
|
|
588
|
+
* to switch between them.
|
|
589
|
+
*
|
|
590
|
+
* Each `<Tab />` must have a `header` (that can be arbitary react element but
|
|
591
|
+
* is most commonly just a string), `id` and regular children.
|
|
592
|
+
*
|
|
593
|
+
* Top-level `<Tabs />` can work in either controlled or uncontrolled mode.
|
|
594
|
+
* In controlled mode, it uses `initialActiveTabId` to determine which
|
|
595
|
+
* tab is open by default, and then manually manageschanging tabs
|
|
596
|
+
* on appropriate header clicks.
|
|
597
|
+
* In uncontrolled mode, it uses `activeTabId` prop to determine which tab
|
|
598
|
+
* is open and exposes `onActiveTabChanged` callback that is invoked each time
|
|
599
|
+
* a user clicks on a tab.
|
|
600
|
+
*
|
|
601
|
+
* By default, `<Tabs />` will shrink its tab headers to fit the parent element. Tab
|
|
602
|
+
* headers which don't fit into the parent are rendered inside Show More popover.
|
|
603
|
+
* In order to disable this behavior and allow `<Tabs/>` to occupy as much space as it needs
|
|
604
|
+
* to render all tab headers, set `shrinkToParent` prop to `false`
|
|
595
605
|
**/
|
|
596
606
|
|
|
597
607
|
var Tabs = /*#__PURE__*/function (_React$Component) {
|
|
@@ -1024,4 +1034,8 @@ _defineProperty(Tabs, "defaultProps", {
|
|
|
1024
1034
|
});
|
|
1025
1035
|
Tabs.Tab = Tab;
|
|
1026
1036
|
|
|
1037
|
+
/*********************************************************************
|
|
1038
|
+
* © Copyright IBM Corp. 2024
|
|
1039
|
+
*********************************************************************/
|
|
1040
|
+
|
|
1027
1041
|
export { Tabs };
|