@khanacademy/wonder-blocks-modal 2.2.1 → 2.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @khanacademy/wonder-blocks-modal
2
2
 
3
+ ## 2.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7eaf74bd: Added `closedFocusId` prop so users can specify the element to receive focus after the modal is closed
8
+
9
+ ## 2.2.3
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [246a921d]
14
+ - @khanacademy/wonder-blocks-core@4.3.0
15
+ - @khanacademy/wonder-blocks-breadcrumbs@1.0.29
16
+ - @khanacademy/wonder-blocks-icon@1.2.26
17
+ - @khanacademy/wonder-blocks-icon-button@3.4.5
18
+ - @khanacademy/wonder-blocks-layout@1.4.8
19
+ - @khanacademy/wonder-blocks-toolbar@2.1.30
20
+ - @khanacademy/wonder-blocks-typography@1.1.30
21
+
22
+ ## 2.2.2
23
+
24
+ ### Patch Changes
25
+
26
+ - @khanacademy/wonder-blocks-icon-button@3.4.4
27
+
3
28
  ## 2.2.1
4
29
 
5
30
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -6,6 +6,7 @@ import Spacing from '@khanacademy/wonder-blocks-spacing';
6
6
  import Color from '@khanacademy/wonder-blocks-color';
7
7
  import { HeadingMedium, LabelSmall } from '@khanacademy/wonder-blocks-typography';
8
8
  import * as ReactDOM from 'react-dom';
9
+ import { withActionScheduler } from '@khanacademy/wonder-blocks-timing';
9
10
  import _extends from '@babel/runtime/helpers/extends';
10
11
  import { icons } from '@khanacademy/wonder-blocks-icon';
11
12
  import IconButton from '@khanacademy/wonder-blocks-icon-button';
@@ -717,16 +718,45 @@ class ModalLauncher extends React.Component {
717
718
  });
718
719
  };
719
720
 
721
+ this._returnFocus = () => {
722
+ const {
723
+ closedFocusId,
724
+ schedule
725
+ } = this.props;
726
+ const lastElement = this.lastElementFocusedOutsideModal; // Focus on the specified element after closing the modal.
727
+
728
+ if (closedFocusId) {
729
+ const focusElement = ReactDOM.findDOMNode(document.getElementById(closedFocusId));
730
+
731
+ if (focusElement) {
732
+ // Wait for the modal to leave the DOM before trying
733
+ // to focus on the specified element.
734
+ schedule.animationFrame(() => {
735
+ focusElement.focus();
736
+ });
737
+ return;
738
+ }
739
+ }
740
+
741
+ if (lastElement != null) {
742
+ // Wait for the modal to leave the DOM before trying to
743
+ // return focus to the element that triggered the modal.
744
+ schedule.animationFrame(() => {
745
+ lastElement.focus();
746
+ });
747
+ }
748
+ };
749
+
720
750
  this.handleCloseModal = () => {
721
751
  this.setState({
722
752
  opened: false
723
753
  }, () => {
724
- this.props.onClose && this.props.onClose();
754
+ const {
755
+ onClose
756
+ } = this.props;
757
+ onClose && onClose();
725
758
 
726
- if (this.lastElementFocusedOutsideModal != null) {
727
- // return focus to the element that triggered the modal
728
- this.lastElementFocusedOutsideModal.focus();
729
- }
759
+ this._returnFocus();
730
760
  });
731
761
  };
732
762
  }
@@ -810,6 +840,7 @@ class ModalLauncher extends React.Component {
810
840
  }
811
841
  /** A component that, when mounted, calls `onClose` when Escape is pressed. */
812
842
 
843
+
813
844
  ModalLauncher.defaultProps = {
814
845
  backdropDismissEnabled: true
815
846
  };
@@ -860,6 +891,7 @@ const styles$1 = StyleSheet.create({
860
891
  zIndex: 1080
861
892
  }
862
893
  });
894
+ var modalLauncher = withActionScheduler(ModalLauncher);
863
895
 
864
896
  /**
865
897
  * The Modal content included after the header
@@ -1176,4 +1208,4 @@ function maybeGetPortalMountedModalHostElement(element) {
1176
1208
  return maybeGetNextAncestorModalLauncherPortal(element);
1177
1209
  }
1178
1210
 
1179
- export { ModalDialog, ModalFooter, ModalHeader, ModalLauncher, ModalPanel, OnePaneDialog, maybeGetPortalMountedModalHostElement };
1211
+ export { ModalDialog, ModalFooter, ModalHeader, modalLauncher as ModalLauncher, ModalPanel, OnePaneDialog, maybeGetPortalMountedModalHostElement };