@@ -252,17 +252,39 @@ export const ActionBar: React.FC<React.PropsWithChildren<ActionBarProps>> = prop
252252 )
253253}
254254
255- export const ActionBarIconButton = forwardRef ( ( props : ActionBarIconButtonProps , forwardedRef ) => {
256- const backupRef = useRef < HTMLElement > ( null )
257- const ref = ( forwardedRef ?? backupRef ) as RefObject < HTMLAnchorElement >
258- const { size, setChildrenWidth} = React . useContext ( ActionBarContext )
259- useIsomorphicLayoutEffect ( ( ) => {
260- const text = props [ 'aria-label' ] ? props [ 'aria-label' ] : ''
261- const domRect = ( ref as MutableRefObject < HTMLElement > ) . current . getBoundingClientRect ( )
262- setChildrenWidth ( { text, width : domRect . width } )
263- } , [ ref , setChildrenWidth ] )
264- return < IconButton aria-disabled = { props . disabled } ref = { ref } size = { size } { ...props } variant = "invisible" />
265- } )
255+ export const ActionBarIconButton = forwardRef (
256+ ( { disabled, onClick, ...props } : ActionBarIconButtonProps , forwardedRef ) => {
257+ const backupRef = useRef < HTMLElement > ( null )
258+ const ref = ( forwardedRef ?? backupRef ) as RefObject < HTMLAnchorElement >
259+ const { size, setChildrenWidth} = React . useContext ( ActionBarContext )
260+ useIsomorphicLayoutEffect ( ( ) => {
261+ const text = props [ 'aria-label' ] ? props [ 'aria-label' ] : ''
262+ const domRect = ( ref as MutableRefObject < HTMLElement > ) . current . getBoundingClientRect ( )
263+ setChildrenWidth ( { text, width : domRect . width } )
264+ } , [ ref , setChildrenWidth ] )
265+
266+ const clickHandler = useCallback (
267+ ( event : React . MouseEvent < HTMLButtonElement > ) => {
268+ if ( disabled ) {
269+ return
270+ }
271+ onClick ?.( event )
272+ } ,
273+ [ disabled , onClick ] ,
274+ )
275+
276+ return (
277+ < IconButton
278+ aria-disabled = { disabled }
279+ ref = { ref }
280+ size = { size }
281+ onClick = { clickHandler }
282+ { ...props }
283+ variant = "invisible"
284+ />
285+ )
286+ } ,
287+ )
266288
267289export const VerticalDivider = ( ) => {
268290 const ref = useRef < HTMLDivElement > ( null )
0 commit comments