From 613e4444f7f90abe4ce250d5000a398832436ae3 Mon Sep 17 00:00:00 2001 From: atomiks Date: Fri, 12 Apr 2024 12:27:24 +1000 Subject: [PATCH] Fix clone prop merging of ref and other props --- .../src/Checkbox/CheckboxIndicator.tsx | 4 ++- .../mui-base/src/Checkbox/CheckboxRoot.tsx | 4 ++- .../src/NumberField/NumberFieldDecrement.tsx | 5 +++- .../src/NumberField/NumberFieldGroup.tsx | 5 +++- .../src/NumberField/NumberFieldIncrement.tsx | 5 +++- .../src/NumberField/NumberFieldInput.tsx | 4 +-- .../src/NumberField/NumberFieldRoot.tsx | 5 +++- .../src/NumberField/NumberFieldScrubArea.tsx | 4 +-- .../NumberFieldScrubAreaCursor.tsx | 4 +-- packages/mui-base/src/Switch/SwitchRoot.tsx | 4 ++- packages/mui-base/src/Switch/SwitchThumb.tsx | 4 ++- .../src/utils/evaluateRenderProp.test.tsx | 22 +++++++++++++++ .../mui-base/src/utils/evaluateRenderProp.ts | 2 +- .../mui-base/src/utils/useExtendedForkRef.ts | 14 ++++++++++ .../test/conformanceTests/renderProp.tsx | 27 +++++++++++++++++++ 15 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 packages/mui-base/src/utils/evaluateRenderProp.test.tsx create mode 100644 packages/mui-base/src/utils/useExtendedForkRef.ts diff --git a/packages/mui-base/src/Checkbox/CheckboxIndicator.tsx b/packages/mui-base/src/Checkbox/CheckboxIndicator.tsx index 6e409c6620..41d06bbb5e 100644 --- a/packages/mui-base/src/Checkbox/CheckboxIndicator.tsx +++ b/packages/mui-base/src/Checkbox/CheckboxIndicator.tsx @@ -5,6 +5,7 @@ import { CheckboxContext } from './CheckboxContext'; import { resolveClassName } from '../utils/resolveClassName'; import { useCheckboxStyleHooks } from './utils'; import { evaluateRenderProp } from '../utils/evaluateRenderProp'; +import { useExtendedForkRef } from '../utils/useExtendedForkRef'; function defaultRender(props: React.ComponentPropsWithRef<'span'>) { return ; @@ -34,6 +35,7 @@ const CheckboxIndicator = React.forwardRef(function CheckboxIndicator( } const styleHooks = useCheckboxStyleHooks(ownerState); + const mergedRef = useExtendedForkRef(render, forwardedRef); if (!keepMounted && !ownerState.checked && !ownerState.indeterminate) { return null; @@ -41,7 +43,7 @@ const CheckboxIndicator = React.forwardRef(function CheckboxIndicator( const elementProps = { className: resolveClassName(className, ownerState), - ref: forwardedRef, + ref: mergedRef, ...styleHooks, ...otherProps, }; diff --git a/packages/mui-base/src/Checkbox/CheckboxRoot.tsx b/packages/mui-base/src/Checkbox/CheckboxRoot.tsx index 1662433376..6f58c30fa9 100644 --- a/packages/mui-base/src/Checkbox/CheckboxRoot.tsx +++ b/packages/mui-base/src/Checkbox/CheckboxRoot.tsx @@ -6,6 +6,7 @@ import { CheckboxContext } from './CheckboxContext'; import { useCheckbox } from '../useCheckbox'; import { useCheckboxStyleHooks } from './utils'; import { evaluateRenderProp } from '../utils/evaluateRenderProp'; +import { useExtendedForkRef } from '../utils/useExtendedForkRef'; function defaultRender(props: React.ComponentPropsWithRef<'button'>) { return