@lumx/react 3.0.5-alpha.1 → 3.0.5

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/index.d.ts CHANGED
@@ -1802,6 +1802,8 @@ interface RadioButtonProps extends GenericProps, HasTheme {
1802
1802
  value?: string;
1803
1803
  /** On change callback. */
1804
1804
  onChange?(value?: string, name?: string, event?: SyntheticEvent): void;
1805
+ /** optional props for input */
1806
+ inputProps?: InputHTMLAttributes<HTMLInputElement>;
1805
1807
  }
1806
1808
  /**
1807
1809
  * RadioButton component.
package/index.js CHANGED
@@ -2673,6 +2673,14 @@ const useDisableBodyScroll = modalElement => {
2673
2673
  }, [modalElement]);
2674
2674
  };
2675
2675
 
2676
+ const userHasReducedMotion = () => {
2677
+ try {
2678
+ return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
2679
+ } catch (e) {
2680
+ return false;
2681
+ }
2682
+ };
2683
+
2676
2684
  /**
2677
2685
  * Returns true if the component is visible tracking the opacity transition.
2678
2686
  *
@@ -2684,29 +2692,25 @@ const useDisableBodyScroll = modalElement => {
2684
2692
  const useTransitionVisibility = (ref, isComponentVisible, onVisibilityChange) => {
2685
2693
  const [isVisible, setVisible] = useState(isComponentVisible);
2686
2694
  const previousVisibility = useRef(isVisible);
2695
+
2696
+ // On component visibility change.
2687
2697
  useEffect(() => {
2688
2698
  if (isComponentVisible) {
2689
2699
  setVisible(true);
2690
- } else if (!window.TransitionEvent) {
2691
- // Transition event is not available so visibility is set to false directly.
2692
- setVisible(false);
2693
- }
2694
- }, [isComponentVisible]);
2695
- useEffect(() => {
2696
- if (onVisibilityChange && previousVisibility.current !== isVisible) {
2697
- onVisibilityChange(isVisible);
2698
- previousVisibility.current = isVisible;
2700
+ return undefined;
2699
2701
  }
2700
- }, [isVisible, onVisibilityChange]);
2701
- useEffect(() => {
2702
2702
  const {
2703
2703
  current: element
2704
2704
  } = ref;
2705
- if (!element) {
2705
+
2706
+ // Transition event is not supported or the user prefers reduced motion.
2707
+ // => Skip `transitionend` event listening and set visibility to false directly.
2708
+ if (!element || !window.TransitionEvent || userHasReducedMotion()) {
2709
+ setVisible(false);
2706
2710
  return undefined;
2707
2711
  }
2708
2712
 
2709
- // Listen opacity transition
2713
+ // Update visibility on opacity transition end.
2710
2714
  const onTransitionEnd = e => {
2711
2715
  if (e.target !== ref.current || e.propertyName !== 'opacity') return;
2712
2716
  setVisible(wasVisible => !wasVisible);
@@ -2715,7 +2719,13 @@ const useTransitionVisibility = (ref, isComponentVisible, onVisibilityChange) =>
2715
2719
  return () => {
2716
2720
  element.removeEventListener('transitionend', onTransitionEnd);
2717
2721
  };
2718
- });
2722
+ }, [isComponentVisible, ref]);
2723
+ useEffect(() => {
2724
+ if (onVisibilityChange && previousVisibility.current !== isVisible) {
2725
+ onVisibilityChange(isVisible);
2726
+ previousVisibility.current = isVisible;
2727
+ }
2728
+ }, [isVisible, onVisibilityChange]);
2719
2729
  return isVisible || isComponentVisible;
2720
2730
  };
2721
2731
 
@@ -6405,7 +6415,8 @@ const ExpansionPanel = /*#__PURE__*/forwardRef((props, ref) => {
6405
6415
  }, /*#__PURE__*/React.createElement(IconButton, _extends({}, toggleButtonProps, {
6406
6416
  color: color,
6407
6417
  emphasis: Emphasis.low,
6408
- icon: isOpen ? mdiChevronUp : mdiChevronDown
6418
+ icon: isOpen ? mdiChevronUp : mdiChevronDown,
6419
+ "aria-expanded": isOpen || 'false'
6409
6420
  })))), (isOpen || isContentVisible()) && /*#__PURE__*/React.createElement("div", {
6410
6421
  className: `${CLASSNAME$k}__wrapper`,
6411
6422
  style: {
@@ -8610,7 +8621,7 @@ ProgressTrackerStepPanel.displayName = COMPONENT_NAME$M;
8610
8621
  ProgressTrackerStepPanel.className = CLASSNAME$J;
8611
8622
  ProgressTrackerStepPanel.defaultProps = DEFAULT_PROPS$B;
8612
8623
 
8613
- const _excluded$P = ["checked", "className", "disabled", "helper", "id", "inputRef", "isChecked", "isDisabled", "label", "name", "onChange", "theme", "value"];
8624
+ const _excluded$P = ["checked", "className", "disabled", "helper", "id", "inputRef", "isChecked", "isDisabled", "label", "name", "onChange", "theme", "value", "inputProps"];
8614
8625
 
8615
8626
  /**
8616
8627
  * Defines the props of the component.
@@ -8654,10 +8665,11 @@ const RadioButton = /*#__PURE__*/forwardRef((props, ref) => {
8654
8665
  name,
8655
8666
  onChange,
8656
8667
  theme,
8657
- value
8668
+ value,
8669
+ inputProps
8658
8670
  } = props,
8659
8671
  forwardedProps = _objectWithoutProperties(props, _excluded$P);
8660
- const radioButtonId = useMemo(() => id || `${CLASSNAME$K.toLowerCase()}-${uid()}`, [id]);
8672
+ const inputId = useMemo(() => id || `${CLASSNAME$K.toLowerCase()}-${uid()}`, [id]);
8661
8673
  const handleChange = event => {
8662
8674
  if (onChange) {
8663
8675
  onChange(value, name, event);
@@ -8675,18 +8687,19 @@ const RadioButton = /*#__PURE__*/forwardRef((props, ref) => {
8675
8687
  }))
8676
8688
  }), /*#__PURE__*/React.createElement("div", {
8677
8689
  className: `${CLASSNAME$K}__input-wrapper`
8678
- }, /*#__PURE__*/React.createElement("input", {
8690
+ }, /*#__PURE__*/React.createElement("input", _extends({
8679
8691
  ref: inputRef,
8680
8692
  className: `${CLASSNAME$K}__input-native`,
8681
8693
  disabled: isDisabled,
8682
- id: radioButtonId,
8694
+ id: inputId,
8683
8695
  tabIndex: isDisabled ? -1 : 0,
8684
8696
  type: "radio",
8685
8697
  name: name,
8686
8698
  value: value,
8687
8699
  checked: isChecked,
8688
- onChange: handleChange
8689
- }), /*#__PURE__*/React.createElement("div", {
8700
+ onChange: handleChange,
8701
+ "aria-describedby": helper ? `${inputId}-helper` : undefined
8702
+ }, inputProps)), /*#__PURE__*/React.createElement("div", {
8690
8703
  className: `${CLASSNAME$K}__input-placeholder`
8691
8704
  }, /*#__PURE__*/React.createElement("div", {
8692
8705
  className: `${CLASSNAME$K}__input-background`
@@ -8695,10 +8708,11 @@ const RadioButton = /*#__PURE__*/forwardRef((props, ref) => {
8695
8708
  }))), /*#__PURE__*/React.createElement("div", {
8696
8709
  className: `${CLASSNAME$K}__content`
8697
8710
  }, label && /*#__PURE__*/React.createElement(InputLabel, {
8698
- htmlFor: radioButtonId,
8711
+ htmlFor: inputId,
8699
8712
  theme: theme,
8700
8713
  className: `${CLASSNAME$K}__label`
8701
8714
  }, label), helper && /*#__PURE__*/React.createElement(InputHelper, {
8715
+ id: `${inputId}-helper`,
8702
8716
  theme: theme,
8703
8717
  className: `${CLASSNAME$K}__helper`
8704
8718
  }, helper)));
@@ -10575,7 +10589,7 @@ const Switch = /*#__PURE__*/forwardRef((props, ref) => {
10575
10589
  inputProps = {}
10576
10590
  } = props,
10577
10591
  forwardedProps = _objectWithoutProperties(props, _excluded$13);
10578
- const switchId = useMemo(() => id || `switch-${uid()}`, [id]);
10592
+ const inputId = useMemo(() => id || `switch-${uid()}`, [id]);
10579
10593
  const handleChange = event => {
10580
10594
  if (onChange) {
10581
10595
  onChange(!isChecked, value, name, event);
@@ -10598,14 +10612,15 @@ const Switch = /*#__PURE__*/forwardRef((props, ref) => {
10598
10612
  }, /*#__PURE__*/React.createElement("input", _extends({
10599
10613
  type: "checkbox",
10600
10614
  role: "switch",
10601
- id: switchId,
10615
+ id: inputId,
10602
10616
  className: `${CLASSNAME$Z}__input-native`,
10603
10617
  name: name,
10604
10618
  value: value,
10605
10619
  disabled: isDisabled,
10606
10620
  checked: isChecked,
10607
10621
  "aria-checked": Boolean(isChecked),
10608
- onChange: handleChange
10622
+ onChange: handleChange,
10623
+ "aria-describedby": helper ? `${inputId}-helper` : undefined
10609
10624
  }, inputProps)), /*#__PURE__*/React.createElement("div", {
10610
10625
  className: `${CLASSNAME$Z}__input-placeholder`
10611
10626
  }, /*#__PURE__*/React.createElement("div", {
@@ -10615,10 +10630,11 @@ const Switch = /*#__PURE__*/forwardRef((props, ref) => {
10615
10630
  }))), Children.count(children) > 0 && /*#__PURE__*/React.createElement("div", {
10616
10631
  className: `${CLASSNAME$Z}__content`
10617
10632
  }, /*#__PURE__*/React.createElement(InputLabel, {
10618
- htmlFor: switchId,
10633
+ htmlFor: inputId,
10619
10634
  theme: theme,
10620
10635
  className: `${CLASSNAME$Z}__label`
10621
10636
  }, children), !isEmpty(helper) && /*#__PURE__*/React.createElement(InputHelper, {
10637
+ id: `${inputId}-helper`,
10622
10638
  theme: theme,
10623
10639
  className: `${CLASSNAME$Z}__helper`
10624
10640
  }, helper)));