grommet 2.34.0 → 2.34.1

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.
@@ -614,48 +614,58 @@ var Form = exports.Form = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, r
614
614
  // if the validation fails. And, we assume a javascript action handler
615
615
  // otherwise.
616
616
  event.preventDefault();
617
- setPendingValidation(undefined);
618
- // adding validateOn: "submit" prop to the undefined validateOn fields
619
- // as we want to trigger "submit" validation once form is submitted
620
- var newValidationRulesRef = Object.keys(validationRulesRef.current).reduce(function (acc, key) {
621
- acc[key] = validationRulesRef.current[key];
622
- if (!acc[key].validateOn) {
623
- acc[key] = _extends({}, validationRulesRef.current[key], {
624
- validateOn: 'submit'
617
+ // Prevent any "outer" forms from performing `onSubmit`.
618
+ // Nesting forms is not recommended in HTML. However, with React
619
+ // portals, if the portal (such as Grommet's Layer) contains a form
620
+ // and is nested within another form in the React tree, the event
621
+ // bubbles up to the "outer" form even though in the DOM the portal
622
+ // doesn't render as child of the "outer" form.
623
+ // https://legacy.reactjs.org/docs/portals.html#event-bubbling-through-portals
624
+ if (formRef.current && event.target === formRef.current) {
625
+ setPendingValidation(undefined);
626
+ // adding validateOn: "submit" prop to the undefined validateOn
627
+ // fields as we want to trigger "submit" validation once form
628
+ // is submitted
629
+ var newValidationRulesRef = Object.keys(validationRulesRef.current).reduce(function (acc, key) {
630
+ acc[key] = validationRulesRef.current[key];
631
+ if (!acc[key].validateOn) {
632
+ acc[key] = _extends({}, validationRulesRef.current[key], {
633
+ validateOn: 'submit'
634
+ });
635
+ }
636
+ return acc;
637
+ }, {});
638
+ var _validateForm2 = validateForm(Object.entries(newValidationRulesRef), value, format, messages, true),
639
+ nextErrors = _validateForm2[0],
640
+ nextInfos = _validateForm2[1];
641
+ setValidationResults(function () {
642
+ var nextValidationResults = {
643
+ errors: nextErrors,
644
+ infos: nextInfos,
645
+ // Show form's validity when clicking on Submit
646
+ valid: buildValid(nextErrors)
647
+ };
648
+ if (onValidate) onValidate(nextValidationResults);
649
+ validationResultsRef.current = nextValidationResults;
650
+ updateAnalytics();
651
+ return nextValidationResults;
652
+ });
653
+ if (Object.keys(nextErrors).length === 0 && _onSubmit) {
654
+ event.persist(); // extract from React's synthetic event pool
655
+ var adjustedEvent = event;
656
+ adjustedEvent.value = value;
657
+ adjustedEvent.touched = touched;
658
+ _onSubmit(adjustedEvent);
659
+ sendAnalytics({
660
+ type: 'formSubmit',
661
+ element: formRef.current,
662
+ data: adjustedEvent,
663
+ errors: analyticsRef.current.errors,
664
+ elapsed: new Date().getTime() - analyticsRef.current.start.getTime()
625
665
  });
666
+ analyticsRef.current.errors = {};
667
+ analyticsRef.current.submitted = true;
626
668
  }
627
- return acc;
628
- }, {});
629
- var _validateForm2 = validateForm(Object.entries(newValidationRulesRef), value, format, messages, true),
630
- nextErrors = _validateForm2[0],
631
- nextInfos = _validateForm2[1];
632
- setValidationResults(function () {
633
- var nextValidationResults = {
634
- errors: nextErrors,
635
- infos: nextInfos,
636
- // Show form's validity when clicking on Submit
637
- valid: buildValid(nextErrors)
638
- };
639
- if (onValidate) onValidate(nextValidationResults);
640
- validationResultsRef.current = nextValidationResults;
641
- updateAnalytics();
642
- return nextValidationResults;
643
- });
644
- if (Object.keys(nextErrors).length === 0 && _onSubmit) {
645
- event.persist(); // extract from React's synthetic event pool
646
- var adjustedEvent = event;
647
- adjustedEvent.value = value;
648
- adjustedEvent.touched = touched;
649
- _onSubmit(adjustedEvent);
650
- sendAnalytics({
651
- type: 'formSubmit',
652
- element: formRef.current,
653
- data: adjustedEvent,
654
- errors: analyticsRef.current.errors,
655
- elapsed: new Date().getTime() - analyticsRef.current.start.getTime()
656
- });
657
- analyticsRef.current.errors = {};
658
- analyticsRef.current.submitted = true;
659
669
  }
660
670
  }
661
671
  }), /*#__PURE__*/_react["default"].createElement(_FormContext.FormContext.Provider, {
@@ -67,13 +67,6 @@ var RadioButtonGroup = exports.RadioButtonGroup = /*#__PURE__*/(0, _react.forwar
67
67
  });
68
68
  return result;
69
69
  }, [options, value]);
