From d853bcddcef783efb071da90ba03a5afb30fb6ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dudak?= Date: Wed, 26 Apr 2023 15:34:04 +0200 Subject: [PATCH] [FormControl][base] Do not use optional fields in useFormControlContext's return value --- .../base/api/use-form-control-context.json | 19 +++--- .../src/FormControl/FormControl.types.ts | 60 ++++++++++++------- 2 files changed, 48 insertions(+), 31 deletions(-) diff --git a/docs/pages/base/api/use-form-control-context.json b/docs/pages/base/api/use-form-control-context.json index acbb34e0ef36bc..e34be0c419fbd8 100644 --- a/docs/pages/base/api/use-form-control-context.json +++ b/docs/pages/base/api/use-form-control-context.json @@ -1,26 +1,27 @@ { "parameters": {}, "returnValue": { + "disabled": { "type": { "name": "boolean", "description": "boolean" }, "required": true }, + "error": { "type": { "name": "boolean", "description": "boolean" }, "required": true }, "filled": { "type": { "name": "boolean", "description": "boolean" }, "required": true }, "focused": { "type": { "name": "boolean", "description": "boolean" }, "required": true }, "onBlur": { "type": { "name": "() => void", "description": "() => void" }, "required": true }, - "onFocus": { - "type": { "name": "() => void", "description": "() => void" }, - "required": true - }, - "disabled": { "type": { "name": "boolean", "description": "boolean" }, "default": "false" }, - "error": { "type": { "name": "boolean", "description": "boolean" }, "default": "false" }, "onChange": { "type": { "name": "React.ChangeEventHandler<NativeFormControlElement>", "description": "React.ChangeEventHandler<NativeFormControlElement>" - } + }, + "required": true + }, + "onFocus": { + "type": { "name": "() => void", "description": "() => void" }, + "required": true }, - "required": { "type": { "name": "boolean", "description": "boolean" }, "default": "false" }, - "value": { "type": { "name": "unknown", "description": "unknown" } } + "required": { "type": { "name": "boolean", "description": "boolean" }, "required": true }, + "value": { "type": { "name": "unknown", "description": "unknown" }, "required": true } }, "name": "useFormControlContext", "filename": "/packages/mui-base/src/FormControl/useFormControlContext.ts", diff --git a/packages/mui-base/src/FormControl/FormControl.types.ts b/packages/mui-base/src/FormControl/FormControl.types.ts index faa33734da2979..48b566241e6bb4 100644 --- a/packages/mui-base/src/FormControl/FormControl.types.ts +++ b/packages/mui-base/src/FormControl/FormControl.types.ts @@ -86,28 +86,44 @@ export type FormControlOwnerState = Simplify< } >; -type ContextFromPropsKey = 'disabled' | 'error' | 'onChange' | 'required' | 'value'; - -export type FormControlState = Simplify< - Pick & { - /** - * If `true`, the form element has some value. - */ - filled: boolean; - /** - * If `true`, the form element is focused and not disabled. - */ - focused: boolean; - /** - * Callback fired when the form element has lost focus. - */ - onBlur: () => void; - /** - * Callback fired when the form element receives focus. - */ - onFocus: () => void; - } ->; +export type FormControlState = { + /** + * If `true`, the label, input and helper text should be displayed in a disabled state. + */ + disabled: boolean; + /** + * If `true`, the label is displayed in an error state. + */ + error: boolean; + /** + * If `true`, the form element has some value. + */ + filled: boolean; + /** + * If `true`, the form element is focused and not disabled. + */ + focused: boolean; + /** + * Callback fired when the form element has lost focus. + */ + onBlur: () => void; + /** + * Callback fired when the form element's value is modified. + */ + onChange: React.ChangeEventHandler; + /** + * Callback fired when the form element receives focus. + */ + onFocus: () => void; + /** + * If `true`, the label will indicate that the `input` is required. + */ + required: boolean; + /** + * The value of the form element. + */ + value: unknown; +}; export type FormControlRootSlotProps = { children: React.ReactNode | ((state: FormControlState) => React.ReactNode);