@inera/ids-react 9.0.3 → 9.0.4
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.
|
@@ -11,6 +11,7 @@ function IDSRadioGroup({ name, required, noValidation, invalid, errorMsg, childr
|
|
|
11
11
|
const reactId = useId();
|
|
12
12
|
const groupName = !!name ? name : `radio-group-name-${reactId}`;
|
|
13
13
|
const errorMsgId = `radio-error-${reactId}`;
|
|
14
|
+
const groupInvalid = required && !isValid && hasInteracted && !noValidation;
|
|
14
15
|
const clonedChildren = React.Children.map(children, child => {
|
|
15
16
|
if (!React.isValidElement(child))
|
|
16
17
|
return child;
|
|
@@ -18,20 +19,20 @@ function IDSRadioGroup({ name, required, noValidation, invalid, errorMsg, childr
|
|
|
18
19
|
const { id, ...rest } = child.props;
|
|
19
20
|
const cloneProps = {
|
|
20
21
|
...rest,
|
|
21
|
-
key: child.
|
|
22
|
+
key: child.key,
|
|
22
23
|
id: child.props.id,
|
|
23
24
|
name: groupName,
|
|
24
25
|
required: required && !noValidation,
|
|
25
26
|
noValidation,
|
|
26
27
|
groupErrorMsgId: errorMsg ? errorMsgId : undefined,
|
|
27
|
-
groupInvalid:
|
|
28
|
+
groupInvalid: groupInvalid,
|
|
28
29
|
onChange: onRadioChange
|
|
29
30
|
};
|
|
30
31
|
return React.cloneElement(child, cloneProps);
|
|
31
32
|
}
|
|
32
33
|
return child;
|
|
33
34
|
});
|
|
34
|
-
return (jsx(IDSRadioGroupBase, { ...props, groupRef: groupRef,
|
|
35
|
+
return (jsx(IDSRadioGroupBase, { ...props, groupRef: groupRef, required: required, invalid: groupInvalid || invalid, errorMsg: !noValidation && errorMsg, errorMsgId: errorMsgId, children: clonedChildren }));
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
export { IDSRadioGroup };
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
3
|
import { forwardRef, useRef, useImperativeHandle } from 'react';
|
|
4
|
-
import { useInputValidity } from '../form-hooks/useInputValidity.js';
|
|
5
4
|
import { IDSRadioBase } from './radio-base.js';
|
|
6
5
|
|
|
7
6
|
const IDSRadio = forwardRef(({ groupErrorMsgId, invalid = false, groupInvalid = false, noValidation = false, children, ...props }, ref) => {
|
|
8
7
|
const radioRef = useRef(null);
|
|
9
|
-
const
|
|
10
|
-
const isInvalid = invalid || groupInvalid || (!hasValidValue && !noValidation);
|
|
8
|
+
const isInvalid = invalid || groupInvalid;
|
|
11
9
|
// Expose ref to user
|
|
12
10
|
useImperativeHandle(ref, () => radioRef.current);
|
|
13
11
|
return (jsx(IDSRadioBase, { ...props, inputRef: radioRef, errorMsgId: groupErrorMsgId, invalid: isInvalid, children: children }));
|