70
- (0, _react.useEffect)(function () {
71
- // if tab comes back to RadioButtonGroup when there still is no selection,
72
- // we want focus to be on the first RadioButton
73
- if (focus && !valueIndex) {
74
- optionRefs.current[0].focus();
75
- }
76
- }, [focus, valueIndex]);
77
70
  var onNext = function onNext() {
78
71
  if (valueIndex !== undefined && valueIndex < options.length - 1) {
79
72
  var nextIndex = valueIndex + 1;
@@ -608,48 +608,58 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
608
608
  // if the validation fails. And, we assume a javascript action handler
609
609
  // otherwise.
610
610
  event.preventDefault();
611
- setPendingValidation(undefined);
612
- // adding validateOn: "submit" prop to the undefined validateOn fields
613
- // as we want to trigger "submit" validation once form is submitted
614
- var newValidationRulesRef = Object.keys(validationRulesRef.current).reduce(function (acc, key) {
615
- acc[key] = validationRulesRef.current[key];
616
- if (!acc[key].validateOn) {
617
- acc[key] = _extends({}, validationRulesRef.current[key], {
618
- validateOn: 'submit'
611
+ // Prevent any "outer" forms from performing `onSubmit`.
612
+ // Nesting forms is not recommended in HTML. However, with React
613
+ // portals, if the portal (such as Grommet's Layer) contains a form
614
+ // and is nested within another form in the React tree, the event
615
+ // bubbles up to the "outer" form even though in the DOM the portal
616
+ // doesn't render as child of the "outer" form.
617
+ // https://legacy.reactjs.org/docs/portals.html#event-bubbling-through-portals
618
+ if (formRef.current && event.target === formRef.current) {
619
+ setPendingValidation(undefined);
620
+ // adding validateOn: "submit" prop to the undefined validateOn
621
+ // fields as we want to trigger "submit" validation once form
622
+ // is submitted
623
+ var newValidationRulesRef = Object.keys(validationRulesRef.current).reduce(function (acc, key) {
624
+ acc[key] = validationRulesRef.current[key];
625
+ if (!acc[key].validateOn) {
626
+ acc[key] = _extends({}, validationRulesRef.current[key], {
627
+ validateOn: 'submit'
628
+ });
629
+ }
630
+ return acc;
631
+ }, {});
632
+ var _validateForm2 = validateForm(Object.entries(newValidationRulesRef), value, format, messages, true),
633
+ nextErrors = _validateForm2[0],
634
+ nextInfos = _validateForm2[1];
635
+ setValidationResults(function () {
636
+ var nextValidationResults = {
637
+ errors: nextErrors,
638
+ infos: nextInfos,
639
+ // Show form's validity when clicking on Submit
640
+ valid: buildValid(nextErrors)
641
+ };
642
+ if (onValidate) onValidate(nextValidationResults);
643
+ validationResultsRef.current = nextValidationResults;
644
+ updateAnalytics();
645
+ return nextValidationResults;
646
+ });
647
+ if (Object.keys(nextErrors).length === 0 && _onSubmit) {
648
+ event.persist(); // extract from React's synthetic event pool
649
+ var adjustedEvent = event;
650
+ adjustedEvent.value = value;
651
+ adjustedEvent.touched = touched;
652
+ _onSubmit(adjustedEvent);
653
+ sendAnalytics({
654
+ type: 'formSubmit',
655
+ element: formRef.current,
656
+ data: adjustedEvent,
657
+ errors: analyticsRef.current.errors,
658
+ elapsed: new Date().getTime() - analyticsRef.current.start.getTime()
619
659
  });
660
+ analyticsRef.current.errors = {};
661
+ analyticsRef.current.submitted = true;
620
662
  }
621
- return acc;
622
- }, {});
623
- var _validateForm2 = validateForm(Object.entries(newValidationRulesRef), value, format, messages, true),
624
- nextErrors = _validateForm2[0],
625
- nextInfos = _validateForm2[1];
626
- setValidationResults(function () {
627
- var nextValidationResults = {
628
- errors: nextErrors,
629
- infos: nextInfos,
630
- // Show form's validity when clicking on Submit
631
- valid: buildValid(nextErrors)
632
- };
633
- if (onValidate) onValidate(nextValidationResults);
634
- validationResultsRef.current = nextValidationResults;
635
- updateAnalytics();
636
- return nextValidationResults;
637
- });
638
- if (Object.keys(nextErrors).length === 0 && _onSubmit) {
639
- event.persist(); // extract from React's synthetic event pool
640
- var adjustedEvent = event;
641
- adjustedEvent.value = value;
642
- adjustedEvent.touched = touched;
643
- _onSubmit(adjustedEvent);
644
- sendAnalytics({
645
- type: 'formSubmit',
646
- element: formRef.current,
647
- data: adjustedEvent,
648
- errors: analyticsRef.current.errors,
649
- elapsed: new Date().getTime() - analyticsRef.current.start.getTime()
650
- });
651
- analyticsRef.current.errors = {};
652
- analyticsRef.current.submitted = true;
653
663
  }
654
664
  }
655
665
  }), /*#__PURE__*/React.createElement(FormContext.Provider, {
@@ -2,7 +2,7 @@ var _excluded = ["children", "defaultValue", "disabled", "focusIndicator", "name
2
2
  _excluded2 = ["disabled", "id", "label", "value"];
3
3
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
4
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
5
- import React, { forwardRef, useContext, useEffect, useRef, useState } from 'react';
5
+ import React, { forwardRef, useContext, useRef, useState } from 'react';
6
6
  import { ThemeContext } from 'styled-components';
7
7
  import { FormContext } from '../Form/FormContext';
8
8
  import { defaultProps } from '../../default-props';
@@ -61,13 +61,6 @@ var RadioButtonGroup = /*#__PURE__*/forwardRef(function (_ref, ref) {
61
61
  });
62
62
  return result;
63
63
  }, [options, value]);
64
- useEffect(function () {
65
- // if tab comes back to RadioButtonGroup when there still is no selection,
66
- // we want focus to be on the first RadioButton
67
- if (focus && !valueIndex) {
68
- optionRefs.current[0].focus();
69
- }
70
- }, [focus, valueIndex]);
71
64
  var onNext = function onNext() {
72
65
  if (valueIndex !== undefined && valueIndex < options.length - 1) {
73
66
  var nextIndex = valueIndex + 1;