diff --git a/.changeset/underline-panels-controlled-panel-props.md b/.changeset/underline-panels-controlled-panel-props.md new file mode 100644 index 00000000000..dd4eaf85abb --- /dev/null +++ b/.changeset/underline-panels-controlled-panel-props.md @@ -0,0 +1,5 @@ +--- +'@primer/react': patch +--- + +UnderlinePanels: Correct Panel types to exclude attributes controlled by the component. diff --git a/packages/react/src/ActionBar/ActionBar.tsx b/packages/react/src/ActionBar/ActionBar.tsx index 4e5324b65fd..93b25b4c235 100644 --- a/packages/react/src/ActionBar/ActionBar.tsx +++ b/packages/react/src/ActionBar/ActionBar.tsx @@ -13,6 +13,7 @@ import {useMergedRefs} from '../hooks' import {createDescendantRegistry} from '../utils/descendant-registry' import {OverflowObserverProvider} from '../internal/components/OverflowObserverProvider' import {useIsClipped} from '../internal/hooks/useOverflowObserver' +import {mergeProps} from '../utils/mergeProps' type ChildProps = | { @@ -332,12 +333,11 @@ function useActionBarItem(ref: React.RefObject, registryProp } export const ActionBarIconButton = forwardRef( - ({disabled, onClick, ...props}: ActionBarIconButtonProps, forwardedRef) => { + ({disabled, onClick, className, ...props}: ActionBarIconButtonProps, forwardedRef) => { const ref = useRef(null) const mergedRef = useMergedRefs(forwardedRef, ref) const {size} = React.useContext(ActionBarContext) - const {['aria-label']: ariaLabel, icon} = props const {dataOverflowingAttr} = useActionBarItem( @@ -364,11 +364,16 @@ export const ActionBarIconButton = forwardRef( return ( @@ -376,50 +381,57 @@ export const ActionBarIconButton = forwardRef( }, ) -export const ActionBarButton = forwardRef(({disabled, onClick, ...props}: ActionBarButtonProps, forwardedRef) => { - const ref = useRef(null) - const mergedRef = useMergedRefs(forwardedRef, ref) - - const {size} = React.useContext(ActionBarContext) +export const ActionBarButton = forwardRef( + ({disabled, onClick, className, children, leadingVisual, ...props}: ActionBarButtonProps, forwardedRef) => { + const ref = useRef(null) + const mergedRef = useMergedRefs(forwardedRef, ref) - const {children, leadingVisual} = props + const {size} = React.useContext(ActionBarContext) - const {dataOverflowingAttr} = useActionBarItem( - ref, - useMemo( - (): ChildProps => ({ - type: 'action', - label: children, - // Only forward the leading visual to the overflow menu when it is a component - // that can be rendered as an icon (e.g. an octicon), matching ActionBar.IconButton. - icon: typeof leadingVisual === 'function' ? (leadingVisual as ActionBarIconButtonProps['icon']) : undefined, - disabled: !!disabled, - onClick: onClick as MouseEventHandler, - }), - [children, leadingVisual, disabled, onClick], - ), - ) + const {dataOverflowingAttr} = useActionBarItem( + ref, + useMemo( + (): ChildProps => ({ + type: 'action', + label: children, + // Only forward the leading visual to the overflow menu when it is a component + // that can be rendered as an icon (e.g. an octicon), matching ActionBar.IconButton. + icon: typeof leadingVisual === 'function' ? (leadingVisual as ActionBarIconButtonProps['icon']) : undefined, + disabled: !!disabled, + onClick: onClick as MouseEventHandler, + }), + [children, leadingVisual, disabled, onClick], + ), + ) - const clickHandler = useCallback( - (event: React.MouseEvent) => { - if (disabled) return - onClick?.(event) - }, - [disabled, onClick], - ) + const clickHandler = useCallback( + (event: React.MouseEvent) => { + if (disabled) return + onClick?.(event) + }, + [disabled, onClick], + ) - return ( -