@inera/ids-react 9.0.2 → 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.
@@ -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)
@@ -3,6 +3,7 @@ export interface IDSCheckboxBaseProps extends InputHTMLAttributes<HTMLInputEleme
3
3
  invalid?: boolean;
4
4
  disabled?: boolean;
5
5
  required?: boolean;
6
+ indeterminate?: boolean;
6
7
  light?: boolean;
7
8
  block?: boolean;
8
9
  compact?: boolean;
@@ -15,4 +16,4 @@ export interface IDSCheckboxBaseProps extends InputHTMLAttributes<HTMLInputEleme
15
16
  errorMsgId?: string;
16
17
  inputRef?: React.Ref<HTMLInputElement>;
17
18
  }
18
- 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 ariaHandler = showErrorMsg || !!groupErrorMsgId
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, ...ariaHandler, ...props }), !!children && (jsxs("div", { className: clsx("ids-label-wrapper", {
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,7 +15,7 @@ const IDSCheckbox = forwardRef(({ invalid = false, noValidation = false, indeter
15
15
  checkboxRef.current.indeterminate = indeterminate;
16
16
  }
17
17
  }, [indeterminate]);
18
- return (jsx(IDSCheckboxBase, { ...props, inputRef: checkboxRef, invalid: isInvalid, children: children }));
18
+ return (jsx(IDSCheckboxBase, { ...props, inputRef: checkboxRef, invalid: isInvalid, indeterminate: indeterminate, children: children }));
19
19
  });
20
20
  IDSCheckbox.displayName = "IDSCheckbox";
21
21
 
@@ -14,14 +14,14 @@ function useInputValidity(ref, validateOnBlur) {
14
14
  if (validateOnBlur) {
15
15
  inputEl.addEventListener("blur", updateValidity);
16
16
  }
17
- inputEl.addEventListener("input", updateValidity);
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("input", updateValidity);
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 };
@@ -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.props.id,
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: !isValid && hasInteracted && !noValidation,
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, invalid: !isValid && hasInteracted || invalid, errorMsg: !noValidation && errorMsg, errorMsgId: errorMsgId, children: clonedChildren }));
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 hasValidValue = useInputValidity(radioRef);
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 }));
@@ -13,6 +13,9 @@ function IDSSelectMultiple({ invalid = false, noValidation = false, expanded = f
13
13
  if (checkboxListInvalid && !noValidation)
14
14
  setIsExpanded(true);
15
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)) {
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inera/ids-react",
3
- "version": "9.0.2",
3
+ "version": "9.0.4",
4
4
  "type": "module",
5
5
  "peerDependencies": {
6
6
  "react": "*",