From 4b4804cde1f68677b1099a931b6a5f63b3856804 Mon Sep 17 00:00:00 2001 From: Flavien DELANGLE Date: Wed, 19 Jun 2024 13:12:52 +0200 Subject: [PATCH] [pickers] Add context to `onAccept` callback (#13511) --- .../pages/x/api/date-pickers/date-picker.json | 5 ++- .../x/api/date-pickers/date-range-picker.json | 5 ++- .../x/api/date-pickers/date-time-picker.json | 5 ++- .../date-pickers/date-time-range-picker.json | 5 ++- .../api/date-pickers/desktop-date-picker.json | 5 ++- .../desktop-date-range-picker.json | 5 ++- .../desktop-date-time-picker.json | 5 ++- .../desktop-date-time-range-picker.json | 5 ++- .../api/date-pickers/desktop-time-picker.json | 5 ++- .../api/date-pickers/mobile-date-picker.json | 5 ++- .../mobile-date-range-picker.json | 5 ++- .../date-pickers/mobile-date-time-picker.json | 5 ++- .../mobile-date-time-range-picker.json | 5 ++- .../api/date-pickers/mobile-time-picker.json | 5 ++- .../api/date-pickers/static-date-picker.json | 5 ++- .../static-date-range-picker.json | 5 ++- .../date-pickers/static-date-time-picker.json | 5 ++- .../api/date-pickers/static-time-picker.json | 5 ++- .../pages/x/api/date-pickers/time-picker.json | 5 ++- .../date-pickers/date-picker/date-picker.json | 5 ++- .../date-range-picker/date-range-picker.json | 5 ++- .../date-time-picker/date-time-picker.json | 5 ++- .../date-time-range-picker.json | 5 ++- .../desktop-date-picker.json | 5 ++- .../desktop-date-range-picker.json | 5 ++- .../desktop-date-time-picker.json | 5 ++- .../desktop-date-time-range-picker.json | 5 ++- .../desktop-time-picker.json | 5 ++- .../mobile-date-picker.json | 5 ++- .../mobile-date-range-picker.json | 5 ++- .../mobile-date-time-picker.json | 5 ++- .../mobile-date-time-range-picker.json | 5 ++- .../mobile-time-picker.json | 5 ++- .../static-date-picker.json | 5 ++- .../static-date-range-picker.json | 5 ++- .../static-date-time-picker.json | 5 ++- .../static-time-picker.json | 5 ++- .../date-pickers/time-picker/time-picker.json | 5 ++- .../src/DateRangePicker/DateRangePicker.tsx | 2 + .../DateTimeRangePicker.tsx | 2 + .../DesktopDateRangePicker.tsx | 2 + .../DesktopDateTimeRangePicker.tsx | 2 + .../MobileDateRangePicker.tsx | 2 + .../MobileDateTimeRangePicker.tsx | 2 + .../StaticDateRangePicker.tsx | 2 + .../src/DatePicker/DatePicker.tsx | 2 + .../src/DateTimePicker/DateTimePicker.tsx | 2 + .../DesktopDatePicker/DesktopDatePicker.tsx | 2 + .../DesktopDateTimePicker.tsx | 2 + .../DesktopTimePicker/DesktopTimePicker.tsx | 2 + .../src/MobileDatePicker/MobileDatePicker.tsx | 2 + .../MobileDateTimePicker.tsx | 2 + .../src/MobileTimePicker/MobileTimePicker.tsx | 2 + .../src/StaticDatePicker/StaticDatePicker.tsx | 2 + .../StaticDateTimePicker.tsx | 2 + .../src/StaticTimePicker/StaticTimePicker.tsx | 2 + .../src/TimePicker/TimePicker.tsx | 2 + .../hooks/usePicker/usePickerValue.ts | 43 +++++++++++-------- .../hooks/usePicker/usePickerValue.types.ts | 4 +- 59 files changed, 218 insertions(+), 57 deletions(-) diff --git a/docs/pages/x/api/date-pickers/date-picker.json b/docs/pages/x/api/date-pickers/date-picker.json index bcfd00412af6..4ea68fc760de 100644 --- a/docs/pages/x/api/date-pickers/date-picker.json +++ b/docs/pages/x/api/date-pickers/date-picker.json @@ -44,7 +44,10 @@ "name": { "type": { "name": "string" } }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/date-range-picker.json b/docs/pages/x/api/date-pickers/date-range-picker.json index 025571c76e56..5d5a3cc60a54 100644 --- a/docs/pages/x/api/date-pickers/date-range-picker.json +++ b/docs/pages/x/api/date-pickers/date-range-picker.json @@ -54,7 +54,10 @@ "name": { "type": { "name": "string" } }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/date-time-picker.json b/docs/pages/x/api/date-pickers/date-time-picker.json index 21dd5ccca51b..4c1bcbdbad73 100644 --- a/docs/pages/x/api/date-pickers/date-time-picker.json +++ b/docs/pages/x/api/date-pickers/date-time-picker.json @@ -52,7 +52,10 @@ "name": { "type": { "name": "string" } }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/date-time-range-picker.json b/docs/pages/x/api/date-pickers/date-time-range-picker.json index 727e404614e0..147b2d9dabe8 100644 --- a/docs/pages/x/api/date-pickers/date-time-range-picker.json +++ b/docs/pages/x/api/date-pickers/date-time-range-picker.json @@ -61,7 +61,10 @@ "name": { "type": { "name": "string" } }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/desktop-date-picker.json b/docs/pages/x/api/date-pickers/desktop-date-picker.json index e596175c9ec0..eba85e4232de 100644 --- a/docs/pages/x/api/date-pickers/desktop-date-picker.json +++ b/docs/pages/x/api/date-pickers/desktop-date-picker.json @@ -40,7 +40,10 @@ "name": { "type": { "name": "string" } }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/desktop-date-range-picker.json b/docs/pages/x/api/date-pickers/desktop-date-range-picker.json index ed5c7c6addee..21ee7757ea57 100644 --- a/docs/pages/x/api/date-pickers/desktop-date-range-picker.json +++ b/docs/pages/x/api/date-pickers/desktop-date-range-picker.json @@ -50,7 +50,10 @@ "name": { "type": { "name": "string" } }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/desktop-date-time-picker.json b/docs/pages/x/api/date-pickers/desktop-date-time-picker.json index e29f85b22ede..3f020cd17da5 100644 --- a/docs/pages/x/api/date-pickers/desktop-date-time-picker.json +++ b/docs/pages/x/api/date-pickers/desktop-date-time-picker.json @@ -48,7 +48,10 @@ "name": { "type": { "name": "string" } }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/desktop-date-time-range-picker.json b/docs/pages/x/api/date-pickers/desktop-date-time-range-picker.json index 8022414ca2a8..f6ac402daf92 100644 --- a/docs/pages/x/api/date-pickers/desktop-date-time-range-picker.json +++ b/docs/pages/x/api/date-pickers/desktop-date-time-range-picker.json @@ -57,7 +57,10 @@ "name": { "type": { "name": "string" } }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/desktop-time-picker.json b/docs/pages/x/api/date-pickers/desktop-time-picker.json index a138a9baf6d6..ccd6bfd90001 100644 --- a/docs/pages/x/api/date-pickers/desktop-time-picker.json +++ b/docs/pages/x/api/date-pickers/desktop-time-picker.json @@ -27,7 +27,10 @@ "name": { "type": { "name": "string" } }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/mobile-date-picker.json b/docs/pages/x/api/date-pickers/mobile-date-picker.json index dda2b5f7a06a..f08c28cc0cc2 100644 --- a/docs/pages/x/api/date-pickers/mobile-date-picker.json +++ b/docs/pages/x/api/date-pickers/mobile-date-picker.json @@ -40,7 +40,10 @@ "name": { "type": { "name": "string" } }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/mobile-date-range-picker.json b/docs/pages/x/api/date-pickers/mobile-date-range-picker.json index b325ddcf307e..9da74456e2a0 100644 --- a/docs/pages/x/api/date-pickers/mobile-date-range-picker.json +++ b/docs/pages/x/api/date-pickers/mobile-date-range-picker.json @@ -46,7 +46,10 @@ "name": { "type": { "name": "string" } }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/mobile-date-time-picker.json b/docs/pages/x/api/date-pickers/mobile-date-time-picker.json index 77d8cbe0ff4e..910576d1135b 100644 --- a/docs/pages/x/api/date-pickers/mobile-date-time-picker.json +++ b/docs/pages/x/api/date-pickers/mobile-date-time-picker.json @@ -48,7 +48,10 @@ "name": { "type": { "name": "string" } }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/mobile-date-time-range-picker.json b/docs/pages/x/api/date-pickers/mobile-date-time-range-picker.json index 2daa3399a014..63d8de93ae50 100644 --- a/docs/pages/x/api/date-pickers/mobile-date-time-range-picker.json +++ b/docs/pages/x/api/date-pickers/mobile-date-time-range-picker.json @@ -53,7 +53,10 @@ "name": { "type": { "name": "string" } }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/mobile-time-picker.json b/docs/pages/x/api/date-pickers/mobile-time-picker.json index 6285dff74f33..7eadc80c5316 100644 --- a/docs/pages/x/api/date-pickers/mobile-time-picker.json +++ b/docs/pages/x/api/date-pickers/mobile-time-picker.json @@ -27,7 +27,10 @@ "name": { "type": { "name": "string" } }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/static-date-picker.json b/docs/pages/x/api/date-pickers/static-date-picker.json index 68b8dd519d9d..27c865ca2370 100644 --- a/docs/pages/x/api/date-pickers/static-date-picker.json +++ b/docs/pages/x/api/date-pickers/static-date-picker.json @@ -31,7 +31,10 @@ }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/static-date-range-picker.json b/docs/pages/x/api/date-pickers/static-date-range-picker.json index cf58edc3774e..57a973451e4c 100644 --- a/docs/pages/x/api/date-pickers/static-date-range-picker.json +++ b/docs/pages/x/api/date-pickers/static-date-range-picker.json @@ -41,7 +41,10 @@ "minDate": { "type": { "name": "object" } }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/static-date-time-picker.json b/docs/pages/x/api/date-pickers/static-date-time-picker.json index 0065d1c76585..75caf10f37ff 100644 --- a/docs/pages/x/api/date-pickers/static-date-time-picker.json +++ b/docs/pages/x/api/date-pickers/static-date-time-picker.json @@ -39,7 +39,10 @@ }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/static-time-picker.json b/docs/pages/x/api/date-pickers/static-time-picker.json index 0af386a2e7b7..c8ca193d0eb0 100644 --- a/docs/pages/x/api/date-pickers/static-time-picker.json +++ b/docs/pages/x/api/date-pickers/static-time-picker.json @@ -18,7 +18,10 @@ "minutesStep": { "type": { "name": "number" }, "default": "1" }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/pages/x/api/date-pickers/time-picker.json b/docs/pages/x/api/date-pickers/time-picker.json index 10cfe474c86f..f77fd0bcc355 100644 --- a/docs/pages/x/api/date-pickers/time-picker.json +++ b/docs/pages/x/api/date-pickers/time-picker.json @@ -31,7 +31,10 @@ "name": { "type": { "name": "string" } }, "onAccept": { "type": { "name": "func" }, - "signature": { "type": "function(value: TValue) => void", "describedArgs": ["value"] } + "signature": { + "type": "function(value: TValue, context: FieldChangeHandlerContext) => void", + "describedArgs": ["value", "context"] + } }, "onChange": { "type": { "name": "func" }, diff --git a/docs/translations/api-docs/date-pickers/date-picker/date-picker.json b/docs/translations/api-docs/date-pickers/date-picker/date-picker.json index d7d0bc2a81be..fa776f7501a5 100644 --- a/docs/translations/api-docs/date-pickers/date-picker/date-picker.json +++ b/docs/translations/api-docs/date-pickers/date-picker/date-picker.json @@ -61,7 +61,10 @@ }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/date-range-picker/date-range-picker.json b/docs/translations/api-docs/date-pickers/date-range-picker/date-range-picker.json index 487f01610089..b847113e3e87 100644 --- a/docs/translations/api-docs/date-pickers/date-range-picker/date-range-picker.json +++ b/docs/translations/api-docs/date-pickers/date-range-picker/date-range-picker.json @@ -75,7 +75,10 @@ }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/date-time-picker/date-time-picker.json b/docs/translations/api-docs/date-pickers/date-time-picker/date-time-picker.json index cd9ff892320f..e6bc667be2c4 100644 --- a/docs/translations/api-docs/date-pickers/date-time-picker/date-time-picker.json +++ b/docs/translations/api-docs/date-pickers/date-time-picker/date-time-picker.json @@ -81,7 +81,10 @@ }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/date-time-range-picker/date-time-range-picker.json b/docs/translations/api-docs/date-pickers/date-time-range-picker/date-time-range-picker.json index b343a9a90823..38ff71b4a0bc 100644 --- a/docs/translations/api-docs/date-pickers/date-time-range-picker/date-time-range-picker.json +++ b/docs/translations/api-docs/date-pickers/date-time-range-picker/date-time-range-picker.json @@ -92,7 +92,10 @@ }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/desktop-date-picker/desktop-date-picker.json b/docs/translations/api-docs/date-pickers/desktop-date-picker/desktop-date-picker.json index b7a8202fe828..bd5ad6552128 100644 --- a/docs/translations/api-docs/date-pickers/desktop-date-picker/desktop-date-picker.json +++ b/docs/translations/api-docs/date-pickers/desktop-date-picker/desktop-date-picker.json @@ -58,7 +58,10 @@ }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/desktop-date-range-picker/desktop-date-range-picker.json b/docs/translations/api-docs/date-pickers/desktop-date-range-picker/desktop-date-range-picker.json index f84ba97e26a9..280773356bff 100644 --- a/docs/translations/api-docs/date-pickers/desktop-date-range-picker/desktop-date-range-picker.json +++ b/docs/translations/api-docs/date-pickers/desktop-date-range-picker/desktop-date-range-picker.json @@ -72,7 +72,10 @@ }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/desktop-date-time-picker/desktop-date-time-picker.json b/docs/translations/api-docs/date-pickers/desktop-date-time-picker/desktop-date-time-picker.json index e780c1306adf..850e02434af9 100644 --- a/docs/translations/api-docs/date-pickers/desktop-date-time-picker/desktop-date-time-picker.json +++ b/docs/translations/api-docs/date-pickers/desktop-date-time-picker/desktop-date-time-picker.json @@ -78,7 +78,10 @@ }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/desktop-date-time-range-picker/desktop-date-time-range-picker.json b/docs/translations/api-docs/date-pickers/desktop-date-time-range-picker/desktop-date-time-range-picker.json index b974a4f13026..44308fe67c43 100644 --- a/docs/translations/api-docs/date-pickers/desktop-date-time-range-picker/desktop-date-time-range-picker.json +++ b/docs/translations/api-docs/date-pickers/desktop-date-time-range-picker/desktop-date-time-range-picker.json @@ -89,7 +89,10 @@ }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/desktop-time-picker/desktop-time-picker.json b/docs/translations/api-docs/date-pickers/desktop-time-picker/desktop-time-picker.json index f34197ca9139..cb08e6dbe9b5 100644 --- a/docs/translations/api-docs/date-pickers/desktop-time-picker/desktop-time-picker.json +++ b/docs/translations/api-docs/date-pickers/desktop-time-picker/desktop-time-picker.json @@ -50,7 +50,10 @@ }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/mobile-date-picker/mobile-date-picker.json b/docs/translations/api-docs/date-pickers/mobile-date-picker/mobile-date-picker.json index 3c66bba3cead..6fdc6eaca82e 100644 --- a/docs/translations/api-docs/date-pickers/mobile-date-picker/mobile-date-picker.json +++ b/docs/translations/api-docs/date-pickers/mobile-date-picker/mobile-date-picker.json @@ -58,7 +58,10 @@ }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/mobile-date-range-picker/mobile-date-range-picker.json b/docs/translations/api-docs/date-pickers/mobile-date-range-picker/mobile-date-range-picker.json index 238d3a5996e7..4f31ae0b2920 100644 --- a/docs/translations/api-docs/date-pickers/mobile-date-range-picker/mobile-date-range-picker.json +++ b/docs/translations/api-docs/date-pickers/mobile-date-range-picker/mobile-date-range-picker.json @@ -69,7 +69,10 @@ }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/mobile-date-time-picker/mobile-date-time-picker.json b/docs/translations/api-docs/date-pickers/mobile-date-time-picker/mobile-date-time-picker.json index ae408ea1af35..3731b8d7d2f7 100644 --- a/docs/translations/api-docs/date-pickers/mobile-date-time-picker/mobile-date-time-picker.json +++ b/docs/translations/api-docs/date-pickers/mobile-date-time-picker/mobile-date-time-picker.json @@ -78,7 +78,10 @@ }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/mobile-date-time-range-picker/mobile-date-time-range-picker.json b/docs/translations/api-docs/date-pickers/mobile-date-time-range-picker/mobile-date-time-range-picker.json index 90665962517a..743e5f688d34 100644 --- a/docs/translations/api-docs/date-pickers/mobile-date-time-range-picker/mobile-date-time-range-picker.json +++ b/docs/translations/api-docs/date-pickers/mobile-date-time-range-picker/mobile-date-time-range-picker.json @@ -86,7 +86,10 @@ }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/mobile-time-picker/mobile-time-picker.json b/docs/translations/api-docs/date-pickers/mobile-time-picker/mobile-time-picker.json index 43f9d92678fe..cd9f9871246e 100644 --- a/docs/translations/api-docs/date-pickers/mobile-time-picker/mobile-time-picker.json +++ b/docs/translations/api-docs/date-pickers/mobile-time-picker/mobile-time-picker.json @@ -50,7 +50,10 @@ }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/static-date-picker/static-date-picker.json b/docs/translations/api-docs/date-pickers/static-date-picker/static-date-picker.json index 6642fc5ae6ed..7ebb4803d895 100644 --- a/docs/translations/api-docs/date-pickers/static-date-picker/static-date-picker.json +++ b/docs/translations/api-docs/date-pickers/static-date-picker/static-date-picker.json @@ -44,7 +44,10 @@ "monthsPerRow": { "description": "Months rendered per row." }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/static-date-range-picker/static-date-range-picker.json b/docs/translations/api-docs/date-pickers/static-date-range-picker/static-date-range-picker.json index 93baad91dff8..a5948b80f383 100644 --- a/docs/translations/api-docs/date-pickers/static-date-range-picker/static-date-range-picker.json +++ b/docs/translations/api-docs/date-pickers/static-date-range-picker/static-date-range-picker.json @@ -54,7 +54,10 @@ "minDate": { "description": "Minimal selectable date." }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/static-date-time-picker/static-date-time-picker.json b/docs/translations/api-docs/date-pickers/static-date-time-picker/static-date-time-picker.json index 4da520fb69b3..49348e673329 100644 --- a/docs/translations/api-docs/date-pickers/static-date-time-picker/static-date-time-picker.json +++ b/docs/translations/api-docs/date-pickers/static-date-time-picker/static-date-time-picker.json @@ -64,7 +64,10 @@ "monthsPerRow": { "description": "Months rendered per row." }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/static-time-picker/static-time-picker.json b/docs/translations/api-docs/date-pickers/static-time-picker/static-time-picker.json index 407f598837a7..8ba5b454d5e6 100644 --- a/docs/translations/api-docs/date-pickers/static-time-picker/static-time-picker.json +++ b/docs/translations/api-docs/date-pickers/static-time-picker/static-time-picker.json @@ -36,7 +36,10 @@ "minutesStep": { "description": "Step over minutes." }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/docs/translations/api-docs/date-pickers/time-picker/time-picker.json b/docs/translations/api-docs/date-pickers/time-picker/time-picker.json index c5a1a885b348..3e18c58879a8 100644 --- a/docs/translations/api-docs/date-pickers/time-picker/time-picker.json +++ b/docs/translations/api-docs/date-pickers/time-picker/time-picker.json @@ -53,7 +53,10 @@ }, "onAccept": { "description": "Callback fired when the value is accepted.", - "typeDescriptions": { "value": "The value that was just accepted." } + "typeDescriptions": { + "value": "The value that was just accepted.", + "context": "The context containing the validation result of the current value." + } }, "onChange": { "description": "Callback fired when the value changes.", diff --git a/packages/x-date-pickers-pro/src/DateRangePicker/DateRangePicker.tsx b/packages/x-date-pickers-pro/src/DateRangePicker/DateRangePicker.tsx index d07dafc7a0d1..237b8dc110df 100644 --- a/packages/x-date-pickers-pro/src/DateRangePicker/DateRangePicker.tsx +++ b/packages/x-date-pickers-pro/src/DateRangePicker/DateRangePicker.tsx @@ -195,7 +195,9 @@ DateRangePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers-pro/src/DateTimeRangePicker/DateTimeRangePicker.tsx b/packages/x-date-pickers-pro/src/DateTimeRangePicker/DateTimeRangePicker.tsx index 6a3d955daa36..573a2317e277 100644 --- a/packages/x-date-pickers-pro/src/DateTimeRangePicker/DateTimeRangePicker.tsx +++ b/packages/x-date-pickers-pro/src/DateTimeRangePicker/DateTimeRangePicker.tsx @@ -228,7 +228,9 @@ DateTimeRangePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers-pro/src/DesktopDateRangePicker/DesktopDateRangePicker.tsx b/packages/x-date-pickers-pro/src/DesktopDateRangePicker/DesktopDateRangePicker.tsx index eae9bde06a16..f783f0caa865 100644 --- a/packages/x-date-pickers-pro/src/DesktopDateRangePicker/DesktopDateRangePicker.tsx +++ b/packages/x-date-pickers-pro/src/DesktopDateRangePicker/DesktopDateRangePicker.tsx @@ -230,7 +230,9 @@ DesktopDateRangePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers-pro/src/DesktopDateTimeRangePicker/DesktopDateTimeRangePicker.tsx b/packages/x-date-pickers-pro/src/DesktopDateTimeRangePicker/DesktopDateTimeRangePicker.tsx index 5987b65694f4..431bed8573b8 100644 --- a/packages/x-date-pickers-pro/src/DesktopDateTimeRangePicker/DesktopDateTimeRangePicker.tsx +++ b/packages/x-date-pickers-pro/src/DesktopDateTimeRangePicker/DesktopDateTimeRangePicker.tsx @@ -392,7 +392,9 @@ DesktopDateTimeRangePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers-pro/src/MobileDateRangePicker/MobileDateRangePicker.tsx b/packages/x-date-pickers-pro/src/MobileDateRangePicker/MobileDateRangePicker.tsx index 3fb9e8327ebd..0621f3a26f77 100644 --- a/packages/x-date-pickers-pro/src/MobileDateRangePicker/MobileDateRangePicker.tsx +++ b/packages/x-date-pickers-pro/src/MobileDateRangePicker/MobileDateRangePicker.tsx @@ -226,7 +226,9 @@ MobileDateRangePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers-pro/src/MobileDateTimeRangePicker/MobileDateTimeRangePicker.tsx b/packages/x-date-pickers-pro/src/MobileDateTimeRangePicker/MobileDateTimeRangePicker.tsx index 9aedd2c40dd8..7ba1632219fb 100644 --- a/packages/x-date-pickers-pro/src/MobileDateTimeRangePicker/MobileDateTimeRangePicker.tsx +++ b/packages/x-date-pickers-pro/src/MobileDateTimeRangePicker/MobileDateTimeRangePicker.tsx @@ -382,7 +382,9 @@ MobileDateTimeRangePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers-pro/src/StaticDateRangePicker/StaticDateRangePicker.tsx b/packages/x-date-pickers-pro/src/StaticDateRangePicker/StaticDateRangePicker.tsx index c9b56b0327f3..5a68a35efe9a 100644 --- a/packages/x-date-pickers-pro/src/StaticDateRangePicker/StaticDateRangePicker.tsx +++ b/packages/x-date-pickers-pro/src/StaticDateRangePicker/StaticDateRangePicker.tsx @@ -174,7 +174,9 @@ StaticDateRangePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers/src/DatePicker/DatePicker.tsx b/packages/x-date-pickers/src/DatePicker/DatePicker.tsx index 0d03dd027d40..f65788a14bc0 100644 --- a/packages/x-date-pickers/src/DatePicker/DatePicker.tsx +++ b/packages/x-date-pickers/src/DatePicker/DatePicker.tsx @@ -172,7 +172,9 @@ DatePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers/src/DateTimePicker/DateTimePicker.tsx b/packages/x-date-pickers/src/DateTimePicker/DateTimePicker.tsx index 7150af6bee52..f931e2606cd4 100644 --- a/packages/x-date-pickers/src/DateTimePicker/DateTimePicker.tsx +++ b/packages/x-date-pickers/src/DateTimePicker/DateTimePicker.tsx @@ -210,7 +210,9 @@ DateTimePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers/src/DesktopDatePicker/DesktopDatePicker.tsx b/packages/x-date-pickers/src/DesktopDatePicker/DesktopDatePicker.tsx index 029e27fb90e9..5a1043e6d2d6 100644 --- a/packages/x-date-pickers/src/DesktopDatePicker/DesktopDatePicker.tsx +++ b/packages/x-date-pickers/src/DesktopDatePicker/DesktopDatePicker.tsx @@ -216,7 +216,9 @@ DesktopDatePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers/src/DesktopDateTimePicker/DesktopDateTimePicker.tsx b/packages/x-date-pickers/src/DesktopDateTimePicker/DesktopDateTimePicker.tsx index a11c68129fcb..be5eb451549d 100644 --- a/packages/x-date-pickers/src/DesktopDateTimePicker/DesktopDateTimePicker.tsx +++ b/packages/x-date-pickers/src/DesktopDateTimePicker/DesktopDateTimePicker.tsx @@ -391,7 +391,9 @@ DesktopDateTimePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers/src/DesktopTimePicker/DesktopTimePicker.tsx b/packages/x-date-pickers/src/DesktopTimePicker/DesktopTimePicker.tsx index 26f44fac76b8..d0a2d8b38c20 100644 --- a/packages/x-date-pickers/src/DesktopTimePicker/DesktopTimePicker.tsx +++ b/packages/x-date-pickers/src/DesktopTimePicker/DesktopTimePicker.tsx @@ -244,7 +244,9 @@ DesktopTimePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers/src/MobileDatePicker/MobileDatePicker.tsx b/packages/x-date-pickers/src/MobileDatePicker/MobileDatePicker.tsx index 615392569b1a..23fe6ab1943e 100644 --- a/packages/x-date-pickers/src/MobileDatePicker/MobileDatePicker.tsx +++ b/packages/x-date-pickers/src/MobileDatePicker/MobileDatePicker.tsx @@ -213,7 +213,9 @@ MobileDatePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers/src/MobileDateTimePicker/MobileDateTimePicker.tsx b/packages/x-date-pickers/src/MobileDateTimePicker/MobileDateTimePicker.tsx index 11339d82b183..9964c55a3948 100644 --- a/packages/x-date-pickers/src/MobileDateTimePicker/MobileDateTimePicker.tsx +++ b/packages/x-date-pickers/src/MobileDateTimePicker/MobileDateTimePicker.tsx @@ -266,7 +266,9 @@ MobileDateTimePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers/src/MobileTimePicker/MobileTimePicker.tsx b/packages/x-date-pickers/src/MobileTimePicker/MobileTimePicker.tsx index 13242ec98404..49e09712163b 100644 --- a/packages/x-date-pickers/src/MobileTimePicker/MobileTimePicker.tsx +++ b/packages/x-date-pickers/src/MobileTimePicker/MobileTimePicker.tsx @@ -207,7 +207,9 @@ MobileTimePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers/src/StaticDatePicker/StaticDatePicker.tsx b/packages/x-date-pickers/src/StaticDatePicker/StaticDatePicker.tsx index a26561d9b98e..7fcb43423bc9 100644 --- a/packages/x-date-pickers/src/StaticDatePicker/StaticDatePicker.tsx +++ b/packages/x-date-pickers/src/StaticDatePicker/StaticDatePicker.tsx @@ -152,7 +152,9 @@ StaticDatePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers/src/StaticDateTimePicker/StaticDateTimePicker.tsx b/packages/x-date-pickers/src/StaticDateTimePicker/StaticDateTimePicker.tsx index e9a97bcf54df..a8e81bcbd303 100644 --- a/packages/x-date-pickers/src/StaticDateTimePicker/StaticDateTimePicker.tsx +++ b/packages/x-date-pickers/src/StaticDateTimePicker/StaticDateTimePicker.tsx @@ -204,7 +204,9 @@ StaticDateTimePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers/src/StaticTimePicker/StaticTimePicker.tsx b/packages/x-date-pickers/src/StaticTimePicker/StaticTimePicker.tsx index 39832d96e2f3..b3b2b27047a0 100644 --- a/packages/x-date-pickers/src/StaticTimePicker/StaticTimePicker.tsx +++ b/packages/x-date-pickers/src/StaticTimePicker/StaticTimePicker.tsx @@ -145,7 +145,9 @@ StaticTimePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers/src/TimePicker/TimePicker.tsx b/packages/x-date-pickers/src/TimePicker/TimePicker.tsx index 096406665d1d..2883b0d1d45b 100644 --- a/packages/x-date-pickers/src/TimePicker/TimePicker.tsx +++ b/packages/x-date-pickers/src/TimePicker/TimePicker.tsx @@ -162,7 +162,9 @@ TimePicker.propTypes = { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ onAccept: PropTypes.func, /** diff --git a/packages/x-date-pickers/src/internals/hooks/usePicker/usePickerValue.ts b/packages/x-date-pickers/src/internals/hooks/usePicker/usePickerValue.ts index 12c8b00617d5..3bd7a5eb08a2 100644 --- a/packages/x-date-pickers/src/internals/hooks/usePicker/usePickerValue.ts +++ b/packages/x-date-pickers/src/internals/hooks/usePicker/usePickerValue.ts @@ -269,29 +269,36 @@ export const usePickerValue = < hasBeenModifiedSinceMount: true, })); - if (shouldPublish) { - const validationError = - action.name === 'setValueFromField' - ? action.context.validationError - : validator({ - adapter, - value: action.value, - props: { ...props, value: action.value, timezone }, - }); - - const context: PickerChangeHandlerContext = { - validationError, - }; - - if (action.name === 'setValueFromShortcut') { - context.shortcut = action.shortcut; + let cachedContext: PickerChangeHandlerContext | null = null; + const getContext = (): PickerChangeHandlerContext => { + if (!cachedContext) { + const validationError = + action.name === 'setValueFromField' + ? action.context.validationError + : validator({ + adapter, + value: action.value, + props: { ...props, value: action.value, timezone }, + }); + + cachedContext = { + validationError, + }; + + if (action.name === 'setValueFromShortcut') { + cachedContext.shortcut = action.shortcut; + } } - handleValueChange(action.value, context); + return cachedContext; + }; + + if (shouldPublish) { + handleValueChange(action.value, getContext()); } if (shouldCommit && onAccept) { - onAccept(action.value); + onAccept(action.value, getContext()); } if (shouldClose) { diff --git a/packages/x-date-pickers/src/internals/hooks/usePicker/usePickerValue.types.ts b/packages/x-date-pickers/src/internals/hooks/usePicker/usePickerValue.types.ts index 7c878c57e613..9372640881c4 100644 --- a/packages/x-date-pickers/src/internals/hooks/usePicker/usePickerValue.types.ts +++ b/packages/x-date-pickers/src/internals/hooks/usePicker/usePickerValue.types.ts @@ -229,9 +229,11 @@ export interface UsePickerValueBaseProps { /** * Callback fired when the value is accepted. * @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value. + * @template TError The validation error type. Will be either `string` or a `null`. Can be in `[start, end]` format in case of range value. * @param {TValue} value The value that was just accepted. + * @param {FieldChangeHandlerContext} context The context containing the validation result of the current value. */ - onAccept?: (value: TValue) => void; + onAccept?: (value: TValue, context: PickerChangeHandlerContext) => void; /** * Callback fired when the error associated to the current value changes. * If the error has a non-null value, then the `TextField` will be rendered in `error` state.