@inera/ids-react 9.0.1 → 9.0.3
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/components/accordion/accordion.js +3 -0
- package/components/form/checkbox/checkbox-base.d.ts +1 -1
- package/components/form/checkbox/checkbox-base.js +4 -3
- package/components/form/checkbox/checkbox-group-base.js +1 -1
- package/components/form/checkbox/checkbox-group.js +1 -1
- package/components/form/checkbox/checkbox.js +1 -13
- package/components/form/darkmode-toggle/darkmode-toggle.js +1 -1
- package/components/form/form-hooks/useInputValidity.js +2 -2
- package/components/form/radio/radio-group-base.js +1 -1
- package/components/form/select-multiple/select-multiple.js +6 -3
- package/components/form/toggle/toggle.js +1 -1
- package/components/side-menu/side-menu.js +4 -1
- package/package.json +3 -2
|
@@ -12,6 +12,9 @@ function IDSAccordion({ headline, accordions, level = 1, headlineSize = level ==
|
|
|
12
12
|
setIsLean(true);
|
|
13
13
|
}
|
|
14
14
|
}, [level]);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
setIsExpanded(expanded);
|
|
17
|
+
}, [expanded]);
|
|
15
18
|
const toggleExpanded = () => {
|
|
16
19
|
setIsExpanded(prev => !prev);
|
|
17
20
|
if (isExpanded)
|
|
@@ -16,4 +16,4 @@ export interface IDSCheckboxBaseProps extends InputHTMLAttributes<HTMLInputEleme
|
|
|
16
16
|
errorMsgId?: string;
|
|
17
17
|
inputRef?: React.Ref<HTMLInputElement>;
|
|
18
18
|
}
|
|
19
|
-
export declare function IDSCheckboxBase({ invalid, disabled, required, light, block, compact, focusAnchor, errorMsg, tooltip, children, dataTestId, id, groupErrorMsgId, errorMsgId, inputRef, className, ...props }: IDSCheckboxBaseProps): ReactElement;
|
|
19
|
+
export declare function IDSCheckboxBase({ invalid, disabled, required, indeterminate, light, block, compact, focusAnchor, errorMsg, tooltip, children, dataTestId, id, groupErrorMsgId, errorMsgId, inputRef, className, ...props }: IDSCheckboxBaseProps): ReactElement;
|
|
@@ -3,22 +3,23 @@ import { useId } from 'react';
|
|
|
3
3
|
import clsx from 'clsx';
|
|
4
4
|
import { IDSErrorMessage } from '../error-message/error-message.js';
|
|
5
5
|
|
|
6
|
-
function IDSCheckboxBase({ invalid, disabled, required, light, block, compact, focusAnchor, errorMsg, tooltip, children, dataTestId, id, groupErrorMsgId, errorMsgId, inputRef, className, ...props }) {
|
|
6
|
+
function IDSCheckboxBase({ invalid, disabled, required, indeterminate, light, block, compact, focusAnchor, errorMsg, tooltip, children, dataTestId, id, groupErrorMsgId, errorMsgId, inputRef, className, ...props }) {
|
|
7
7
|
const reactId = useId();
|
|
8
8
|
const inputId = !!id ? id : `checkbox-base-${reactId}`;
|
|
9
9
|
const baseErrorMsgId = !!errorMsgId ? errorMsgId : `checkbox-base-error-${reactId}`;
|
|
10
10
|
const showErrorMsg = invalid && !!errorMsg;
|
|
11
|
-
const
|
|
11
|
+
const ariaErrorHandler = showErrorMsg || !!groupErrorMsgId
|
|
12
12
|
? {
|
|
13
13
|
"aria-describedby": groupErrorMsgId || baseErrorMsgId
|
|
14
14
|
}
|
|
15
15
|
: {};
|
|
16
|
+
const ariaCheckedHandler = indeterminate ? { "aria-checked": "mixed" } : {};
|
|
16
17
|
return (jsxs("div", { className: clsx("ids-checkbox-component", className), style: { display: "inline-flex", flexDirection: "column", gap: showErrorMsg ? "0.5rem" : "" }, "data-testid": dataTestId, children: [jsxs("div", { className: clsx("ids-checkbox", {
|
|
17
18
|
"ids-checkbox--light": light,
|
|
18
19
|
"ids-checkbox--block": block
|
|
19
20
|
}), "data-testid": dataTestId, children: [jsx("input", { id: inputId, ref: inputRef, type: "checkbox", className: clsx("ids-checkbox__input", {
|
|
20
21
|
"ids-focus-anchor": focusAnchor
|
|
21
|
-
}), "aria-invalid": invalid, disabled: disabled, "aria-disabled": disabled, required: required, "aria-required": required, ...
|
|
22
|
+
}), "aria-invalid": invalid, disabled: disabled, "aria-disabled": disabled, required: required, "aria-required": required, ...ariaErrorHandler, ...ariaCheckedHandler, ...props }), !!children && (jsxs("div", { className: clsx("ids-label-wrapper", {
|
|
22
23
|
"ids-label-wrapper--block": block
|
|
23
24
|
}), children: [jsx("label", { htmlFor: inputId, className: clsx("ids-checkbox__label ids-label", {
|
|
24
25
|
"ids-label--clickable": !disabled,
|
|
@@ -7,7 +7,7 @@ function IDSCheckboxGroupBase({ legend = "", errorMsg = "", compact = false, too
|
|
|
7
7
|
const baseErrorMsgId = !!errorMsgId ? errorMsgId : `checkbox-group-base-error-${useId()}`;
|
|
8
8
|
return (jsxs("fieldset", { ref: groupRef, className: clsx("ids-form-group__fieldset", {
|
|
9
9
|
"ids-form-group__fieldset--compact": compact
|
|
10
|
-
}, className), ...props, children: [legend && (jsx("div", { className: "ids-label-wrapper", children: jsxs("legend", { children: [legend, tooltip && jsx("span", { className: "ids-legend__tooltip", children: tooltip })] }) })), children, invalid && !!errorMsg && (jsx(IDSErrorMessage, { id: baseErrorMsgId, show: true, compact: true, children: errorMsg }))] }));
|
|
10
|
+
}, className), ...props, children: [legend && (jsx("div", { className: "ids-label-wrapper", children: jsxs("legend", { children: [legend, tooltip && jsx("span", { className: "ids-legend__tooltip", children: tooltip })] }) })), children, invalid && !!errorMsg && (jsx(IDSErrorMessage, { id: baseErrorMsgId, show: true, compact: true, style: { marginTop: compact ? "0.75rem" : "auto" }, children: errorMsg }))] }));
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export { IDSCheckboxGroupBase };
|
|
@@ -33,7 +33,7 @@ function IDSCheckboxGroup({ errorMsg = "", block, invalid, noValidation = false,
|
|
|
33
33
|
}
|
|
34
34
|
return child;
|
|
35
35
|
});
|
|
36
|
-
return (jsx(IDSCheckboxGroupBase, { ...props, groupRef: groupRef, invalid: !isValid || invalid, errorMsgId: errorMsgId, errorMsg: !noValidation && errorMsg, children: clonedChildren }));
|
|
36
|
+
return (jsx(IDSCheckboxGroupBase, { ...props, groupRef: groupRef, invalid: !isValid && hasInteracted || invalid, errorMsgId: errorMsgId, errorMsg: !noValidation && errorMsg, children: clonedChildren }));
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export { IDSCheckboxGroup };
|
|
@@ -15,19 +15,7 @@ const IDSCheckbox = forwardRef(({ invalid = false, noValidation = false, indeter
|
|
|
15
15
|
checkboxRef.current.indeterminate = indeterminate;
|
|
16
16
|
}
|
|
17
17
|
}, [indeterminate]);
|
|
18
|
-
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
const el = checkboxRef.current;
|
|
21
|
-
if (!el)
|
|
22
|
-
return;
|
|
23
|
-
const updateAriaChecked = () => {
|
|
24
|
-
el.setAttribute("aria-checked", el.indeterminate ? "mixed" : `${el.checked}`);
|
|
25
|
-
};
|
|
26
|
-
updateAriaChecked();
|
|
27
|
-
el.addEventListener("change", updateAriaChecked);
|
|
28
|
-
return () => el.removeEventListener("change", updateAriaChecked);
|
|
29
|
-
}, []);
|
|
30
|
-
return (jsx(IDSCheckboxBase, { ...props, inputRef: checkboxRef, invalid: isInvalid, children: children }));
|
|
18
|
+
return (jsx(IDSCheckboxBase, { ...props, inputRef: checkboxRef, invalid: isInvalid, indeterminate: indeterminate, children: children }));
|
|
31
19
|
});
|
|
32
20
|
IDSCheckbox.displayName = "IDSCheckbox";
|
|
33
21
|
|
|
@@ -6,7 +6,7 @@ const IDSDarkmodeToggle = forwardRef(({ id, dataTestId, focusAnchor, disabled, c
|
|
|
6
6
|
const inputId = !!id ? id : useId();
|
|
7
7
|
return (jsxs("div", { className: clsx("ids-darkmode-toggle", className), "data-testid": dataTestId, children: [jsx("input", { id: inputId, ref: ref, className: clsx("ids-darkmode-toggle__input", {
|
|
8
8
|
"ids-focus-anchor": focusAnchor
|
|
9
|
-
}), "aria-label": srText, disabled: disabled, type: "checkbox", role: "switch",
|
|
9
|
+
}), "aria-label": srText, disabled: disabled, type: "checkbox", role: "switch", ...props }), jsxs("div", { className: "ids-label-wrapper", children: [jsx("label", { htmlFor: inputId, className: "ids-darkmode-toggle__label ids-label ids-label--clickable", children: children }), tooltip && jsx("span", { className: "ids-label__tooltip", children: tooltip })] })] }));
|
|
10
10
|
});
|
|
11
11
|
IDSDarkmodeToggle.displayName = "IDSDarkmodeToggle";
|
|
12
12
|
|
|
@@ -14,14 +14,14 @@ function useInputValidity(ref, validateOnBlur) {
|
|
|
14
14
|
if (validateOnBlur) {
|
|
15
15
|
inputEl.addEventListener("blur", updateValidity);
|
|
16
16
|
}
|
|
17
|
-
inputEl.addEventListener("
|
|
17
|
+
inputEl.addEventListener("change", updateValidity);
|
|
18
18
|
inputEl.addEventListener("invalid", updateValidity);
|
|
19
19
|
return () => {
|
|
20
20
|
form?.removeEventListener("submit", updateValidity);
|
|
21
21
|
if (validateOnBlur) {
|
|
22
22
|
inputEl.removeEventListener("blur", updateValidity);
|
|
23
23
|
}
|
|
24
|
-
inputEl.removeEventListener("
|
|
24
|
+
inputEl.removeEventListener("change", updateValidity);
|
|
25
25
|
inputEl.removeEventListener("invalid", updateValidity);
|
|
26
26
|
};
|
|
27
27
|
}, [ref]);
|
|
@@ -4,7 +4,7 @@ import clsx from 'clsx';
|
|
|
4
4
|
|
|
5
5
|
function IDSRadioGroupBase({ legend, errorMsg, errorMsgId, compact = false, required = false, tooltip, className, children, invalid, groupRef, ...props }) {
|
|
6
6
|
const showErrorMsg = invalid && !!errorMsg && !!errorMsgId;
|
|
7
|
-
return (jsxs("fieldset", { ref: groupRef, "aria-required": required, className: clsx("ids-form-group__fieldset", { "ids-form-group__fieldset--compact": compact }, className), ...props, children: [legend && (jsx("div", { className: "ids-label-wrapper", children: jsxs("legend", { children: [legend, tooltip && jsx("span", { className: "ids-legend__tooltip", children: tooltip })] }) })), children, showErrorMsg && (jsx(IDSErrorMessage, { id: errorMsgId, show: true, children: errorMsg }))] }));
|
|
7
|
+
return (jsxs("fieldset", { ref: groupRef, "aria-required": required, className: clsx("ids-form-group__fieldset", { "ids-form-group__fieldset--compact": compact }, className), ...props, children: [legend && (jsx("div", { className: "ids-label-wrapper", children: jsxs("legend", { children: [legend, tooltip && jsx("span", { className: "ids-legend__tooltip", children: tooltip })] }) })), children, showErrorMsg && (jsx(IDSErrorMessage, { id: errorMsgId, show: true, style: { marginTop: compact ? "0.75rem" : "auto" }, children: errorMsg }))] }));
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export { IDSRadioGroupBase };
|
|
@@ -10,9 +10,12 @@ function IDSSelectMultiple({ invalid = false, noValidation = false, expanded = f
|
|
|
10
10
|
const inputRef = useRef(null);
|
|
11
11
|
const componentRef = useRef(null);
|
|
12
12
|
useEffect(() => {
|
|
13
|
-
if (checkboxListInvalid)
|
|
13
|
+
if (checkboxListInvalid && !noValidation)
|
|
14
14
|
setIsExpanded(true);
|
|
15
|
-
}, [checkboxListInvalid]);
|
|
15
|
+
}, [checkboxListInvalid, noValidation]);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
setIsExpanded(expanded);
|
|
18
|
+
}, [expanded]);
|
|
16
19
|
useEffect(() => {
|
|
17
20
|
const handleClickOutside = (event) => {
|
|
18
21
|
if (componentRef.current && !componentRef.current.contains(event.target)) {
|
|
@@ -35,7 +38,7 @@ function IDSSelectMultiple({ invalid = false, noValidation = false, expanded = f
|
|
|
35
38
|
return (jsx(IDSSelectMultipleBase, { ...props, style: style, client: true, componentRef: componentRef, inputRef: inputRef, invalid: invalid || (!noValidation && checkboxListInvalid), expanded: isExpanded, ariaDisabled: ariaDisabled, onClick: () => {
|
|
36
39
|
setIsExpanded(!isExpanded);
|
|
37
40
|
}, children: jsx(IDSCheckboxGroup, { block: true, noValidation: noValidation, errorMsg: errorMsg, onValidityChange: (isValid) => {
|
|
38
|
-
if (!isValid) {
|
|
41
|
+
if (!isValid && !noValidation) {
|
|
39
42
|
setIsExpanded(true);
|
|
40
43
|
setCheckboxListInvalid(!isValid);
|
|
41
44
|
}
|
|
@@ -7,7 +7,7 @@ const IDSToggle = forwardRef(({ id, dataTestId, disabled, tooltip, focusAnchor,
|
|
|
7
7
|
const inputId = !!id ? id : useId();
|
|
8
8
|
return (jsxs("div", { className: clsx("ids-toggle", className), "data-testid": dataTestId, children: [jsx("input", { ref: ref, id: inputId, className: clsx("ids-toggle__input", {
|
|
9
9
|
"ids-focus-anchor": focusAnchor
|
|
10
|
-
}), type: "checkbox", role: "switch",
|
|
10
|
+
}), type: "checkbox", role: "switch", disabled: disabled, ...props }), jsxs("div", { className: "ids-label-wrapper", children: [jsx("label", { htmlFor: inputId, className: "ids-toggle__label ids-label ids-label--clickable", children: children }), tooltip && jsx("span", { className: "ids-label__tooltip", children: tooltip })] })] }));
|
|
11
11
|
});
|
|
12
12
|
IDSToggle.displayName = "IDSToggle";
|
|
13
13
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { useState } from 'react';
|
|
3
|
+
import { useState, useEffect } from 'react';
|
|
4
4
|
import { IDSSideMenuBase } from './side-menu-base.js';
|
|
5
5
|
|
|
6
6
|
function IDSSideMenu({ expanded = false, onToggleMenu, srToggleText = "Sektion", className, ...props }) {
|
|
@@ -11,6 +11,9 @@ function IDSSideMenu({ expanded = false, onToggleMenu, srToggleText = "Sektion",
|
|
|
11
11
|
setIsExpanded(newExpanded);
|
|
12
12
|
onToggleMenu?.(newExpanded);
|
|
13
13
|
};
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
setIsExpanded(expanded);
|
|
16
|
+
}, [expanded]);
|
|
14
17
|
const handleKeyDown = (e) => {
|
|
15
18
|
if (e.code !== "Escape")
|
|
16
19
|
e.stopPropagation();
|
package/package.json
CHANGED