@@ -29,7 +29,7 @@ import {
29
29
import { centerBaseline } from './CenterBaseline' ;
30
30
import { Collection , DOMRef , DOMRefValue , FocusableRef , FocusableRefValue , Key , Node , Orientation , RefObject } from '@react-types/shared' ;
31
31
import { createContext , forwardRef , Fragment , ReactNode , useCallback , useContext , useEffect , useMemo , useRef , useState } from 'react' ;
32
- import { focusRing , style } from '../style' with { type : 'macro' } ;
32
+ import { focusRing , size , style } from '../style' with { type : 'macro' } ;
33
33
import { getAllowedOverrides , StyleProps , StylesPropWithHeight , UnsafeStyles } from './style-utils' with { type : 'macro' } ;
34
34
import { IconContext } from './Icon' ;
35
35
// @ts -ignore
@@ -55,7 +55,7 @@ export interface TabsProps extends Omit<AriaTabsProps, 'className' | 'style' | '
55
55
/**
56
56
* If the tabs should only display icons and no text.
57
57
*/
58
- iconOnly ?: boolean
58
+ isIconOnly ?: boolean
59
59
}
60
60
61
61
export interface TabProps extends Omit < AriaTabProps , 'children' | 'style' | 'className' > , StyleProps {
@@ -96,7 +96,7 @@ export const Tabs = forwardRef(function Tabs(props: TabsProps, ref: DOMRef<HTMLD
96
96
isDisabled,
97
97
disabledKeys,
98
98
orientation = 'horizontal' ,
99
- iconOnly = false
99
+ isIconOnly = false
100
100
} = props ;
101
101
let domRef = useDOMRef ( ref ) ;
102
102
let [ value , setValue ] = useControlledState ( props . selectedKey , props . defaultSelectedKey ?? null ! , props . onSelectionChange ) ;
@@ -112,7 +112,7 @@ export const Tabs = forwardRef(function Tabs(props: TabsProps, ref: DOMRef<HTMLD
112
112
disabledKeys,
113
113
selectedKey : value ,
114
114
onSelectionChange : setValue ,
115
- iconOnly ,
115
+ isIconOnly ,
116
116
onFocus : ( ) => pickerRef . current ?. focus ( ) ,
117
117
pickerRef
118
118
} ]
@@ -170,7 +170,7 @@ const tablist = style({
170
170
} ) ;
171
171
172
172
export function TabList < T extends object > ( props : TabListProps < T > ) {
173
- let { density, isDisabled, disabledKeys, orientation, iconOnly , onFocus} = useContext ( InternalTabsContext ) ?? { } ;
173
+ let { density, isDisabled, disabledKeys, orientation, isIconOnly , onFocus} = useContext ( InternalTabsContext ) ?? { } ;
174
174
let { showItems} = useContext ( CollapseContext ) ?? { } ;
175
175
let state = useContext ( TabListStateContext ) ;
176
176
let [ selectedTab , setSelectedTab ] = useState < HTMLElement | undefined > ( undefined ) ;
@@ -208,7 +208,7 @@ export function TabList<T extends object>(props: TabListProps<T>) {
208
208
< RACTabList
209
209
{ ...props }
210
210
ref = { tablistRef }
211
- className = { renderProps => tablist ( { ...renderProps , isIconOnly : iconOnly , density} ) } />
211
+ className = { renderProps => tablist ( { ...renderProps , isIconOnly, density} ) } />
212
212
{ orientation === 'horizontal' &&
213
213
< TabLine showItems = { showItems } disabledKeys = { disabledKeys } isDisabled = { isDisabled } selectedTab = { selectedTab } orientation = { orientation } density = { density } /> }
214
214
</ div >
@@ -255,7 +255,7 @@ const selectedIndicator = style({
255
255
transitionTimingFunction : 'in-out'
256
256
} ) ;
257
257
258
- function TabLine ( props : TabLineProps ) {
258
+ function TabLine ( props : TabLineProps & { isIconOnly ?: boolean } ) {
259
259
let {
260
260
disabledKeys,
261
261
isDisabled : isTabsDisabled ,
@@ -301,7 +301,14 @@ function TabLine(props: TabLineProps) {
301
301
302
302
useLayoutEffect ( ( ) => {
303
303
onResize ( ) ;
304
- } , [ onResize , state ?. selectedItem ?. key , direction , orientation , density ] ) ;
304
+ } , [ onResize , state ?. selectedItem ?. key , density ] ) ;
305
+
306
+ let ref = useRef < HTMLElement | undefined > ( selectedTab ) ;
307
+ // assign ref before the useResizeObserver useEffect runs
308
+ useLayoutEffect ( ( ) => {
309
+ ref . current = selectedTab ;
310
+ } ) ;
311
+ useResizeObserver ( { ref, onResize} ) ;
305
312
306
313
return (
307
314
< div style = { { ...style } } className = { selectedIndicator ( { isDisabled, orientation} ) } />
@@ -333,7 +340,10 @@ const tab = style({
333
340
position : 'relative' ,
334
341
cursor : 'default' ,
335
342
flexShrink : 0 ,
336
- transition : 'default'
343
+ transition : 'default' ,
344
+ paddingX : {
345
+ isIconOnly : size ( 6 )
346
+ }
337
347
} , getAllowedOverrides ( ) ) ;
338
348
339
349
const icon = style ( {
@@ -346,15 +356,15 @@ const icon = style({
346
356
} ) ;
347
357
348
358
export function Tab ( props : TabProps ) {
349
- let { density, iconOnly } = useContext ( InternalTabsContext ) ?? { } ;
359
+ let { density, isIconOnly } = useContext ( InternalTabsContext ) ?? { } ;
350
360
351
361
return (
352
362
< RACTab
353
363
{ ...props }
354
364
// @ts -ignore
355
365
originalProps = { props }
356
366
style = { props . UNSAFE_style }
357
- className = { renderProps => ( props . UNSAFE_className || '' ) + tab ( { ...renderProps , density} , props . styles ) } >
367
+ className = { renderProps => ( props . UNSAFE_className || '' ) + tab ( { ...renderProps , density, isIconOnly } , props . styles ) } >
358
368
{ ( {
359
369
// @ts -ignore
360
370
isMenu
@@ -372,7 +382,7 @@ export function Tab(props: TabProps) {
372
382
display : {
373
383
isIconOnly : 'none'
374
384
}
375
- } ) ( { isIconOnly : iconOnly } )
385
+ } ) ( { isIconOnly} )
376
386
} ] ,
377
387
[ IconContext , {
378
388
render : centerBaseline ( { slot : 'icon' , styles : style ( { order : 0 } ) } ) ,
@@ -469,7 +479,7 @@ let HiddenTabs = function (props: {
469
479
let TabsMenu = ( props : { items : Array < Node < any > > , onSelectionChange : TabsProps [ 'onSelectionChange' ] } ) => {
470
480
let stringFormatter = useLocalizedStringFormatter ( intlMessages , '@react-spectrum/s2' ) ;
471
481
let { items} = props ;
472
- let { density, onSelectionChange, selectedKey, isDisabled, disabledKeys, pickerRef} = useContext ( InternalTabsContext ) ;
482
+ let { density, onSelectionChange, selectedKey, isDisabled, disabledKeys, pickerRef, isIconOnly } = useContext ( InternalTabsContext ) ;
473
483
let state = useContext ( TabListStateContext ) ;
474
484
let allKeysDisabled = useMemo ( ( ) => {
475
485
return isAllTabsDisabled ( state ?. collection , disabledKeys ? new Set ( disabledKeys ) : new Set ( ) ) ;
@@ -491,6 +501,7 @@ let TabsMenu = (props: {items: Array<Node<any>>, onSelectionChange: TabsProps['o
491
501
ref = { pickerRef ? pickerRef : undefined }
492
502
isDisabled = { isDisabled || allKeysDisabled }
493
503
density = { density ! }
504
+ isIconOnly = { isIconOnly }
494
505
items = { items }
495
506
disabledKeys = { disabledKeys }
496
507
selectedKey = { selectedKey }
0 commit comments