mirror of
https://github.com/strapi/strapi.git
synced 2025-07-21 07:57:45 +00:00
Merge pull request #21163 from strapi/fix/custom-fields-backward-compatibility
fix(content-manager): pass field to CustomField input to have backward compatibility
This commit is contained in:
commit
25f8ab9fbc
@ -4,6 +4,7 @@ import {
|
|||||||
useStrapiApp,
|
useStrapiApp,
|
||||||
useForm,
|
useForm,
|
||||||
InputRenderer as FormInputRenderer,
|
InputRenderer as FormInputRenderer,
|
||||||
|
useField,
|
||||||
} from '@strapi/admin/strapi-admin';
|
} from '@strapi/admin/strapi-admin';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
|
|
||||||
@ -63,6 +64,9 @@ const InputRenderer = ({ visible, hint: providedHint, ...props }: InputRendererP
|
|||||||
edit: { components },
|
edit: { components },
|
||||||
} = useDocLayout();
|
} = useDocLayout();
|
||||||
|
|
||||||
|
// We pass field in case of Custom Fields to keep backward compatibility
|
||||||
|
const field = useField(props.name);
|
||||||
|
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -86,7 +90,7 @@ const InputRenderer = ({ visible, hint: providedHint, ...props }: InputRendererP
|
|||||||
|
|
||||||
if (CustomInput) {
|
if (CustomInput) {
|
||||||
// @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.
|
// @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.
|
||||||
return <CustomInput {...props} hint={hint} disabled={fieldIsDisabled} />;
|
return <CustomInput {...props} {...field} hint={hint} disabled={fieldIsDisabled} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -10,7 +10,7 @@ import {
|
|||||||
useComposedRefs,
|
useComposedRefs,
|
||||||
} from '@strapi/design-system';
|
} from '@strapi/design-system';
|
||||||
import { CaretDown } from '@strapi/icons';
|
import { CaretDown } from '@strapi/icons';
|
||||||
import { useField, type InputProps } from '@strapi/strapi/admin';
|
import { useField, type InputProps, type FieldValue } from '@strapi/strapi/admin';
|
||||||
import { HexColorPicker } from 'react-colorful';
|
import { HexColorPicker } from 'react-colorful';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import { styled } from 'styled-components';
|
import { styled } from 'styled-components';
|
||||||
@ -73,13 +73,16 @@ const ColorPickerPopover = styled(Popover.Content)`
|
|||||||
min-height: 270px;
|
min-height: 270px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
type ColorPickerInputProps = InputProps & {
|
type ColorPickerInputProps = InputProps &
|
||||||
|
FieldValue & {
|
||||||
labelAction?: React.ReactNode;
|
labelAction?: React.ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ColorPickerInput = React.forwardRef<HTMLButtonElement, ColorPickerInputProps>(
|
export const ColorPickerInput = React.forwardRef<HTMLButtonElement, ColorPickerInputProps>(
|
||||||
({ hint, disabled = false, labelAction, label, name, required = false }, forwardedRef) => {
|
(
|
||||||
const { onChange, value, error } = useField(name);
|
{ hint, disabled = false, labelAction, label, name, required = false, onChange, value, error },
|
||||||
|
forwardedRef
|
||||||
|
) => {
|
||||||
const [showColorPicker, setShowColorPicker] = React.useState(false);
|
const [showColorPicker, setShowColorPicker] = React.useState(false);
|
||||||
const colorPickerButtonRef = React.useRef<HTMLButtonElement>(null!);
|
const colorPickerButtonRef = React.useRef<HTMLButtonElement>(null!);
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
@ -7,7 +7,16 @@ import { IntlProvider } from 'react-intl';
|
|||||||
import { ColorPickerInput } from '../ColorPickerInput';
|
import { ColorPickerInput } from '../ColorPickerInput';
|
||||||
|
|
||||||
const render = () => ({
|
const render = () => ({
|
||||||
...renderRTL(<ColorPickerInput name="color" label={'color-picker'} type="string" />, {
|
...renderRTL(
|
||||||
|
<ColorPickerInput
|
||||||
|
name="color"
|
||||||
|
label={'color-picker'}
|
||||||
|
type="string"
|
||||||
|
initialValue=""
|
||||||
|
value=""
|
||||||
|
onChange={() => {}}
|
||||||
|
/>,
|
||||||
|
{
|
||||||
wrapper: ({ children }) => {
|
wrapper: ({ children }) => {
|
||||||
const locale = 'en';
|
const locale = 'en';
|
||||||
return (
|
return (
|
||||||
@ -20,7 +29,8 @@ const render = () => ({
|
|||||||
</IntlProvider>
|
</IntlProvider>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
}),
|
}
|
||||||
|
),
|
||||||
user: userEvent.setup(),
|
user: userEvent.setup(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user