@loadsmart/loadsmart-ui 5.12.3 → 5.13.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/dist/components/Tabs/Tabs.d.ts +26 -1
- package/dist/index.js +232 -232
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Tabs/Tabs.test.tsx +31 -0
- package/src/components/Tabs/Tabs.tsx +26 -2
package/package.json
CHANGED
|
@@ -69,4 +69,35 @@ describe('Tabs', () => {
|
|
|
69
69
|
|
|
70
70
|
expect(screen.getByRole('tab', { selected: true })).toHaveTextContent('Multi-quote')
|
|
71
71
|
})
|
|
72
|
+
|
|
73
|
+
it('mounts only the visible tab when using the `lazy` prop', () => {
|
|
74
|
+
setup({
|
|
75
|
+
children: (
|
|
76
|
+
<Fragment>
|
|
77
|
+
<Tabs.Items>
|
|
78
|
+
<Tabs.Item name="tab-1" default>
|
|
79
|
+
Tabs 1
|
|
80
|
+
</Tabs.Item>
|
|
81
|
+
<Tabs.Item name="tab-2">Tabs 2</Tabs.Item>
|
|
82
|
+
</Tabs.Items>
|
|
83
|
+
<Tabs.Panels>
|
|
84
|
+
<Tabs.Panel name="tab-1" lazy>
|
|
85
|
+
first content
|
|
86
|
+
</Tabs.Panel>
|
|
87
|
+
<Tabs.Panel name="tab-2" lazy>
|
|
88
|
+
second content
|
|
89
|
+
</Tabs.Panel>
|
|
90
|
+
</Tabs.Panels>
|
|
91
|
+
</Fragment>
|
|
92
|
+
),
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
expect(screen.getByText('first content')).toBeInTheDocument()
|
|
96
|
+
expect(screen.queryByText('second content')).not.toBeInTheDocument()
|
|
97
|
+
|
|
98
|
+
fire.click(screen.getByDisplayValue('tab-2'))
|
|
99
|
+
|
|
100
|
+
expect(screen.getByText('second content')).toBeInTheDocument()
|
|
101
|
+
expect(screen.queryByText('first content')).not.toBeInTheDocument()
|
|
102
|
+
})
|
|
72
103
|
})
|
|
@@ -203,20 +203,29 @@ function PanelsItems({ children, ...props }: PanelsItemsProps) {
|
|
|
203
203
|
|
|
204
204
|
interface PanelsItemProps extends HTMLAttributes<HTMLElement> {
|
|
205
205
|
name: string
|
|
206
|
+
/**
|
|
207
|
+
* Renders the Panel.Item only when is visible
|
|
208
|
+
* @default false
|
|
209
|
+
*/
|
|
210
|
+
lazy?: boolean
|
|
206
211
|
}
|
|
207
212
|
|
|
208
|
-
function PanelsItem({ children, name, ...props }: PanelsItemProps) {
|
|
213
|
+
function PanelsItem({ children, name, lazy, ...props }: PanelsItemProps) {
|
|
209
214
|
const { activeTab } = useContext(TabContext)
|
|
210
215
|
|
|
211
216
|
const hidden = activeTab !== name
|
|
212
217
|
|
|
213
218
|
return (
|
|
214
219
|
<PanelsItemWrapper {...props} role="tabpanel" aria-hidden={hidden}>
|
|
215
|
-
{children}
|
|
220
|
+
{lazy && hidden ? null : children}
|
|
216
221
|
</PanelsItemWrapper>
|
|
217
222
|
)
|
|
218
223
|
}
|
|
219
224
|
|
|
225
|
+
PanelsItem.defaultProps = {
|
|
226
|
+
lazy: false,
|
|
227
|
+
}
|
|
228
|
+
|
|
220
229
|
export interface TabsProps extends HTMLAttributes<HTMLElement>, WithDirectionProps {
|
|
221
230
|
activeTab?: string
|
|
222
231
|
onTabChange?: (tab: string) => void
|
|
@@ -228,6 +237,21 @@ const TabsWrapper = styled.div`
|
|
|
228
237
|
}
|
|
229
238
|
`
|
|
230
239
|
|
|
240
|
+
/**
|
|
241
|
+
* @example
|
|
242
|
+
* <Tabs>
|
|
243
|
+
<Tabs.Items>
|
|
244
|
+
<Tabs.Item name="tab-1" default>
|
|
245
|
+
Tabs 1
|
|
246
|
+
</Tabs.Item>
|
|
247
|
+
<Tabs.Item name="tab-2">Tabs 2</Tabs.Item>
|
|
248
|
+
</Tabs.Items>
|
|
249
|
+
<Tabs.Panels>
|
|
250
|
+
<Tabs.Panel name="tab-1">first content</Tabs.Panel>
|
|
251
|
+
<Tabs.Panel name="tab-2">second content</Tabs.Panel>
|
|
252
|
+
</Tabs.Panels>
|
|
253
|
+
* </Tabs>
|
|
254
|
+
*/
|
|
231
255
|
function Tabs({
|
|
232
256
|
children,
|
|
233
257
|
direction = 'horizontal',
|