@@ -53,9 +53,11 @@ export interface TabsProps extends Omit<AriaTabsProps, 'className' | 'style' | '
53
53
*/
54
54
density ?: 'compact' | 'regular' ,
55
55
/**
56
- * If the tabs should only display icons and no text.
56
+ * Defines if the text within the tabs should be hidden and only the icon should be shown.
57
+ * The text is always visible when the item is collapsed into a picker.
58
+ * @default 'show'
57
59
*/
58
- isIconOnly ?: boolean
60
+ labelBehavior ?: 'show' | 'hide'
59
61
}
60
62
61
63
export interface TabProps extends Omit < AriaTabProps , 'children' | 'style' | 'className' > , StyleProps {
@@ -96,7 +98,7 @@ export const Tabs = forwardRef(function Tabs(props: TabsProps, ref: DOMRef<HTMLD
96
98
isDisabled,
97
99
disabledKeys,
98
100
orientation = 'horizontal' ,
99
- isIconOnly = false
101
+ labelBehavior = 'show'
100
102
} = props ;
101
103
let domRef = useDOMRef ( ref ) ;
102
104
let [ value , setValue ] = useControlledState ( props . selectedKey , props . defaultSelectedKey ?? null ! , props . onSelectionChange ) ;
@@ -112,7 +114,7 @@ export const Tabs = forwardRef(function Tabs(props: TabsProps, ref: DOMRef<HTMLD
112
114
disabledKeys,
113
115
selectedKey : value ,
114
116
onSelectionChange : setValue ,
115
- isIconOnly ,
117
+ labelBehavior ,
116
118
onFocus : ( ) => pickerRef . current ?. focus ( ) ,
117
119
pickerRef
118
120
} ]
@@ -141,10 +143,12 @@ const tablist = style({
141
143
compact : 24 ,
142
144
regular : 32
143
145
} ,
144
- isIconOnly : {
145
- density : {
146
- compact : 16 ,
147
- regular : 24
146
+ labelBehavior : {
147
+ hide : {
148
+ density : {
149
+ compact : 16 ,
150
+ regular : 24
151
+ }
148
152
}
149
153
}
150
154
}
@@ -170,7 +174,7 @@ const tablist = style({
170
174
} ) ;
171
175
172
176
export function TabList < T extends object > ( props : TabListProps < T > ) {
173
- let { density, isDisabled, disabledKeys, orientation, isIconOnly , onFocus} = useContext ( InternalTabsContext ) ?? { } ;
177
+ let { density, isDisabled, disabledKeys, orientation, labelBehavior , onFocus} = useContext ( InternalTabsContext ) ?? { } ;
174
178
let { showItems} = useContext ( CollapseContext ) ?? { } ;
175
179
let state = useContext ( TabListStateContext ) ;
176
180
let [ selectedTab , setSelectedTab ] = useState < HTMLElement | undefined > ( undefined ) ;
@@ -208,7 +212,7 @@ export function TabList<T extends object>(props: TabListProps<T>) {
208
212
< RACTabList
209
213
{ ...props }
210
214
ref = { tablistRef }
211
- className = { renderProps => tablist ( { ...renderProps , isIconOnly , density} ) } />
215
+ className = { renderProps => tablist ( { ...renderProps , labelBehavior , density} ) } />
212
216
{ orientation === 'horizontal' &&
213
217
< TabLine showItems = { showItems } disabledKeys = { disabledKeys } isDisabled = { isDisabled } selectedTab = { selectedTab } orientation = { orientation } density = { density } /> }
214
218
</ div >
@@ -255,7 +259,7 @@ const selectedIndicator = style({
255
259
transitionTimingFunction : 'in-out'
256
260
} ) ;
257
261
258
- function TabLine ( props : TabLineProps & { isIconOnly ?: boolean } ) {
262
+ function TabLine ( props : TabLineProps ) {
259
263
let {
260
264
disabledKeys,
261
265
isDisabled : isTabsDisabled ,
@@ -342,7 +346,9 @@ const tab = style({
342
346
flexShrink : 0 ,
343
347
transition : 'default' ,
344
348
paddingX : {
345
- isIconOnly : size ( 6 )
349
+ labelBehavior : {
350
+ hide : size ( 6 )
351
+ }
346
352
}
347
353
} , getAllowedOverrides ( ) ) ;
348
354
@@ -356,15 +362,15 @@ const icon = style({
356
362
} ) ;
357
363
358
364
export function Tab ( props : TabProps ) {
359
- let { density, isIconOnly } = useContext ( InternalTabsContext ) ?? { } ;
365
+ let { density, labelBehavior } = useContext ( InternalTabsContext ) ?? { } ;
360
366
361
367
return (
362
368
< RACTab
363
369
{ ...props }
364
370
// @ts -ignore
365
371
originalProps = { props }
366
372
style = { props . UNSAFE_style }
367
- className = { renderProps => ( props . UNSAFE_className || '' ) + tab ( { ...renderProps , density, isIconOnly } , props . styles ) } >
373
+ className = { renderProps => ( props . UNSAFE_className || '' ) + tab ( { ...renderProps , density, labelBehavior } , props . styles ) } >
368
374
{ ( {
369
375
// @ts -ignore
370
376
isMenu
@@ -380,9 +386,11 @@ export function Tab(props: TabProps) {
380
386
style ( {
381
387
order : 1 ,
382
388
display : {
383
- isIconOnly : 'none'
389
+ labelBehavior : {
390
+ hide : 'none'
391
+ }
384
392
}
385
- } ) ( { isIconOnly } )
393
+ } ) ( { labelBehavior } )
386
394
} ] ,
387
395
[ IconContext , {
388
396
render : centerBaseline ( { slot : 'icon' , styles : style ( { order : 0 } ) } ) ,
@@ -479,7 +487,7 @@ let HiddenTabs = function (props: {
479
487
let TabsMenu = ( props : { items : Array < Node < any > > , onSelectionChange : TabsProps [ 'onSelectionChange' ] } ) => {
480
488
let stringFormatter = useLocalizedStringFormatter ( intlMessages , '@react-spectrum/s2' ) ;
481
489
let { items} = props ;
482
- let { density, onSelectionChange, selectedKey, isDisabled, disabledKeys, pickerRef, isIconOnly } = useContext ( InternalTabsContext ) ;
490
+ let { density, onSelectionChange, selectedKey, isDisabled, disabledKeys, pickerRef, labelBehavior } = useContext ( InternalTabsContext ) ;
483
491
let state = useContext ( TabListStateContext ) ;
484
492
let allKeysDisabled = useMemo ( ( ) => {
485
493
return isAllTabsDisabled ( state ?. collection , disabledKeys ? new Set ( disabledKeys ) : new Set ( ) ) ;
@@ -501,7 +509,7 @@ let TabsMenu = (props: {items: Array<Node<any>>, onSelectionChange: TabsProps['o
501
509
ref = { pickerRef ? pickerRef : undefined }
502
510
isDisabled = { isDisabled || allKeysDisabled }
503
511
density = { density ! }
504
- isIconOnly = { isIconOnly }
512
+ labelBehavior = { labelBehavior }
505
513
items = { items }
506
514
disabledKeys = { disabledKeys }
507
515
selectedKey = { selectedKey }
0 commit comments