@@ -29,7 +29,7 @@ import {
2929import { centerBaseline } from './CenterBaseline' ;
3030import { Collection , DOMRef , DOMRefValue , FocusableRef , FocusableRefValue , Key , Node , Orientation , RefObject } from '@react-types/shared' ;
3131import { 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' } ;
3333import { getAllowedOverrides , StyleProps , StylesPropWithHeight , UnsafeStyles } from './style-utils' with { type : 'macro' } ;
3434import { IconContext } from './Icon' ;
3535// @ts -ignore
@@ -55,7 +55,7 @@ export interface TabsProps extends Omit<AriaTabsProps, 'className' | 'style' | '
5555 /**
5656 * If the tabs should only display icons and no text.
5757 */
58- iconOnly ?: boolean
58+ isIconOnly ?: boolean
5959}
6060
6161export interface TabProps extends Omit < AriaTabProps , 'children' | 'style' | 'className' > , StyleProps {
@@ -96,7 +96,7 @@ export const Tabs = forwardRef(function Tabs(props: TabsProps, ref: DOMRef<HTMLD
9696 isDisabled,
9797 disabledKeys,
9898 orientation = 'horizontal' ,
99- iconOnly = false
99+ isIconOnly = false
100100 } = props ;
101101 let domRef = useDOMRef ( ref ) ;
102102 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
112112 disabledKeys,
113113 selectedKey : value ,
114114 onSelectionChange : setValue ,
115- iconOnly ,
115+ isIconOnly ,
116116 onFocus : ( ) => pickerRef . current ?. focus ( ) ,
117117 pickerRef
118118 } ]
@@ -170,7 +170,7 @@ const tablist = style({
170170} ) ;
171171
172172export 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 ) ?? { } ;
174174 let { showItems} = useContext ( CollapseContext ) ?? { } ;
175175 let state = useContext ( TabListStateContext ) ;
176176 let [ selectedTab , setSelectedTab ] = useState < HTMLElement | undefined > ( undefined ) ;
@@ -208,7 +208,7 @@ export function TabList<T extends object>(props: TabListProps<T>) {
208208 < RACTabList
209209 { ...props }
210210 ref = { tablistRef }
211- className = { renderProps => tablist ( { ...renderProps , isIconOnly : iconOnly , density} ) } />
211+ className = { renderProps => tablist ( { ...renderProps , isIconOnly, density} ) } />
212212 { orientation === 'horizontal' &&
213213 < TabLine showItems = { showItems } disabledKeys = { disabledKeys } isDisabled = { isDisabled } selectedTab = { selectedTab } orientation = { orientation } density = { density } /> }
214214 </ div >
@@ -255,7 +255,7 @@ const selectedIndicator = style({
255255 transitionTimingFunction : 'in-out'
256256} ) ;
257257
258- function TabLine ( props : TabLineProps ) {
258+ function TabLine ( props : TabLineProps & { isIconOnly ?: boolean } ) {
259259 let {
260260 disabledKeys,
261261 isDisabled : isTabsDisabled ,
@@ -301,7 +301,14 @@ function TabLine(props: TabLineProps) {
301301
302302 useLayoutEffect ( ( ) => {
303303 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} ) ;
305312
306313 return (
307314 < div style = { { ...style } } className = { selectedIndicator ( { isDisabled, orientation} ) } />
@@ -333,7 +340,10 @@ const tab = style({
333340 position : 'relative' ,
334341 cursor : 'default' ,
335342 flexShrink : 0 ,
336- transition : 'default'
343+ transition : 'default' ,
344+ paddingX : {
345+ isIconOnly : size ( 6 )
346+ }
337347} , getAllowedOverrides ( ) ) ;
338348
339349const icon = style ( {
@@ -346,15 +356,15 @@ const icon = style({
346356} ) ;
347357
348358export function Tab ( props : TabProps ) {
349- let { density, iconOnly } = useContext ( InternalTabsContext ) ?? { } ;
359+ let { density, isIconOnly } = useContext ( InternalTabsContext ) ?? { } ;
350360
351361 return (
352362 < RACTab
353363 { ...props }
354364 // @ts -ignore
355365 originalProps = { props }
356366 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 ) } >
358368 { ( {
359369 // @ts -ignore
360370 isMenu
@@ -372,7 +382,7 @@ export function Tab(props: TabProps) {
372382 display : {
373383 isIconOnly : 'none'
374384 }
375- } ) ( { isIconOnly : iconOnly } )
385+ } ) ( { isIconOnly} )
376386 } ] ,
377387 [ IconContext , {
378388 render : centerBaseline ( { slot : 'icon' , styles : style ( { order : 0 } ) } ) ,
@@ -469,7 +479,7 @@ let HiddenTabs = function (props: {
469479let TabsMenu = ( props : { items : Array < Node < any > > , onSelectionChange : TabsProps [ 'onSelectionChange' ] } ) => {
470480 let stringFormatter = useLocalizedStringFormatter ( intlMessages , '@react-spectrum/s2' ) ;
471481 let { items} = props ;
472- let { density, onSelectionChange, selectedKey, isDisabled, disabledKeys, pickerRef} = useContext ( InternalTabsContext ) ;
482+ let { density, onSelectionChange, selectedKey, isDisabled, disabledKeys, pickerRef, isIconOnly } = useContext ( InternalTabsContext ) ;
473483 let state = useContext ( TabListStateContext ) ;
474484 let allKeysDisabled = useMemo ( ( ) => {
475485 return isAllTabsDisabled ( state ?. collection , disabledKeys ? new Set ( disabledKeys ) : new Set ( ) ) ;
@@ -491,6 +501,7 @@ let TabsMenu = (props: {items: Array<Node<any>>, onSelectionChange: TabsProps['o
491501 ref = { pickerRef ? pickerRef : undefined }
492502 isDisabled = { isDisabled || allKeysDisabled }
493503 density = { density ! }
504+ isIconOnly = { isIconOnly }
494505 items = { items }
495506 disabledKeys = { disabledKeys }
496507 selectedKey = { selectedKey }
0 commit comments