@try-at-software/input-elements 1.2.0-beta.4 → 1.2.0-beta.7
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/lib/SingleValueInputElements/DropdownInputElement/DropdownInput.js +7 -1
- package/lib/SingleValueInputElements/DropdownInputElement/IDropdownInputProps.d.ts +2 -0
- package/lib/SingleValueInputElements/SingleValueInputElement.js +10 -11
- package/lib/Utilities/DropdownHelper.js +1 -0
- package/package.json +1 -1
|
@@ -18,9 +18,15 @@ const DropdownInputComponent = (props) => {
|
|
|
18
18
|
props.invalidateInput(invalidationOptions);
|
|
19
19
|
}, [props.value, normalizedOptions, props.consistencyErrorMessage, props.invalidateInput]);
|
|
20
20
|
const DropdownComponent = react_2.useMemo(() => { var _a; return (_a = dynamicProps.dropdownComponent) !== null && _a !== void 0 ? _a : react_1.Dropdown; }, [dynamicProps.dropdownComponent]);
|
|
21
|
+
const onChange = react_2.useCallback((_event, option) => !!props.onChange && props.onChange(option.id), [props.onChange]);
|
|
22
|
+
const onRenderOption = react_2.useCallback((option, defaultRender) => {
|
|
23
|
+
if (!dynamicProps.renderOption)
|
|
24
|
+
return defaultRender(option);
|
|
25
|
+
return dynamicProps.renderOption(option.id);
|
|
26
|
+
}, []);
|
|
21
27
|
return (React.createElement(React.Fragment, null,
|
|
22
28
|
React.createElement(Components_1.LabelRenderer, { label: props.label, required: !!props.renderRequiredIndicator }),
|
|
23
|
-
React.createElement(DropdownComponent, { "data-automationid": "dropdown-input", options: normalizedOptions, onChange:
|
|
29
|
+
React.createElement(DropdownComponent, { "data-automationid": "dropdown-input", options: normalizedOptions, onChange: onChange, onRenderOption: onRenderOption, placeholder: operativeProps.placeholder,
|
|
24
30
|
// This value should never be `undefined`.
|
|
25
31
|
selectedKey: props.value || ((_a = dynamicProps.defaultOption) === null || _a === void 0 ? void 0 : _a.key) || null, disabled: dynamicProps.isDisabled }),
|
|
26
32
|
React.createElement(Components_1.ErrorRenderer, { error: props.errorMessage, messageBarType: react_1.MessageBarType.error })));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { IBaseInputElementDynamicProps } from '../IBaseInputElementDynamicProps';
|
|
2
3
|
import { IDropdownInputOption } from './IDropdownInputOption';
|
|
3
4
|
export interface IDropdownInputProps extends IBaseInputElementDynamicProps {
|
|
@@ -6,4 +7,5 @@ export interface IDropdownInputProps extends IBaseInputElementDynamicProps {
|
|
|
6
7
|
* The default option for the dropdown.
|
|
7
8
|
*/
|
|
8
9
|
defaultOption: IDropdownInputOption;
|
|
10
|
+
renderOption?: (optionId: string) => JSX.Element;
|
|
9
11
|
}
|
|
@@ -25,7 +25,7 @@ class SingleValueInputElement extends ExtendedInputElement_1.ExtendedInputElemen
|
|
|
25
25
|
};
|
|
26
26
|
this.invalidateInput = (options) => {
|
|
27
27
|
this._isInvalidated = true;
|
|
28
|
-
if (options.errorMessage)
|
|
28
|
+
if (options === null || options === void 0 ? void 0 : options.errorMessage)
|
|
29
29
|
this.setError(options.errorMessage);
|
|
30
30
|
this.updateInternally();
|
|
31
31
|
this.invalidValueChangeSubscriptions.forEach((x) => x === null || x === void 0 ? void 0 : x());
|
|
@@ -86,11 +86,7 @@ class SingleValueInputElement extends ExtendedInputElement_1.ExtendedInputElemen
|
|
|
86
86
|
}
|
|
87
87
|
/** @inheritdoc */
|
|
88
88
|
get isValid() {
|
|
89
|
-
if (this._isInvalidated)
|
|
90
|
-
return false;
|
|
91
|
-
if (this.isLoading)
|
|
92
|
-
return false;
|
|
93
|
-
if (this.errorMessage && this.errorMessage.length > 0)
|
|
89
|
+
if (this._isInvalidated || this.isLoading || this.errorMessage)
|
|
94
90
|
return false;
|
|
95
91
|
return (!!this._configuration && !this._configuration.isRequired) || this._valueIsSet || this._initialValueIsSet;
|
|
96
92
|
}
|
|
@@ -127,17 +123,20 @@ class SingleValueInputElement extends ExtendedInputElement_1.ExtendedInputElemen
|
|
|
127
123
|
var _a, _b, _c, _d, _e;
|
|
128
124
|
if (!!((_a = this._configuration) === null || _a === void 0 ? void 0 : _a.shouldExecuteValidation) && this._configuration.shouldExecuteValidation() === false)
|
|
129
125
|
return;
|
|
130
|
-
let errorMessage =
|
|
126
|
+
let errorMessage = undefined;
|
|
131
127
|
if (((_b = this._configuration) === null || _b === void 0 ? void 0 : _b.isRequired) && !this.valueIsValid()) {
|
|
132
128
|
// If a value is required but the input field is empty.
|
|
133
129
|
errorMessage = ((_c = this._configuration) === null || _c === void 0 ? void 0 : _c.requiredValidationMessage) || `The field is required`;
|
|
134
130
|
}
|
|
135
131
|
else if (((_d = this._configuration) === null || _d === void 0 ? void 0 : _d.isRequired) || this.value || ((_e = this._configuration) === null || _e === void 0 ? void 0 : _e.executeAllValidations)) {
|
|
136
132
|
// If a value is provided.
|
|
137
|
-
this.validationRules
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
133
|
+
for (const validationRule of this.validationRules) {
|
|
134
|
+
const currentError = validationRule(this.value);
|
|
135
|
+
if (currentError) {
|
|
136
|
+
errorMessage = currentError;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
141
140
|
}
|
|
142
141
|
this.setError(errorMessage);
|
|
143
142
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@try-at-software/input-elements",
|
|
3
|
-
"version": "1.2.0-beta.
|
|
3
|
+
"version": "1.2.0-beta.7",
|
|
4
4
|
"description": "A package providing different input elements that are extensible and easily configurable for your custom needs.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|