@okta/odyssey-react-mui 1.7.1 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/@types/react-augment.d.js +2 -0
- package/dist/@types/react-augment.d.js.map +1 -0
- package/dist/Autocomplete.js +32 -23
- package/dist/Autocomplete.js.map +1 -1
- package/dist/Checkbox.js +33 -18
- package/dist/Checkbox.js.map +1 -1
- package/dist/NativeSelect.js +22 -8
- package/dist/NativeSelect.js.map +1 -1
- package/dist/PasswordField.js +19 -5
- package/dist/PasswordField.js.map +1 -1
- package/dist/RadioGroup.js +11 -8
- package/dist/RadioGroup.js.map +1 -1
- package/dist/SearchField.js +17 -16
- package/dist/SearchField.js.map +1 -1
- package/dist/Select.js +34 -18
- package/dist/Select.js.map +1 -1
- package/dist/TextField.js +20 -6
- package/dist/TextField.js.map +1 -1
- package/dist/inputUtils.js +46 -0
- package/dist/inputUtils.js.map +1 -0
- package/dist/labs/VirtualizedAutocomplete.js +29 -23
- package/dist/labs/VirtualizedAutocomplete.js.map +1 -1
- package/dist/src/Autocomplete.d.ts +0 -1
- package/dist/src/Autocomplete.d.ts.map +1 -1
- package/dist/src/Checkbox.d.ts +5 -1
- package/dist/src/Checkbox.d.ts.map +1 -1
- package/dist/src/NativeSelect.d.ts +19 -44
- package/dist/src/NativeSelect.d.ts.map +1 -1
- package/dist/src/PasswordField.d.ts +10 -2
- package/dist/src/PasswordField.d.ts.map +1 -1
- package/dist/src/RadioGroup.d.ts.map +1 -1
- package/dist/src/SearchField.d.ts +10 -2
- package/dist/src/SearchField.d.ts.map +1 -1
- package/dist/src/Select.d.ts +5 -1
- package/dist/src/Select.d.ts.map +1 -1
- package/dist/src/TextField.d.ts +8 -0
- package/dist/src/TextField.d.ts.map +1 -1
- package/dist/src/inputUtils.d.ts +47 -0
- package/dist/src/inputUtils.d.ts.map +1 -0
- package/dist/src/labs/VirtualizedAutocomplete.d.ts.map +1 -1
- package/dist/tsconfig.production.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/@types/react-augment.d.ts +19 -0
- package/src/Autocomplete.tsx +49 -43
- package/src/Checkbox.tsx +41 -22
- package/src/NativeSelect.tsx +78 -25
- package/src/PasswordField.tsx +32 -4
- package/src/RadioGroup.tsx +12 -10
- package/src/SearchField.tsx +24 -18
- package/src/Select.tsx +43 -25
- package/src/TextField.tsx +33 -5
- package/src/inputUtils.ts +76 -0
- package/src/labs/VirtualizedAutocomplete.tsx +48 -42
- package/dist/src/useControlledState.d.ts +0 -28
- package/dist/src/useControlledState.d.ts.map +0 -1
- package/dist/useControlledState.js +0 -33
- package/dist/useControlledState.js.map +0 -1
- package/src/useControlledState.ts +0 -56
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.8.1](https://github.com/okta/odyssey/compare/v1.8.0...v1.8.1) (2023-12-01)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- support controlled and uncontrolled states in form components ([#2045](https://github.com/okta/odyssey/issues/2045)) ([eacf2b4](https://github.com/okta/odyssey/commit/eacf2b496e0650388c8f0bc6015c88a3fc1ef47d))
|
|
11
|
+
|
|
12
|
+
## [1.8.0](https://github.com/okta/odyssey/compare/v1.7.1...v1.8.0) (2023-12-01)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- add hint prop to Checkbox ([#2050](https://github.com/okta/odyssey/issues/2050)) ([1fdc55e](https://github.com/okta/odyssey/commit/1fdc55e667c89b7768f300a160d550a62e6e8eb0))
|
|
17
|
+
|
|
6
18
|
## [1.7.1](https://github.com/okta/odyssey/compare/v1.7.0...v1.7.1) (2023-12-01)
|
|
7
19
|
|
|
8
20
|
**Note:** Version bump only for package @okta/odyssey-react-mui
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-augment.d.js","names":[],"sources":["../../src/@types/react-augment.d.ts"],"sourcesContent":["/*!\n * Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport { FC } from \"react\";\n\nexport interface ForwardRefWithType extends FC<WithForwardRefProps<Option>> {\n <T extends Option>(props: WithForwardRefProps<T>): ReturnType<\n FC<WithForwardRefProps<T>>\n >;\n}\n"],"mappings":""}
|
package/dist/Autocomplete.js
CHANGED
|
@@ -11,9 +11,9 @@ import _InputBase from "@mui/material/InputBase";
|
|
|
11
11
|
*
|
|
12
12
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
|
-
import { memo, useCallback, useMemo } from "react";
|
|
14
|
+
import { memo, useCallback, useMemo, useRef } from "react";
|
|
15
15
|
import { Field } from "./Field.js";
|
|
16
|
-
import {
|
|
16
|
+
import { ComponentControlledState, useInputValues, getControlState } from "./inputUtils.js";
|
|
17
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
18
|
const Autocomplete = _ref => {
|
|
19
19
|
let {
|
|
@@ -39,6 +39,32 @@ const Autocomplete = _ref => {
|
|
|
39
39
|
getIsOptionEqualToValue,
|
|
40
40
|
testId
|
|
41
41
|
} = _ref;
|
|
42
|
+
const controlledStateRef = useRef(getControlState({
|
|
43
|
+
controlledValue: value,
|
|
44
|
+
uncontrolledValue: defaultValue
|
|
45
|
+
}));
|
|
46
|
+
const defaultValueProp = useMemo(() => {
|
|
47
|
+
if (hasMultipleChoices) {
|
|
48
|
+
if (value === undefined) {
|
|
49
|
+
return defaultValue;
|
|
50
|
+
}
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
return value === undefined ? defaultValue : undefined;
|
|
54
|
+
}, [defaultValue, hasMultipleChoices, value]);
|
|
55
|
+
const valueProps = useInputValues({
|
|
56
|
+
defaultValue: defaultValueProp,
|
|
57
|
+
value: value,
|
|
58
|
+
controlState: controlledStateRef.current
|
|
59
|
+
});
|
|
60
|
+
const inputValueProp = useMemo(() => {
|
|
61
|
+
if (controlledStateRef.current === ComponentControlledState.CONTROLLED) {
|
|
62
|
+
return {
|
|
63
|
+
inputValue
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}, [inputValue]);
|
|
42
68
|
const renderInput = useCallback(_ref2 => {
|
|
43
69
|
let {
|
|
44
70
|
InputLabelProps,
|
|
@@ -76,32 +102,17 @@ const Autocomplete = _ref => {
|
|
|
76
102
|
}
|
|
77
103
|
});
|
|
78
104
|
}, [errorMessage, hint, isOptional, label, nameOverride]);
|
|
79
|
-
const defaultValuesProp = useMemo(() => {
|
|
80
|
-
if (hasMultipleChoices) {
|
|
81
|
-
return defaultValue === undefined ? [] : defaultValue;
|
|
82
|
-
}
|
|
83
|
-
return defaultValue ?? undefined;
|
|
84
|
-
}, [defaultValue, hasMultipleChoices]);
|
|
85
|
-
const [localValue, setLocalValue] = useControlledState({
|
|
86
|
-
controlledValue: value,
|
|
87
|
-
uncontrolledValue: defaultValuesProp
|
|
88
|
-
});
|
|
89
|
-
const [localInputValue, setLocalInputValue] = useControlledState({
|
|
90
|
-
controlledValue: inputValue,
|
|
91
|
-
uncontrolledValue: undefined
|
|
92
|
-
});
|
|
93
105
|
const onChange = useCallback((event, value, reason, details) => {
|
|
94
|
-
setLocalValue(value);
|
|
95
106
|
onChangeProp?.(event, value, reason, details);
|
|
96
|
-
}, [onChangeProp
|
|
107
|
+
}, [onChangeProp]);
|
|
97
108
|
const onInputChange = useCallback((event, value, reason) => {
|
|
98
|
-
setLocalInputValue(value);
|
|
99
109
|
onInputChangeProp?.(event, value, reason);
|
|
100
|
-
}, [onInputChangeProp
|
|
110
|
+
}, [onInputChangeProp]);
|
|
101
111
|
return _jsx(_Autocomplete, {
|
|
112
|
+
...valueProps,
|
|
113
|
+
...inputValueProp,
|
|
102
114
|
"aria-disabled": isDisabled,
|
|
103
115
|
"data-se": testId,
|
|
104
|
-
defaultValue: defaultValuesProp,
|
|
105
116
|
disableCloseOnSelect: hasMultipleChoices,
|
|
106
117
|
disabled: isDisabled,
|
|
107
118
|
freeSolo: isCustomValueAllowed,
|
|
@@ -116,8 +127,6 @@ const Autocomplete = _ref => {
|
|
|
116
127
|
options: options,
|
|
117
128
|
readOnly: isReadOnly,
|
|
118
129
|
renderInput: renderInput,
|
|
119
|
-
value: localValue,
|
|
120
|
-
inputValue: localInputValue,
|
|
121
130
|
isOptionEqualToValue: getIsOptionEqualToValue
|
|
122
131
|
});
|
|
123
132
|
};
|
package/dist/Autocomplete.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Autocomplete.js","names":["memo","useCallback","useMemo","Field","useControlledState","jsx","_jsx","Autocomplete","_ref","defaultValue","errorMessage","hasMultipleChoices","id","idOverride","inputValue","isCustomValueAllowed","isDisabled","isLoading","isOptional","isReadOnly","hint","label","name","nameOverride","onBlur","onChange","onChangeProp","onInputChange","onInputChangeProp","onFocus","options","value","getIsOptionEqualToValue","testId","renderInput","_ref2","InputLabelProps","InputProps","params","fieldType","hasVisibleLabel","htmlFor","renderFieldComponent","_ref3","ariaDescribedBy","errorMessageElementId","labelElementId","_InputBase","inputProps","required","defaultValuesProp","undefined","localValue","setLocalValue","controlledValue","uncontrolledValue","localInputValue","setLocalInputValue","event","reason","details","_Autocomplete","disableCloseOnSelect","disabled","freeSolo","filterSelectedOptions","loading","multiple","readOnly","isOptionEqualToValue","MemoizedAutocomplete","displayName"],"sources":["../src/Autocomplete.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport {\n Autocomplete as MuiAutocomplete,\n AutocompleteProps as MuiAutocompleteProps,\n InputBase,\n UseAutocompleteProps,\n AutocompleteValue,\n} from \"@mui/material\";\nimport { memo, useCallback, useMemo } from \"react\";\n\nimport { Field } from \"./Field\";\nimport { FieldComponentProps } from \"./FieldComponentProps\";\nimport type { SeleniumProps } from \"./SeleniumProps\";\nimport { useControlledState } from \"./useControlledState\";\n\nexport type AutocompleteProps<\n OptionType,\n HasMultipleChoices extends boolean | undefined,\n IsCustomValueAllowed extends boolean | undefined\n> = {\n /**\n * The default value. Use when the component is not controlled.\n * @default props.multiple ? [] : null\n */\n defaultValue?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"defaultValue\"];\n /**\n * Enables multiple choice selection\n */\n hasMultipleChoices?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"multiple\"];\n /**\n * The value for the input\n */\n inputValue?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"inputValue\"];\n /**\n * Allows the input of custom values\n */\n isCustomValueAllowed?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"freeSolo\"];\n /**\n * Disables the Autocomplete input\n */\n isDisabled?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"disabled\"];\n /**\n * Displays a loading indicator\n */\n isLoading?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"loading\"];\n /**\n * Makes the Autocomplete input read-only\n */\n isReadOnly?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"readOnly\"];\n /**\n * The label text for the autocomplete input\n */\n label: string;\n /**\n * Callback fired when the autocomplete loses focus.\n */\n onBlur?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onBlur\"];\n /**\n * Callback fired when a selection is made.\n */\n onChange?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onChange\"];\n /**\n * Callback fired when the textbox receives typed characters.\n */\n onInputChange?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onInputChange\"];\n /**\n * Callback fired when the autocomplete gains focus.\n */\n onFocus?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onFocus\"];\n /**\n * The options for the Autocomplete input\n */\n options: ReadonlyArray<OptionType>;\n /**\n * The value of the Autocomplete input\n */\n value?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"value\"];\n\n /**\n * Used to determine if the option represents the given value. Uses strict equality by default if none provided.\n * Both arguments need to be handled, an option can only match with one value.\n * option: the option to test\n * value: the value to test against\n *\n * You will need to implement this function if your `option` items are objects.\n */\n getIsOptionEqualToValue?: (option: OptionType, value: OptionType) => boolean;\n} & Pick<\n FieldComponentProps,\n \"errorMessage\" | \"hint\" | \"id\" | \"isOptional\" | \"name\"\n> &\n SeleniumProps;\n\nconst Autocomplete = <\n OptionType,\n HasMultipleChoices extends boolean | undefined,\n IsCustomValueAllowed extends boolean | undefined\n>({\n defaultValue,\n errorMessage,\n hasMultipleChoices,\n id: idOverride,\n inputValue,\n isCustomValueAllowed,\n isDisabled,\n isLoading,\n isOptional = false,\n isReadOnly,\n hint,\n label,\n name: nameOverride,\n onBlur,\n onChange: onChangeProp,\n onInputChange: onInputChangeProp,\n onFocus,\n options,\n value,\n getIsOptionEqualToValue,\n testId,\n}: AutocompleteProps<OptionType, HasMultipleChoices, IsCustomValueAllowed>) => {\n const renderInput = useCallback(\n ({ InputLabelProps, InputProps, ...params }) => (\n <Field\n errorMessage={errorMessage}\n fieldType=\"single\"\n hasVisibleLabel\n id={InputLabelProps.htmlFor}\n hint={hint}\n label={label}\n isOptional={isOptional}\n renderFieldComponent={({\n ariaDescribedBy,\n id,\n errorMessageElementId,\n labelElementId,\n }) => (\n <InputBase\n {...params}\n {...InputProps}\n inputProps={{\n ...params.inputProps,\n \"aria-errormessage\": errorMessageElementId,\n \"aria-labelledby\": labelElementId,\n }}\n aria-describedby={ariaDescribedBy}\n id={id}\n name={nameOverride ?? id}\n required={!isOptional}\n />\n )}\n />\n ),\n [errorMessage, hint, isOptional, label, nameOverride]\n );\n\n const defaultValuesProp = useMemo<\n | AutocompleteValue<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >\n | undefined\n >(() => {\n if (hasMultipleChoices) {\n return defaultValue === undefined\n ? ([] as AutocompleteValue<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >)\n : defaultValue;\n }\n return defaultValue ?? undefined;\n }, [defaultValue, hasMultipleChoices]);\n\n const [localValue, setLocalValue] = useControlledState({\n controlledValue: value,\n uncontrolledValue: defaultValuesProp,\n });\n\n const [localInputValue, setLocalInputValue] = useControlledState({\n controlledValue: inputValue,\n uncontrolledValue: undefined,\n });\n\n const onChange = useCallback<\n NonNullable<\n UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onChange\"]\n >\n >(\n (event, value, reason, details) => {\n setLocalValue(value);\n onChangeProp?.(event, value, reason, details);\n },\n [onChangeProp, setLocalValue]\n );\n\n const onInputChange = useCallback<\n NonNullable<\n UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onInputChange\"]\n >\n >(\n (event, value, reason) => {\n setLocalInputValue(value);\n onInputChangeProp?.(event, value, reason);\n },\n [onInputChangeProp, setLocalInputValue]\n );\n\n return (\n <MuiAutocomplete\n // AutoComplete is wrapped in a div within MUI which does not get the disabled attr. So this aria-disabled gets set in the div\n aria-disabled={isDisabled}\n data-se={testId}\n defaultValue={defaultValuesProp}\n disableCloseOnSelect={hasMultipleChoices}\n disabled={isDisabled}\n freeSolo={isCustomValueAllowed}\n filterSelectedOptions={true}\n id={idOverride}\n loading={isLoading}\n multiple={hasMultipleChoices}\n onBlur={onBlur}\n onChange={onChange}\n onInputChange={onInputChange}\n onFocus={onFocus}\n options={options}\n readOnly={isReadOnly}\n renderInput={renderInput}\n value={localValue}\n inputValue={localInputValue}\n isOptionEqualToValue={getIsOptionEqualToValue}\n />\n );\n};\n\n// Need the `typeof Autocomplete` because generics don't get passed through\nconst MemoizedAutocomplete = memo(Autocomplete) as typeof Autocomplete;\n// @ts-expect-error displayName is expected to not be on `typeof Autocomplete`\nMemoizedAutocomplete.displayName = \"Autocomplete\";\n\nexport { MemoizedAutocomplete as Autocomplete };\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AASA,SAASA,IAAI,EAAEC,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAAC,SAE1CC,KAAK;AAAA,SAGLC,kBAAkB;AAAA,SAAAC,GAAA,IAAAC,IAAA;AA4I3B,MAAMC,YAAY,GAAGC,IAAA,IA0B0D;EAAA,IAtB7E;IACAC,YAAY;IACZC,YAAY;IACZC,kBAAkB;IAClBC,EAAE,EAAEC,UAAU;IACdC,UAAU;IACVC,oBAAoB;IACpBC,UAAU;IACVC,SAAS;IACTC,UAAU,GAAG,KAA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ExD,kBAAmB;IAC7Ba,MAAM,EAAEA,MAAO;IACfC,QAAQ,EAAEA,QAAS;IACnBE,aAAa,EAAEA,aAAc;IAC7BE,OAAO,EAAEA,OAAQ;IACjBC,OAAO,EAAEA,OAAQ;IACjBsC,QAAQ,EAAEjD,UAAW;IACrBe,WAAW,EAAEA,WAAY;IACzBH,KAAK,EAAEqB,UAAW;IAClBtC,UAAU,EAAE0C,eAAgB;IAC5Ba,oBAAoB,EAAErC;EAAwB,CAC/C,CAAC;AAEN,CAAC;AAGD,MAAMsC,oBAAoB,GAAGtE,IAAI,CAACO,YAAY,CAAwB;AAEtE+D,oBAAoB,CAACC,WAAW,GAAG,cAAc;AAEjD,SAASD,oBAAoB,IAAI/D,YAAY"}
|
|
1
|
+
{"version":3,"file":"Autocomplete.js","names":["memo","useCallback","useMemo","useRef","Field","ComponentControlledState","useInputValues","getControlState","jsx","_jsx","Autocomplete","_ref","defaultValue","errorMessage","hasMultipleChoices","id","idOverride","inputValue","isCustomValueAllowed","isDisabled","isLoading","isOptional","isReadOnly","hint","label","name","nameOverride","onBlur","onChange","onChangeProp","onInputChange","onInputChangeProp","onFocus","options","value","getIsOptionEqualToValue","testId","controlledStateRef","controlledValue","uncontrolledValue","defaultValueProp","undefined","valueProps","controlState","current","inputValueProp","CONTROLLED","renderInput","_ref2","InputLabelProps","InputProps","params","fieldType","hasVisibleLabel","htmlFor","renderFieldComponent","_ref3","ariaDescribedBy","errorMessageElementId","labelElementId","_InputBase","inputProps","required","event","reason","details","_Autocomplete","disableCloseOnSelect","disabled","freeSolo","filterSelectedOptions","loading","multiple","readOnly","isOptionEqualToValue","MemoizedAutocomplete","displayName"],"sources":["../src/Autocomplete.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport {\n Autocomplete as MuiAutocomplete,\n AutocompleteProps as MuiAutocompleteProps,\n InputBase,\n UseAutocompleteProps,\n AutocompleteValue,\n} from \"@mui/material\";\nimport { memo, useCallback, useMemo, useRef } from \"react\";\n\nimport { Field } from \"./Field\";\nimport { FieldComponentProps } from \"./FieldComponentProps\";\nimport type { SeleniumProps } from \"./SeleniumProps\";\nimport {\n ComponentControlledState,\n useInputValues,\n getControlState,\n} from \"./inputUtils\";\n\nexport type AutocompleteProps<\n OptionType,\n HasMultipleChoices extends boolean | undefined,\n IsCustomValueAllowed extends boolean | undefined\n> = {\n /**\n * The default value. Use when the component is not controlled.\n */\n defaultValue?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"defaultValue\"];\n /**\n * Enables multiple choice selection\n */\n hasMultipleChoices?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"multiple\"];\n /**\n * The value for the input\n */\n inputValue?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"inputValue\"];\n /**\n * Allows the input of custom values\n */\n isCustomValueAllowed?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"freeSolo\"];\n /**\n * Disables the Autocomplete input\n */\n isDisabled?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"disabled\"];\n /**\n * Displays a loading indicator\n */\n isLoading?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"loading\"];\n /**\n * Makes the Autocomplete input read-only\n */\n isReadOnly?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"readOnly\"];\n /**\n * The label text for the autocomplete input\n */\n label: string;\n /**\n * Callback fired when the autocomplete loses focus.\n */\n onBlur?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onBlur\"];\n /**\n * Callback fired when a selection is made.\n */\n onChange?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onChange\"];\n /**\n * Callback fired when the textbox receives typed characters.\n */\n onInputChange?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onInputChange\"];\n /**\n * Callback fired when the autocomplete gains focus.\n */\n onFocus?: MuiAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onFocus\"];\n /**\n * The options for the Autocomplete input\n */\n options: ReadonlyArray<OptionType>;\n /**\n * The value of the Autocomplete input\n */\n value?: UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"value\"];\n\n /**\n * Used to determine if the option represents the given value. Uses strict equality by default if none provided.\n * Both arguments need to be handled, an option can only match with one value.\n * option: the option to test\n * value: the value to test against\n *\n * You will need to implement this function if your `option` items are objects.\n */\n getIsOptionEqualToValue?: (option: OptionType, value: OptionType) => boolean;\n} & Pick<\n FieldComponentProps,\n \"errorMessage\" | \"hint\" | \"id\" | \"isOptional\" | \"name\"\n> &\n SeleniumProps;\n\nconst Autocomplete = <\n OptionType,\n HasMultipleChoices extends boolean | undefined,\n IsCustomValueAllowed extends boolean | undefined\n>({\n defaultValue,\n errorMessage,\n hasMultipleChoices,\n id: idOverride,\n inputValue,\n isCustomValueAllowed,\n isDisabled,\n isLoading,\n isOptional = false,\n isReadOnly,\n hint,\n label,\n name: nameOverride,\n onBlur,\n onChange: onChangeProp,\n onInputChange: onInputChangeProp,\n onFocus,\n options,\n value,\n getIsOptionEqualToValue,\n testId,\n}: AutocompleteProps<OptionType, HasMultipleChoices, IsCustomValueAllowed>) => {\n const controlledStateRef = useRef(\n getControlState({ controlledValue: value, uncontrolledValue: defaultValue })\n );\n const defaultValueProp = useMemo<\n | AutocompleteValue<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >\n | undefined\n >(() => {\n if (hasMultipleChoices) {\n if (value === undefined) {\n return defaultValue;\n }\n return [] as AutocompleteValue<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >;\n }\n return value === undefined ? defaultValue : undefined;\n }, [defaultValue, hasMultipleChoices, value]);\n\n const valueProps = useInputValues({\n defaultValue: defaultValueProp,\n value: value,\n controlState: controlledStateRef.current,\n });\n\n const inputValueProp = useMemo(() => {\n if (controlledStateRef.current === ComponentControlledState.CONTROLLED) {\n return { inputValue };\n }\n return undefined;\n }, [inputValue]);\n\n const renderInput = useCallback(\n ({ InputLabelProps, InputProps, ...params }) => (\n <Field\n errorMessage={errorMessage}\n fieldType=\"single\"\n hasVisibleLabel\n id={InputLabelProps.htmlFor}\n hint={hint}\n label={label}\n isOptional={isOptional}\n renderFieldComponent={({\n ariaDescribedBy,\n id,\n errorMessageElementId,\n labelElementId,\n }) => (\n <InputBase\n {...params}\n {...InputProps}\n inputProps={{\n ...params.inputProps,\n \"aria-errormessage\": errorMessageElementId,\n \"aria-labelledby\": labelElementId,\n }}\n aria-describedby={ariaDescribedBy}\n id={id}\n name={nameOverride ?? id}\n required={!isOptional}\n />\n )}\n />\n ),\n [errorMessage, hint, isOptional, label, nameOverride]\n );\n const onChange = useCallback<\n NonNullable<\n UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onChange\"]\n >\n >(\n (event, value, reason, details) => {\n onChangeProp?.(event, value, reason, details);\n },\n [onChangeProp]\n );\n\n const onInputChange = useCallback<\n NonNullable<\n UseAutocompleteProps<\n OptionType,\n HasMultipleChoices,\n undefined,\n IsCustomValueAllowed\n >[\"onInputChange\"]\n >\n >(\n (event, value, reason) => {\n onInputChangeProp?.(event, value, reason);\n },\n [onInputChangeProp]\n );\n\n return (\n <MuiAutocomplete\n {...valueProps}\n {...inputValueProp}\n // AutoComplete is wrapped in a div within MUI which does not get the disabled attr. So this aria-disabled gets set in the div\n aria-disabled={isDisabled}\n data-se={testId}\n disableCloseOnSelect={hasMultipleChoices}\n disabled={isDisabled}\n freeSolo={isCustomValueAllowed}\n filterSelectedOptions={true}\n id={idOverride}\n loading={isLoading}\n multiple={hasMultipleChoices}\n onBlur={onBlur}\n onChange={onChange}\n onInputChange={onInputChange}\n onFocus={onFocus}\n options={options}\n readOnly={isReadOnly}\n renderInput={renderInput}\n isOptionEqualToValue={getIsOptionEqualToValue}\n />\n );\n};\n\n// Need the `typeof Autocomplete` because generics don't get passed through\nconst MemoizedAutocomplete = memo(Autocomplete) as typeof Autocomplete;\n// @ts-expect-error displayName is expected to not be on `typeof Autocomplete`\nMemoizedAutocomplete.displayName = \"Autocomplete\";\n\nexport { MemoizedAutocomplete as Autocomplete };\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AASA,SAASA,IAAI,EAAEC,WAAW,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAAC,SAElDC,KAAK;AAAA,SAIZC,wBAAwB,EACxBC,cAAc,EACdC,eAAe;AAAA,SAAAC,GAAA,IAAAC,IAAA;AA4IjB,MAAMC,YAAY,GAAGC,IAAA,IA0B0D;EAAA,IAtB7E;IACAC,YAAY;IACZC,YAAY;IACZC,kBAAkB;IAClBC,EAAE,EAAEC,UAAU;IACdC,UAAU;IACVC,oBAAoB;IACpBC,UAAU;IACVC,SAAS;IACTC,UAAU,GAAG,KAAK;IAClBC,UAAU;IACVC,IAAI;IACJC,KAAK;IACLC,IAAI,EAAEC,YAAY;IAClBC,MAAM;IACNC,QAAQ,EAAEC,YAAY;IACtB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AAK;IAC5BvD,EAAE,EAAEC,UAAW;IACfuD,OAAO,EAAEnD,SAAU;IACnBoD,QAAQ,EAAE1D,kBAAmB;IAC7Ba,MAAM,EAAEA,MAAO;IACfC,QAAQ,EAAEA,QAAS;IACnBE,aAAa,EAAEA,aAAc;IAC7BE,OAAO,EAAEA,OAAQ;IACjBC,OAAO,EAAEA,OAAQ;IACjBwC,QAAQ,EAAEnD,UAAW;IACrByB,WAAW,EAAEA,WAAY;IACzB2B,oBAAoB,EAAEvC;EAAwB,CAC/C,CAAC;AAEN,CAAC;AAGD,MAAMwC,oBAAoB,GAAG3E,IAAI,CAACU,YAAY,CAAwB;AAEtEiE,oBAAoB,CAACC,WAAW,GAAG,cAAc;AAEjD,SAASD,oBAAoB,IAAIjE,YAAY"}
|
package/dist/Checkbox.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _FormControlLabel from "@mui/material/FormControlLabel";
|
|
2
2
|
import _Checkbox from "@mui/material/Checkbox";
|
|
3
|
+
import _FormHelperText from "@mui/material/FormHelperText";
|
|
3
4
|
/*!
|
|
4
5
|
* Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.
|
|
5
6
|
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
|
|
@@ -13,9 +14,9 @@ import _Checkbox from "@mui/material/Checkbox";
|
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
16
|
import { useTranslation } from "react-i18next";
|
|
16
|
-
import { memo, useCallback, useMemo } from "react";
|
|
17
|
+
import { memo, useCallback, useMemo, useRef } from "react";
|
|
17
18
|
import { Typography } from "./Typography.js";
|
|
18
|
-
import {
|
|
19
|
+
import { ComponentControlledState, getControlState } from "./inputUtils.js";
|
|
19
20
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
21
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
21
22
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -31,6 +32,7 @@ const Checkbox = _ref => {
|
|
|
31
32
|
isIndeterminate,
|
|
32
33
|
isRequired,
|
|
33
34
|
label: labelProp,
|
|
35
|
+
hint,
|
|
34
36
|
name: nameOverride,
|
|
35
37
|
onChange: onChangeProp,
|
|
36
38
|
testId,
|
|
@@ -40,38 +42,51 @@ const Checkbox = _ref => {
|
|
|
40
42
|
const {
|
|
41
43
|
t
|
|
42
44
|
} = useTranslation();
|
|
43
|
-
const
|
|
45
|
+
const controlledStateRef = useRef(getControlState({
|
|
44
46
|
controlledValue: isChecked,
|
|
45
47
|
uncontrolledValue: isDefaultChecked
|
|
46
|
-
});
|
|
48
|
+
}));
|
|
49
|
+
const inputValues = useMemo(() => {
|
|
50
|
+
if (controlledStateRef.current === ComponentControlledState.CONTROLLED) {
|
|
51
|
+
return {
|
|
52
|
+
checked: isChecked
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
defaultChecked: isDefaultChecked
|
|
57
|
+
};
|
|
58
|
+
}, [isDefaultChecked, isChecked]);
|
|
47
59
|
const label = useMemo(() => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
children: [
|
|
60
|
+
return _jsxs(_Fragment, {
|
|
61
|
+
children: [labelProp, isRequired && _jsxs(_Fragment, {
|
|
62
|
+
children: [" ", _jsxs(Typography, {
|
|
51
63
|
component: "span",
|
|
52
64
|
color: "textSecondary",
|
|
53
65
|
children: ["(", t("fieldlabel.required.text"), ")"]
|
|
54
66
|
})]
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
}, [isRequired, labelProp, t]);
|
|
67
|
+
}), hint && _jsx(_FormHelperText, {
|
|
68
|
+
children: hint
|
|
69
|
+
})]
|
|
70
|
+
});
|
|
71
|
+
}, [isRequired, labelProp, hint, t]);
|
|
62
72
|
const onChange = useCallback((event, checked) => {
|
|
63
|
-
setIsLocalChecked(checked);
|
|
64
73
|
onChangeProp?.(event, checked);
|
|
65
|
-
}, [onChangeProp
|
|
74
|
+
}, [onChangeProp]);
|
|
66
75
|
return _jsx(_FormControlLabel, {
|
|
76
|
+
sx: {
|
|
77
|
+
alignItems: "flex-start"
|
|
78
|
+
},
|
|
67
79
|
"aria-label": ariaLabel,
|
|
68
80
|
"aria-labelledby": ariaLabelledBy,
|
|
69
81
|
className: validity === "invalid" ? "Mui-error" : validity === "valid" ? "Mui-valid" : "",
|
|
70
82
|
control: _jsx(_Checkbox, {
|
|
71
|
-
|
|
83
|
+
...inputValues,
|
|
72
84
|
indeterminate: isIndeterminate,
|
|
73
85
|
onChange: onChange,
|
|
74
|
-
required: isRequired
|
|
86
|
+
required: isRequired,
|
|
87
|
+
sx: () => ({
|
|
88
|
+
marginBlockStart: "2px"
|
|
89
|
+
})
|
|
75
90
|
}),
|
|
76
91
|
"data-se": testId,
|
|
77
92
|
disabled: isDisabled,
|
package/dist/Checkbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.js","names":["useTranslation","memo","useCallback","useMemo","Typography","
|
|
1
|
+
{"version":3,"file":"Checkbox.js","names":["useTranslation","memo","useCallback","useMemo","useRef","Typography","ComponentControlledState","getControlState","jsxs","_jsxs","Fragment","_Fragment","jsx","_jsx","checkboxValidityValues","Checkbox","_ref","ariaLabel","ariaLabelledBy","id","idOverride","isChecked","isDefaultChecked","isDisabled","isIndeterminate","isRequired","label","labelProp","hint","name","nameOverride","onChange","onChangeProp","testId","validity","value","t","controlledStateRef","controlledValue","uncontrolledValue","inputValues","current","CONTROLLED","checked","defaultChecked","children","component","color","_FormHelperText","event","_FormControlLabel","sx","alignItems","className","control","_Checkbox","indeterminate","required","marginBlockStart","disabled","MemoizedCheckbox","displayName"],"sources":["../src/Checkbox.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport { useTranslation } from \"react-i18next\";\nimport { memo, useCallback, useMemo, useRef } from \"react\";\nimport {\n Checkbox as MuiCheckbox,\n CheckboxProps as MuiCheckboxProps,\n FormControlLabel,\n FormHelperText,\n} from \"@mui/material\";\n\nimport { FieldComponentProps } from \"./FieldComponentProps\";\nimport { Typography } from \"./Typography\";\nimport type { SeleniumProps } from \"./SeleniumProps\";\nimport { ComponentControlledState, getControlState } from \"./inputUtils\";\nimport { CheckedFieldProps } from \"./FormCheckedProps\";\n\nexport const checkboxValidityValues = [\"valid\", \"invalid\", \"inherit\"] as const;\n\nexport type CheckboxProps = {\n /**\n * The ARIA label for the Checkbox\n */\n ariaLabel?: string;\n /**\n * The ID of the element that labels the Checkbox\n */\n ariaLabelledBy?: string;\n /**\n * The id of the `input` element.\n */\n id?: string;\n /**\n * Determines whether the Checkbox is disabled\n */\n isDisabled?: boolean;\n /**\n * Determines whether the Checkbox is in an indeterminate state\n */\n isIndeterminate?: boolean;\n /**\n * Determines whether the Checkbox is required\n */\n isRequired?: boolean;\n /**\n * The label text for the Checkbox\n */\n label?: string;\n /**\n * The helper text content\n */\n hint?: string;\n /**\n * The checkbox validity, if different from its enclosing group. Defaults to \"inherit\".\n */\n validity?: (typeof checkboxValidityValues)[number];\n /**\n * The value attribute of the Checkbox\n */\n value?: string;\n} & Pick<FieldComponentProps, \"id\" | \"isDisabled\" | \"name\"> &\n CheckedFieldProps<MuiCheckboxProps> &\n SeleniumProps;\n\nconst Checkbox = ({\n ariaLabel,\n ariaLabelledBy,\n id: idOverride,\n isChecked,\n isDefaultChecked,\n isDisabled,\n isIndeterminate,\n isRequired,\n label: labelProp,\n hint,\n name: nameOverride,\n onChange: onChangeProp,\n testId,\n validity = \"inherit\",\n value,\n}: CheckboxProps) => {\n const { t } = useTranslation();\n const controlledStateRef = useRef(\n getControlState({\n controlledValue: isChecked,\n uncontrolledValue: isDefaultChecked,\n })\n );\n const inputValues = useMemo(() => {\n if (controlledStateRef.current === ComponentControlledState.CONTROLLED) {\n return { checked: isChecked };\n }\n return { defaultChecked: isDefaultChecked };\n }, [isDefaultChecked, isChecked]);\n\n const label = useMemo(() => {\n return (\n <>\n {labelProp}\n {isRequired && (\n <>\n {\" \"}\n <Typography component=\"span\" color=\"textSecondary\">\n ({t(\"fieldlabel.required.text\")})\n </Typography>\n </>\n )}\n {hint && <FormHelperText>{hint}</FormHelperText>}\n </>\n );\n }, [isRequired, labelProp, hint, t]);\n\n const onChange = useCallback<NonNullable<MuiCheckboxProps[\"onChange\"]>>(\n (event, checked) => {\n onChangeProp?.(event, checked);\n },\n [onChangeProp]\n );\n\n return (\n <FormControlLabel\n sx={{ alignItems: \"flex-start\" }}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n className={\n validity === \"invalid\"\n ? \"Mui-error\"\n : validity === \"valid\"\n ? \"Mui-valid\"\n : \"\"\n }\n control={\n <MuiCheckbox\n {...inputValues}\n indeterminate={isIndeterminate}\n onChange={onChange}\n required={isRequired}\n sx={() => ({\n marginBlockStart: \"2px\",\n })}\n />\n }\n data-se={testId}\n disabled={isDisabled}\n id={idOverride}\n label={label}\n name={nameOverride ?? idOverride}\n value={value}\n required={isRequired}\n />\n );\n};\n\nconst MemoizedCheckbox = memo(Checkbox);\nMemoizedCheckbox.displayName = \"Checkbox\";\n\nexport { MemoizedCheckbox as Checkbox };\n"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,cAAc,QAAQ,eAAe;AAC9C,SAASC,IAAI,EAAEC,WAAW,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAAC,SASlDC,UAAU;AAAA,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AAU;AAEzC,SAASD,gBAAgB,IAAI7C,QAAQ"}
|
package/dist/NativeSelect.js
CHANGED
|
@@ -11,26 +11,41 @@ import _Select from "@mui/material/Select";
|
|
|
11
11
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import { forwardRef, memo, useCallback } from "react";
|
|
14
|
+
import React, { forwardRef, memo, useCallback, useMemo, useRef } from "react";
|
|
15
15
|
import { Field } from "./Field.js";
|
|
16
|
+
import { getControlState, useInputValues } from "./inputUtils.js";
|
|
16
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
18
|
const NativeSelect = forwardRef((_ref, ref) => {
|
|
18
19
|
let {
|
|
19
20
|
defaultValue,
|
|
20
21
|
errorMessage,
|
|
22
|
+
hasMultipleChoices: hasMultipleChoicesProp,
|
|
21
23
|
hint,
|
|
22
24
|
id: idOverride,
|
|
23
25
|
isDisabled = false,
|
|
24
|
-
isMultiSelect
|
|
26
|
+
isMultiSelect,
|
|
25
27
|
isOptional = false,
|
|
26
28
|
label,
|
|
27
29
|
onBlur,
|
|
28
|
-
onChange,
|
|
30
|
+
onChange: onChangeProp,
|
|
29
31
|
onFocus,
|
|
30
32
|
testId,
|
|
31
33
|
value,
|
|
32
34
|
children
|
|
33
35
|
} = _ref;
|
|
36
|
+
const controlledStateRef = useRef(getControlState({
|
|
37
|
+
controlledValue: value,
|
|
38
|
+
uncontrolledValue: defaultValue
|
|
39
|
+
}));
|
|
40
|
+
const inputValues = useInputValues({
|
|
41
|
+
defaultValue,
|
|
42
|
+
value,
|
|
43
|
+
controlState: controlledStateRef.current
|
|
44
|
+
});
|
|
45
|
+
const onChange = useCallback((event, child) => {
|
|
46
|
+
onChangeProp?.(event, child);
|
|
47
|
+
}, [onChangeProp]);
|
|
48
|
+
const hasMultipleChoices = useMemo(() => hasMultipleChoicesProp === undefined ? isMultiSelect : hasMultipleChoicesProp, [hasMultipleChoicesProp, isMultiSelect]);
|
|
34
49
|
const renderFieldComponent = useCallback(_ref2 => {
|
|
35
50
|
let {
|
|
36
51
|
ariaDescribedBy,
|
|
@@ -38,25 +53,24 @@ const NativeSelect = forwardRef((_ref, ref) => {
|
|
|
38
53
|
labelElementId
|
|
39
54
|
} = _ref2;
|
|
40
55
|
return _jsx(_Select, {
|
|
56
|
+
...inputValues,
|
|
41
57
|
"aria-describedby": ariaDescribedBy,
|
|
42
58
|
children: children,
|
|
43
59
|
"data-se": testId,
|
|
44
|
-
defaultValue: defaultValue,
|
|
45
60
|
id: idOverride,
|
|
46
61
|
inputProps: {
|
|
47
62
|
"aria-errormessage": errorMessageElementId,
|
|
48
63
|
"aria-labelledby": labelElementId
|
|
49
64
|
},
|
|
50
65
|
name: idOverride,
|
|
51
|
-
multiple:
|
|
66
|
+
multiple: hasMultipleChoices,
|
|
52
67
|
native: true,
|
|
53
68
|
onBlur: onBlur,
|
|
54
69
|
onChange: onChange,
|
|
55
70
|
onFocus: onFocus,
|
|
56
|
-
ref: ref
|
|
57
|
-
value: value
|
|
71
|
+
ref: ref
|
|
58
72
|
});
|
|
59
|
-
}, [children,
|
|
73
|
+
}, [children, idOverride, inputValues, hasMultipleChoices, onBlur, onChange, onFocus, ref, testId]);
|
|
60
74
|
return _jsx(Field, {
|
|
61
75
|
errorMessage: errorMessage,
|
|
62
76
|
fieldType: "single",
|
package/dist/NativeSelect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeSelect.js","names":["forwardRef","memo","useCallback","Field","jsx","_jsx","NativeSelect","_ref","ref","defaultValue","errorMessage","hint","id","idOverride","isDisabled","isMultiSelect","isOptional","label","onBlur","onChange","onFocus","testId","value","children","renderFieldComponent","_ref2","ariaDescribedBy","errorMessageElementId","labelElementId","_Select","inputProps","name","multiple","native","fieldType","hasVisibleLabel","MemoizedNativeSelect","displayName"],"sources":["../src/NativeSelect.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport {
|
|
1
|
+
{"version":3,"file":"NativeSelect.js","names":["React","forwardRef","memo","useCallback","useMemo","useRef","Field","getControlState","useInputValues","jsx","_jsx","NativeSelect","_ref","ref","defaultValue","errorMessage","hasMultipleChoices","hasMultipleChoicesProp","hint","id","idOverride","isDisabled","isMultiSelect","isOptional","label","onBlur","onChange","onChangeProp","onFocus","testId","value","children","controlledStateRef","controlledValue","uncontrolledValue","inputValues","controlState","current","event","child","undefined","renderFieldComponent","_ref2","ariaDescribedBy","errorMessageElementId","labelElementId","_Select","inputProps","name","multiple","native","fieldType","hasVisibleLabel","MemoizedNativeSelect","displayName"],"sources":["../src/NativeSelect.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport React, {\n ReactElement,\n forwardRef,\n memo,\n useCallback,\n useMemo,\n useRef,\n} from \"react\";\nimport {\n Select as MuiSelect,\n SelectProps as MuiSelectProps,\n} from \"@mui/material\";\nimport { Field } from \"./Field\";\nimport { FieldComponentProps } from \"./FieldComponentProps\";\nimport type { SeleniumProps } from \"./SeleniumProps\";\nimport { getControlState, useInputValues } from \"./inputUtils\";\nimport { ForwardRefWithType } from \"./@types/react-augment\";\n\nexport type NativeSelectOption = {\n text: string;\n value?: string;\n type?: \"heading\" | \"option\";\n};\n\nexport type NativeSelectValueType<HasMultipleChoices> =\n HasMultipleChoices extends true ? string[] : string;\n\nexport type NativeSelectProps<\n Value extends NativeSelectValueType<HasMultipleChoices>,\n HasMultipleChoices extends boolean\n> = {\n /**\n * The options or optgroup elements within the NativeSelect\n */\n children?: ReactElement<\"option\"> | ReactElement<\"optgroup\">;\n /**\n * The default value of the NativeSelect. Use when component is uncontrolled\n */\n defaultValue?: Value;\n /**\n * If `true`, the Select allows multiple selections\n */\n hasMultipleChoices?: HasMultipleChoices;\n /**\n * @deprecated Use `hasMultipleChoices` instead\n */\n /** **Deprecated:** use `hasMultipleChoices` */\n isMultiSelect?: HasMultipleChoices;\n /**\n * The label text for the NativeSelect\n */\n label: string;\n /**\n * Callback fired when the NativeSelect loses focus\n */\n onBlur?: MuiSelectProps<Value>[\"onBlur\"];\n /**\n * Callback fired when the value of the NativeSelect changes\n */\n onChange?: MuiSelectProps<Value>[\"onChange\"];\n /**\n * Callback fired when the NativeSelect gains focus\n */\n onFocus?: MuiSelectProps<Value>[\"onFocus\"];\n options: Value;\n /**\n * The value or values selected in the NativeSelect. Use when component is controlled\n */\n value?: Value;\n} & Pick<\n FieldComponentProps,\n \"errorMessage\" | \"hint\" | \"id\" | \"isDisabled\" | \"isOptional\"\n> &\n SeleniumProps;\n\nconst NativeSelect: ForwardRefWithType = forwardRef(\n <\n Value extends NativeSelectValueType<HasMultipleChoices>,\n HasMultipleChoices extends boolean\n >(\n {\n defaultValue,\n errorMessage,\n hasMultipleChoices: hasMultipleChoicesProp,\n hint,\n id: idOverride,\n isDisabled = false,\n isMultiSelect,\n isOptional = false,\n label,\n onBlur,\n onChange: onChangeProp,\n onFocus,\n testId,\n value,\n children,\n }: NativeSelectProps<Value, HasMultipleChoices>,\n ref?: React.Ref<ReactElement>\n ) => {\n const controlledStateRef = useRef(\n getControlState({\n controlledValue: value,\n uncontrolledValue: defaultValue,\n })\n );\n const inputValues = useInputValues({\n defaultValue,\n value,\n controlState: controlledStateRef.current,\n });\n\n const onChange = useCallback<\n NonNullable<MuiSelectProps<Value>[\"onChange\"]>\n >(\n (event, child) => {\n onChangeProp?.(event, child);\n },\n [onChangeProp]\n );\n\n const hasMultipleChoices = useMemo(\n () =>\n hasMultipleChoicesProp === undefined\n ? isMultiSelect\n : hasMultipleChoicesProp,\n [hasMultipleChoicesProp, isMultiSelect]\n );\n const renderFieldComponent = useCallback(\n ({ ariaDescribedBy, errorMessageElementId, labelElementId }) => (\n <MuiSelect\n {...inputValues}\n aria-describedby={ariaDescribedBy}\n children={children}\n data-se={testId}\n id={idOverride}\n inputProps={{\n \"aria-errormessage\": errorMessageElementId,\n \"aria-labelledby\": labelElementId,\n }}\n name={idOverride}\n multiple={hasMultipleChoices}\n native={true}\n onBlur={onBlur}\n onChange={onChange}\n onFocus={onFocus}\n ref={ref}\n />\n ),\n [\n children,\n idOverride,\n inputValues,\n hasMultipleChoices,\n onBlur,\n onChange,\n onFocus,\n ref,\n testId,\n ]\n );\n\n return (\n <Field\n errorMessage={errorMessage}\n fieldType=\"single\"\n hasVisibleLabel\n hint={hint}\n id={idOverride}\n isDisabled={isDisabled}\n isOptional={isOptional}\n label={label}\n renderFieldComponent={renderFieldComponent}\n />\n );\n }\n);\n\nconst MemoizedNativeSelect = memo(NativeSelect);\nMemoizedNativeSelect.displayName = \"NativeSelect\";\n\nexport { MemoizedNativeSelect as NativeSelect };\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,IAEVC,UAAU,EACVC,IAAI,EACJC,WAAW,EACXC,OAAO,EACPC,MAAM,QACD,OAAO;AAAC,SAKNC,KAAK;AAAA,SAGLC,eAAe,EAAEC,cAAc;AAAA,SAAAC,GAAA,IAAAC,IAAA;AA4DxC,MAAMC,YAAgC,GAAGV,UAAU,CACjD,CAAA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CAAE;MACFG,IAAI,EAAE5B,UAAW;MACjB6B,QAAQ,EAAEjC,kBAAmB;MAC7BkC,MAAM,EAAE,IAAK;MACbzB,MAAM,EAAEA,MAAO;MACfC,QAAQ,EAAEA,QAAS;MACnBE,OAAO,EAAEA,OAAQ;MACjBf,GAAG,EAAEA;IAAI,CACV,CAAC;EAAA,CACH,EACD,CACEkB,QAAQ,EACRX,UAAU,EACVe,WAAW,EACXnB,kBAAkB,EAClBS,MAAM,EACNC,QAAQ,EACRE,OAAO,EACPf,GAAG,EACHgB,MAAM,CAEV,CAAC;EAED,OACEnB,IAAA,CAACJ,KAAK;IACJS,YAAY,EAAEA,YAAa;IAC3BoC,SAAS,EAAC,QAAQ;IAClBC,eAAe;IACflC,IAAI,EAAEA,IAAK;IACXC,EAAE,EAAEC,UAAW;IACfC,UAAU,EAAEA,UAAW;IACvBE,UAAU,EAAEA,UAAW;IACvBC,KAAK,EAAEA,KAAM;IACbiB,oBAAoB,EAAEA;EAAqB,CAC5C,CAAC;AAEN,CACF,CAAC;AAED,MAAMY,oBAAoB,GAAGnD,IAAI,CAACS,YAAY,CAAC;AAC/C0C,oBAAoB,CAACC,WAAW,GAAG,cAAc;AAEjD,SAASD,oBAAoB,IAAI1C,YAAY"}
|
package/dist/PasswordField.js
CHANGED
|
@@ -12,14 +12,16 @@ import _IconButton from "@mui/material/IconButton";
|
|
|
12
12
|
*
|
|
13
13
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
14
14
|
*/
|
|
15
|
-
import { forwardRef, memo, useCallback, useState } from "react";
|
|
15
|
+
import { forwardRef, memo, useCallback, useRef, useState } from "react";
|
|
16
16
|
import { ShowIcon, HideIcon } from "./icons.generated/index.js";
|
|
17
17
|
import { Field } from "./Field.js";
|
|
18
18
|
import { useTranslation } from "react-i18next";
|
|
19
|
+
import { getControlState, useInputValues } from "./inputUtils.js";
|
|
19
20
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
21
|
const PasswordField = forwardRef((_ref, ref) => {
|
|
21
22
|
let {
|
|
22
23
|
autoCompleteType,
|
|
24
|
+
defaultValue,
|
|
23
25
|
errorMessage,
|
|
24
26
|
hasInitialFocus,
|
|
25
27
|
hint,
|
|
@@ -30,7 +32,7 @@ const PasswordField = forwardRef((_ref, ref) => {
|
|
|
30
32
|
isReadOnly,
|
|
31
33
|
label,
|
|
32
34
|
name: nameOverride,
|
|
33
|
-
onChange,
|
|
35
|
+
onChange: onChangeProp,
|
|
34
36
|
onFocus,
|
|
35
37
|
onBlur,
|
|
36
38
|
placeholder,
|
|
@@ -44,6 +46,18 @@ const PasswordField = forwardRef((_ref, ref) => {
|
|
|
44
46
|
const togglePasswordVisibility = useCallback(() => {
|
|
45
47
|
setInputType(inputType => inputType === "password" ? "text" : "password");
|
|
46
48
|
}, []);
|
|
49
|
+
const controlledStateRef = useRef(getControlState({
|
|
50
|
+
controlledValue: value,
|
|
51
|
+
uncontrolledValue: defaultValue
|
|
52
|
+
}));
|
|
53
|
+
const inputValues = useInputValues({
|
|
54
|
+
defaultValue,
|
|
55
|
+
value,
|
|
56
|
+
controlState: controlledStateRef.current
|
|
57
|
+
});
|
|
58
|
+
const onChange = useCallback(event => {
|
|
59
|
+
onChangeProp?.(event);
|
|
60
|
+
}, [onChangeProp]);
|
|
47
61
|
const renderFieldComponent = useCallback(_ref2 => {
|
|
48
62
|
let {
|
|
49
63
|
ariaDescribedBy,
|
|
@@ -52,6 +66,7 @@ const PasswordField = forwardRef((_ref, ref) => {
|
|
|
52
66
|
labelElementId
|
|
53
67
|
} = _ref2;
|
|
54
68
|
return _jsx(_InputBase, {
|
|
69
|
+
...inputValues,
|
|
55
70
|
"aria-describedby": ariaDescribedBy,
|
|
56
71
|
autoComplete: inputType === "password" ? autoCompleteType : "off",
|
|
57
72
|
autoFocus: hasInitialFocus,
|
|
@@ -78,10 +93,9 @@ const PasswordField = forwardRef((_ref, ref) => {
|
|
|
78
93
|
readOnly: isReadOnly,
|
|
79
94
|
ref: ref,
|
|
80
95
|
required: !isOptional,
|
|
81
|
-
type: inputType
|
|
82
|
-
value: value
|
|
96
|
+
type: inputType
|
|
83
97
|
});
|
|
84
|
-
}, [autoCompleteType, hasInitialFocus, t, togglePasswordVisibility, inputType, nameOverride, onChange, onFocus, onBlur, placeholder, isOptional, isReadOnly, hasShowPassword, ref, testId
|
|
98
|
+
}, [autoCompleteType, hasInitialFocus, inputValues, t, togglePasswordVisibility, inputType, nameOverride, onChange, onFocus, onBlur, placeholder, isOptional, isReadOnly, hasShowPassword, ref, testId]);
|
|
85
99
|
return _jsx(Field, {
|
|
86
100
|
errorMessage: errorMessage,
|
|
87
101
|
fieldType: "single",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PasswordField.js","names":["forwardRef","memo","useCallback","useState","ShowIcon","HideIcon","Field","useTranslation","jsx","_jsx","PasswordField","_ref","ref","autoCompleteType","errorMessage","hasInitialFocus","hint","id","idOverride","isDisabled","isOptional","hasShowPassword","isReadOnly","label","name","nameOverride","onChange","onFocus","onBlur","placeholder","testId","value","t","inputType","setInputType","togglePasswordVisibility","renderFieldComponent","_ref2","ariaDescribedBy","errorMessageElementId","labelElementId","_InputBase","autoComplete","autoFocus","endAdornment","_InputAdornment","position","children","_IconButton","onClick","inputProps","role","readOnly","required","type","fieldType","hasVisibleLabel","MemoizedPasswordField","displayName"],"sources":["../src/PasswordField.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport { InputAdornment, InputBase, IconButton } from \"@mui/material\";\nimport {\n ChangeEventHandler,\n FocusEventHandler,\n forwardRef,\n memo,\n useCallback,\n useState,\n} from \"react\";\n\nimport { ShowIcon, HideIcon } from \"./icons.generated\";\nimport { Field } from \"./Field\";\nimport { FieldComponentProps } from \"./FieldComponentProps\";\nimport type { SeleniumProps } from \"./SeleniumProps\";\nimport { useTranslation } from \"react-i18next\";\n\nexport type PasswordFieldProps = {\n /**\n * This prop helps users to fill forms faster, especially on mobile devices.\n * The name can be confusing, as it's more like an autofill.\n * You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).\n */\n autoCompleteType?: \"current-password\" | \"new-password\";\n /**\n * If `true`, the component will receive focus automatically.\n */\n hasInitialFocus?: boolean;\n /**\n * If `true`, the show/hide icon is not shown to the user\n */\n hasShowPassword?: boolean;\n /**\n * The label for the `input` element.\n */\n label: string;\n /**\n * Callback fired when the `input` element loses focus.\n */\n onBlur?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;\n /**\n * Callback fired when the value is changed.\n */\n onChange?: ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;\n /**\n * Callback fired when the `input` element get focus.\n */\n onFocus?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;\n /**\n * The short hint displayed in the `input` before the user enters a value.\n */\n placeholder?: string;\n /**\n * The value of the `input` element, required for a controlled component.\n */\n value?: string;\n} & FieldComponentProps &\n SeleniumProps;\n\nconst PasswordField = forwardRef<HTMLInputElement, PasswordFieldProps>(\n (\n {\n autoCompleteType,\n errorMessage,\n hasInitialFocus,\n hint,\n id: idOverride,\n isDisabled = false,\n isOptional = false,\n hasShowPassword = true,\n isReadOnly,\n label,\n name: nameOverride,\n onChange,\n onFocus,\n onBlur,\n placeholder,\n testId,\n value,\n },\n ref\n ) => {\n const { t } = useTranslation();\n const [inputType, setInputType] = useState(\"password\");\n\n const togglePasswordVisibility = useCallback(() => {\n setInputType((inputType) =>\n inputType === \"password\" ? \"text\" : \"password\"\n );\n }, []);\n\n const renderFieldComponent = useCallback(\n ({ ariaDescribedBy, errorMessageElementId, id, labelElementId }) => (\n <InputBase\n aria-describedby={ariaDescribedBy}\n autoComplete={inputType === \"password\" ? autoCompleteType : \"off\"}\n /* eslint-disable-next-line jsx-a11y/no-autofocus */\n autoFocus={hasInitialFocus}\n data-se={testId}\n endAdornment={\n hasShowPassword && (\n <InputAdornment position=\"end\">\n <IconButton\n aria-label={\n inputType === \"password\"\n ? t(\"passwordfield.icon.label.show\")\n : t(\"passwordfield.icon.label.hide\")\n }\n onClick={togglePasswordVisibility}\n >\n {inputType === \"password\" ? <ShowIcon /> : <HideIcon />}\n </IconButton>\n </InputAdornment>\n )\n }\n id={id}\n inputProps={{\n \"aria-errormessage\": errorMessageElementId,\n \"aria-labelledby\": labelElementId,\n // role: \"textbox\" Added because password inputs don't have an implicit role assigned. This causes problems with element selection.\n role: \"textbox\",\n }}\n name={nameOverride ?? id}\n onChange={onChange}\n onFocus={onFocus}\n onBlur={onBlur}\n placeholder={placeholder}\n readOnly={isReadOnly}\n ref={ref}\n required={!isOptional}\n type={inputType}\n value={value}\n />\n ),\n [\n autoCompleteType,\n hasInitialFocus,\n t,\n togglePasswordVisibility,\n inputType,\n nameOverride,\n onChange,\n onFocus,\n onBlur,\n placeholder,\n isOptional,\n isReadOnly,\n hasShowPassword,\n ref,\n testId,\n value,\n ]\n );\n\n return (\n <Field\n errorMessage={errorMessage}\n fieldType=\"single\"\n hasVisibleLabel\n hint={hint}\n id={idOverride}\n isDisabled={isDisabled}\n isOptional={isOptional}\n label={label}\n renderFieldComponent={renderFieldComponent}\n />\n );\n }\n);\n\nconst MemoizedPasswordField = memo(PasswordField);\nMemoizedPasswordField.displayName = \"PasswordField\";\n\nexport { MemoizedPasswordField as PasswordField };\n"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA,SAGEA,UAAU,EACVC,IAAI,EACJC,WAAW,EACXC,QAAQ,QACH,OAAO;AAAC,SAENC,QAAQ,EA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D,IAAI,CAACS,aAAa,CAAC;AACjD+C,qBAAqB,CAACC,WAAW,GAAG,eAAe;AAEnD,SAASD,qBAAqB,IAAI/C,aAAa"}
|
|
1
|
+
{"version":3,"file":"PasswordField.js","names":["forwardRef","memo","useCallback","useRef","useState","ShowIcon","HideIcon","Field","useTranslation","getControlState","useInputValues","jsx","_jsx","PasswordField","_ref","ref","autoCompleteType","defaultValue","errorMessage","hasInitialFocus","hint","id","idOverride","isDisabled","isOptional","hasShowPassword","isReadOnly","label","name","nameOverride","onChange","onChangeProp","onFocus","onBlur","placeholder","testId","value","t","inputType","setInputType","togglePasswordVisibility","controlledStateRef","controlledValue","uncontrolledValue","inputValues","controlState","current","event","renderFieldComponent","_ref2","ariaDescribedBy","errorMessageElementId","labelElementId","_InputBase","autoComplete","autoFocus","endAdornment","_InputAdornment","position","children","_IconButton","onClick","inputProps","role","readOnly","required","type","fieldType","hasVisibleLabel","MemoizedPasswordField","displayName"],"sources":["../src/PasswordField.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport { InputAdornment, InputBase, IconButton } from \"@mui/material\";\nimport {\n ChangeEventHandler,\n FocusEventHandler,\n forwardRef,\n memo,\n useCallback,\n useRef,\n useState,\n} from \"react\";\n\nimport { ShowIcon, HideIcon } from \"./icons.generated\";\nimport { Field } from \"./Field\";\nimport { FieldComponentProps } from \"./FieldComponentProps\";\nimport type { SeleniumProps } from \"./SeleniumProps\";\nimport { useTranslation } from \"react-i18next\";\nimport { getControlState, useInputValues } from \"./inputUtils\";\n\nexport type PasswordFieldProps = {\n /**\n * This prop helps users to fill forms faster, especially on mobile devices.\n * The name can be confusing, as it's more like an autofill.\n * You can learn more about it [following the specification](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill).\n */\n autoCompleteType?: \"current-password\" | \"new-password\";\n /**\n * initial value for input. Use when component in uncontrolled.\n */\n defaultValue?: string;\n /**\n * If `true`, the component will receive focus automatically.\n */\n hasInitialFocus?: boolean;\n /**\n * If `true`, the show/hide icon is not shown to the user\n */\n hasShowPassword?: boolean;\n /**\n * The label for the `input` element.\n */\n label: string;\n /**\n * Callback fired when the `input` element loses focus.\n */\n onBlur?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;\n /**\n * Callback fired when the value is changed.\n */\n onChange?: ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;\n /**\n * Callback fired when the `input` element get focus.\n */\n onFocus?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;\n /**\n * The short hint displayed in the `input` before the user enters a value.\n */\n placeholder?: string;\n /**\n * The value of the `input` element. Use when component is controlled.\n */\n value?: string;\n} & FieldComponentProps &\n SeleniumProps;\n\nconst PasswordField = forwardRef<HTMLInputElement, PasswordFieldProps>(\n (\n {\n autoCompleteType,\n defaultValue,\n errorMessage,\n hasInitialFocus,\n hint,\n id: idOverride,\n isDisabled = false,\n isOptional = false,\n hasShowPassword = true,\n isReadOnly,\n label,\n name: nameOverride,\n onChange: onChangeProp,\n onFocus,\n onBlur,\n placeholder,\n testId,\n value,\n },\n ref\n ) => {\n const { t } = useTranslation();\n const [inputType, setInputType] = useState(\"password\");\n\n const togglePasswordVisibility = useCallback(() => {\n setInputType((inputType) =>\n inputType === \"password\" ? \"text\" : \"password\"\n );\n }, []);\n\n const controlledStateRef = useRef(\n getControlState({\n controlledValue: value,\n uncontrolledValue: defaultValue,\n })\n );\n const inputValues = useInputValues({\n defaultValue,\n value,\n controlState: controlledStateRef.current,\n });\n\n const onChange = useCallback<\n ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>\n >(\n (event) => {\n onChangeProp?.(event);\n },\n [onChangeProp]\n );\n\n const renderFieldComponent = useCallback(\n ({ ariaDescribedBy, errorMessageElementId, id, labelElementId }) => (\n <InputBase\n {...inputValues}\n aria-describedby={ariaDescribedBy}\n autoComplete={inputType === \"password\" ? autoCompleteType : \"off\"}\n /* eslint-disable-next-line jsx-a11y/no-autofocus */\n autoFocus={hasInitialFocus}\n data-se={testId}\n endAdornment={\n hasShowPassword && (\n <InputAdornment position=\"end\">\n <IconButton\n aria-label={\n inputType === \"password\"\n ? t(\"passwordfield.icon.label.show\")\n : t(\"passwordfield.icon.label.hide\")\n }\n onClick={togglePasswordVisibility}\n >\n {inputType === \"password\" ? <ShowIcon /> : <HideIcon />}\n </IconButton>\n </InputAdornment>\n )\n }\n id={id}\n inputProps={{\n \"aria-errormessage\": errorMessageElementId,\n \"aria-labelledby\": labelElementId,\n // role: \"textbox\" Added because password inputs don't have an implicit role assigned. This causes problems with element selection.\n role: \"textbox\",\n }}\n name={nameOverride ?? id}\n onChange={onChange}\n onFocus={onFocus}\n onBlur={onBlur}\n placeholder={placeholder}\n readOnly={isReadOnly}\n ref={ref}\n required={!isOptional}\n type={inputType}\n />\n ),\n [\n autoCompleteType,\n hasInitialFocus,\n inputValues,\n t,\n togglePasswordVisibility,\n inputType,\n nameOverride,\n onChange,\n onFocus,\n onBlur,\n placeholder,\n isOptional,\n isReadOnly,\n hasShowPassword,\n ref,\n testId,\n ]\n );\n\n return (\n <Field\n errorMessage={errorMessage}\n fieldType=\"single\"\n hasVisibleLabel\n hint={hint}\n id={idOverride}\n isDisabled={isDisabled}\n isOptional={isOptional}\n label={label}\n renderFieldComponent={renderFieldComponent}\n />\n );\n }\n);\n\nconst MemoizedPasswordField = memo(PasswordField);\nMemoizedPasswordField.displayName = \"PasswordField\";\n\nexport { MemoizedPasswordField as PasswordField };\n"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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AC;EAAA,CACH,EACD,CACEtB,gBAAgB,EAChBG,eAAe,EACfyB,WAAW,EACXP,CAAC,EACDG,wBAAwB,EACxBF,SAAS,EACTT,YAAY,EACZC,QAAQ,EACRE,OAAO,EACPC,MAAM,EACNC,WAAW,EACXV,UAAU,EACVE,UAAU,EACVD,eAAe,EACfV,GAAG,EACHoB,MAAM,CAEV,CAAC;EAED,OACEvB,IAAA,CAACL,KAAK;IACJW,YAAY,EAAEA,YAAa;IAC3BiD,SAAS,EAAC,QAAQ;IAClBC,eAAe;IACfhD,IAAI,EAAEA,IAAK;IACXC,EAAE,EAAEC,UAAW;IACfC,UAAU,EAAEA,UAAW;IACvBC,UAAU,EAAEA,UAAW;IACvBG,KAAK,EAAEA,KAAM;IACbqB,oBAAoB,EAAEA;EAAqB,CAC5C,CAAC;AAEN,CACF,CAAC;AAED,MAAMqB,qBAAqB,GAAGpE,IAAI,CAACY,aAAa,CAAC;AACjDwD,qBAAqB,CAACC,WAAW,GAAG,eAAe;AAEnD,SAASD,qBAAqB,IAAIxD,aAAa"}
|
package/dist/RadioGroup.js
CHANGED
|
@@ -10,9 +10,9 @@ import _RadioGroup from "@mui/material/RadioGroup";
|
|
|
10
10
|
*
|
|
11
11
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
12
12
|
*/
|
|
13
|
-
import { memo, useCallback } from "react";
|
|
13
|
+
import { memo, useCallback, useRef } from "react";
|
|
14
14
|
import { Field } from "./Field.js";
|
|
15
|
-
import {
|
|
15
|
+
import { getControlState, useInputValues } from "./inputUtils.js";
|
|
16
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
17
|
const RadioGroup = _ref => {
|
|
18
18
|
let {
|
|
@@ -28,14 +28,18 @@ const RadioGroup = _ref => {
|
|
|
28
28
|
testId,
|
|
29
29
|
value
|
|
30
30
|
} = _ref;
|
|
31
|
-
const
|
|
31
|
+
const controlledStateRef = useRef(getControlState({
|
|
32
32
|
controlledValue: value,
|
|
33
33
|
uncontrolledValue: defaultValue
|
|
34
|
+
}));
|
|
35
|
+
const inputValues = useInputValues({
|
|
36
|
+
defaultValue,
|
|
37
|
+
value,
|
|
38
|
+
controlState: controlledStateRef.current
|
|
34
39
|
});
|
|
35
40
|
const onChange = useCallback((event, value) => {
|
|
36
|
-
setLocalValue(value);
|
|
37
41
|
onChangeProp?.(event, value);
|
|
38
|
-
}, [onChangeProp
|
|
42
|
+
}, [onChangeProp]);
|
|
39
43
|
const renderFieldComponent = useCallback(_ref2 => {
|
|
40
44
|
let {
|
|
41
45
|
ariaDescribedBy,
|
|
@@ -44,18 +48,17 @@ const RadioGroup = _ref => {
|
|
|
44
48
|
labelElementId
|
|
45
49
|
} = _ref2;
|
|
46
50
|
return _jsx(_RadioGroup, {
|
|
51
|
+
...inputValues,
|
|
47
52
|
"aria-describedby": ariaDescribedBy,
|
|
48
53
|
"aria-errormessage": errorMessageElementId,
|
|
49
54
|
"aria-labelledby": labelElementId,
|
|
50
55
|
"data-se": testId,
|
|
51
|
-
defaultValue: defaultValue,
|
|
52
56
|
id: id,
|
|
53
57
|
name: nameOverride ?? id,
|
|
54
58
|
onChange: onChange,
|
|
55
|
-
value: localValue,
|
|
56
59
|
children: children
|
|
57
60
|
});
|
|
58
|
-
}, [children,
|
|
61
|
+
}, [children, inputValues, nameOverride, onChange, testId]);
|
|
59
62
|
return _jsx(Field, {
|
|
60
63
|
errorMessage: errorMessage,
|
|
61
64
|
fieldType: "group",
|