@norges-domstoler/dds-components 18.0.0 → 18.1.0
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/dist/index.d.mts +21 -18
- package/dist/index.d.ts +21 -18
- package/dist/index.js +27 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -10700,12 +10700,17 @@ var useRadioButtonGroup = () => {
|
|
|
10700
10700
|
|
|
10701
10701
|
// src/components/SelectionControl/RadioButton/RadioButton.tsx
|
|
10702
10702
|
import { jsx as jsx281, jsxs as jsxs71 } from "react/jsx-runtime";
|
|
10703
|
-
var
|
|
10703
|
+
var getIsChecked = ({
|
|
10704
|
+
value,
|
|
10705
|
+
group,
|
|
10706
|
+
checked
|
|
10707
|
+
}) => {
|
|
10708
|
+
if (checked !== void 0) return checked;
|
|
10704
10709
|
if (typeof value !== "undefined" && value !== null && group) {
|
|
10705
10710
|
if (typeof value === "number") {
|
|
10706
|
-
return value === Number(group
|
|
10711
|
+
return value === Number(group.value);
|
|
10707
10712
|
}
|
|
10708
|
-
return value ===
|
|
10713
|
+
return value === group.value;
|
|
10709
10714
|
}
|
|
10710
10715
|
return !!value;
|
|
10711
10716
|
};
|
|
@@ -10739,7 +10744,7 @@ var RadioButton = forwardRef87(
|
|
|
10739
10744
|
const radioButtonGroup = useRadioButtonGroup();
|
|
10740
10745
|
const handleChange = (event) => {
|
|
10741
10746
|
onChange && onChange(event);
|
|
10742
|
-
radioButtonGroup == null ? void 0 : radioButtonGroup.onChange(event);
|
|
10747
|
+
radioButtonGroup == null ? void 0 : radioButtonGroup.onChange(event, event.target.value);
|
|
10743
10748
|
};
|
|
10744
10749
|
const describedByIds = [];
|
|
10745
10750
|
if (radioButtonGroup == null ? void 0 : radioButtonGroup.errorMessageId)
|
|
@@ -10748,6 +10753,7 @@ var RadioButton = forwardRef87(
|
|
|
10748
10753
|
const isReadOnly = readOnly || (radioButtonGroup == null ? void 0 : radioButtonGroup.readOnly);
|
|
10749
10754
|
const isDisabled = disabled || (radioButtonGroup == null ? void 0 : radioButtonGroup.disabled);
|
|
10750
10755
|
const hasError = error || (radioButtonGroup == null ? void 0 : radioButtonGroup.error);
|
|
10756
|
+
const isChecked = getIsChecked({ value, group: radioButtonGroup, checked });
|
|
10751
10757
|
return /* @__PURE__ */ jsxs71(
|
|
10752
10758
|
Label2,
|
|
10753
10759
|
{
|
|
@@ -10768,7 +10774,7 @@ var RadioButton = forwardRef87(
|
|
|
10768
10774
|
name: name != null ? name : radioButtonGroup == null ? void 0 : radioButtonGroup.name,
|
|
10769
10775
|
disabled: isDisabled,
|
|
10770
10776
|
required: required || !!(radioButtonGroup == null ? void 0 : radioButtonGroup.required),
|
|
10771
|
-
checked:
|
|
10777
|
+
checked: isChecked,
|
|
10772
10778
|
onChange: readOnlyChangeHandler(isReadOnly, handleChange),
|
|
10773
10779
|
value,
|
|
10774
10780
|
"aria-describedby": describedByIds.length > 0 ? describedByIds.join(" ") : void 0,
|
|
@@ -10819,6 +10825,7 @@ var RadioButtonGroupInner = (props, ref) => {
|
|
|
10819
10825
|
readOnly = false,
|
|
10820
10826
|
direction = "row",
|
|
10821
10827
|
value,
|
|
10828
|
+
defaultValue,
|
|
10822
10829
|
children,
|
|
10823
10830
|
required = false,
|
|
10824
10831
|
onChange,
|
|
@@ -10828,13 +10835,22 @@ var RadioButtonGroupInner = (props, ref) => {
|
|
|
10828
10835
|
...rest
|
|
10829
10836
|
} = props;
|
|
10830
10837
|
const { "aria-required": ariaRequired = false } = htmlProps;
|
|
10831
|
-
const [
|
|
10838
|
+
const [uncontrolledValue, setUncontrolledValue] = useState25(
|
|
10839
|
+
defaultValue
|
|
10840
|
+
);
|
|
10832
10841
|
const generatedId = useId24();
|
|
10833
10842
|
const uniqueGroupId = groupId != null ? groupId : `${generatedId}-radioButtonGroup`;
|
|
10834
|
-
const
|
|
10835
|
-
|
|
10836
|
-
|
|
10837
|
-
|
|
10843
|
+
const isControlled = value !== void 0;
|
|
10844
|
+
const groupValue = isControlled ? value : uncontrolledValue;
|
|
10845
|
+
const handleChange = (e) => {
|
|
10846
|
+
const newValue = e.target.value;
|
|
10847
|
+
if (!isControlled) {
|
|
10848
|
+
setUncontrolledValue(newValue);
|
|
10849
|
+
}
|
|
10850
|
+
if (onChange) {
|
|
10851
|
+
onChange(e, newValue);
|
|
10852
|
+
}
|
|
10853
|
+
};
|
|
10838
10854
|
const hasErrorMessage = !!errorMessage;
|
|
10839
10855
|
const showRequiredMarker = required || ariaRequired;
|
|
10840
10856
|
const tipId = tip && `${uniqueGroupId}-tip`;
|
|
@@ -10842,6 +10858,7 @@ var RadioButtonGroupInner = (props, ref) => {
|
|
|
10842
10858
|
const contextProps = {
|
|
10843
10859
|
name,
|
|
10844
10860
|
disabled,
|
|
10861
|
+
defaultValue,
|
|
10845
10862
|
error: hasErrorMessage,
|
|
10846
10863
|
errorMessageId,
|
|
10847
10864
|
required,
|