diff --git a/packages/x-date-pickers/src/validation/useValidation.ts b/packages/x-date-pickers/src/validation/useValidation.ts index 284e36d4860d..392d6780725a 100644 --- a/packages/x-date-pickers/src/validation/useValidation.ts +++ b/packages/x-date-pickers/src/validation/useValidation.ts @@ -32,6 +32,8 @@ interface UseValidationOptions< /** * The validator function to use. * They can be imported from `@mui/x-date-pickers/validation` and `@mui/x-date-pickers-pro/validation`. + * It is recommended to only use the validator exported by the MUI X packages, + * otherwise you may have inconsistent behaviors between the field and the views. */ validator: Validator; /** @@ -62,6 +64,18 @@ interface UseValidationReturnValue { getValidationErrorForNewValue: (newValue: TValue) => TError; } +/** + * Utility hook to check if a given value is valid based on the provided validation props. + * @template TDate + * @template TValue The value type. It will be either the same type as `value` or `null`. It can be in `[start, end]` format in case of range value. + * @template TError The validation error type. It will be either `string` or a `null`. It can be in `[start, end]` format in case of range value. + * @param {UseValidationOptions} options The options to configure the hook. + * @param {TValue} options.value The value to validate. + * @param {PickersTimezone} options.timezone The timezone to use for the validation. + * @param {Validator} options.validator The validator function to use. + * @param {TValidationProps} options.props The validation props, they differ depending on the component. + * @param {(error: TError, value: TValue) => void} options.onError Callback fired when the error associated with the current value changes. + */ export function useValidation< TValue, TDate extends PickerValidDate,