Skip to content

Commit

Permalink
Work
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Sep 5, 2024
1 parent 80162f2 commit 0b57b8c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/x-date-pickers/src/validation/useValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TValue, TDate, TError, TValidationProps>;
/**
Expand Down Expand Up @@ -62,6 +64,18 @@ interface UseValidationReturnValue<TValue, TError> {
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<TValue, TDate, TError, TValidationProps>} 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<TValue, TDate, TError, TValidationProps>} 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,
Expand Down

0 comments on commit 0b57b8c

Please sign in to comment.