File tree 2 files changed +17
-9
lines changed
2 files changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ export function Tabs(props: T.Props) {
17
17
contentClassName,
18
18
items,
19
19
hideTabsIfSingle = false ,
20
+ allowEmpty = false ,
20
21
onChange,
21
22
renderAll,
22
23
activeId : initialId ,
@@ -33,16 +34,21 @@ export function Tabs(props: T.Props) {
33
34
}
34
35
} , [ initialId ] ) ;
35
36
36
- const onTabClick = useCallback ( ( e , { id, onClick } = { } as T . Item ) => {
37
- // @ts -ignore
38
- if ( onClick && ! onClick ( e ) ) {
39
- e . peventDefault ( ) ;
40
- return ;
41
- }
37
+ const onTabClick = useCallback (
38
+ ( e , { id, onClick } = { } as T . Item ) => {
39
+ // @ts -ignore
40
+ if ( onClick && ! onClick ( e ) ) {
41
+ e . peventDefault ( ) ;
42
+ return ;
43
+ }
44
+
45
+ const newId = allowEmpty && id === activeId ? null : id ;
42
46
43
- setActiveId ( id ) ;
44
- onChange ?.( id ) ;
45
- } , [ ] ) ;
47
+ setActiveId ( newId ) ;
48
+ onChange ?.( newId ) ;
49
+ } ,
50
+ [ activeId ]
51
+ ) ;
46
52
47
53
const tabsContent = [ ] ;
48
54
const tabsButtons = items . map ( ( params : T . Item ) => {
Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ export type Props = {
23
23
contentClassName ?: string ;
24
24
items : Item [ ] ;
25
25
hideTabsIfSingle ?: boolean ;
26
+ // Allow to unselect tab, so no content will be rendered
27
+ allowEmpty ?: boolean ;
26
28
activeId ?: ID ;
27
29
onChange : ( id : ID ) => void ;
28
30
renderAll ?: boolean ;
You can’t perform that action at this time.
0 commit comments