@skyscanner/backpack-web 34.0.0-premajor → 34.0.0-premajor.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.
@@ -14,7 +14,7 @@
14
14
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
- */import BpkPopoverPortal, { propTypes as bpkPopoverPortalPropTypes, defaultProps as bpkPopoverPortalDefaultProps } from "./src/BpkPopoverPortal";
17
+ */import BpkPopover from "./src/BpkPopover";
18
18
  import themeAttributes from "./src/themeAttributes";
19
- export { themeAttributes, bpkPopoverPortalPropTypes, bpkPopoverPortalDefaultProps };
20
- export default BpkPopoverPortal;
19
+ export { themeAttributes };
20
+ export default BpkPopover;
@@ -14,10 +14,17 @@
14
14
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
- */import PropTypes from 'prop-types';
18
- import { useState, cloneElement } from 'react';
19
- import { useFloating, autoUpdate, offset, flip, shift, useClick, useDismiss, useInteractions, FloatingFocusManager } from '@floating-ui/react';
17
+ */
18
+
19
+ import { useState, cloneElement, useRef } from 'react';
20
+ import { useFloating, autoUpdate, offset, flip, useClick, useDismiss, useInteractions, FloatingFocusManager, FloatingArrow, arrow } from '@floating-ui/react';
21
+
22
+ // @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
23
+ import { surfaceHighlightDay } from '@skyscanner/bpk-foundations-web/tokens/base.es6';
24
+
25
+ // @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
20
26
  import BpkCloseButton from "../../bpk-component-close-button";
27
+ // @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
21
28
  import { BpkButtonLink } from "../../bpk-component-link";
22
29
  import BpkText, { TEXT_STYLES } from "../../bpk-component-text";
23
30
  import { TransitionInitialMount, cssModules } from "../../bpk-react-utils";
@@ -37,27 +44,25 @@ const bindEventSource = (source, callback) => event => {
37
44
  source
38
45
  });
39
46
  };
40
- const BpkPopover = props => {
41
- const {
42
- children,
43
- className,
44
- closeButtonIcon,
45
- closeButtonProps,
46
- closeButtonText,
47
- id,
48
- isOpen,
49
- label,
50
- labelAsTitle,
51
- onClose,
52
- padded,
53
- placement,
54
- popperModifiers,
55
- portalStyle,
56
- renderTarget,
57
- target,
58
- ...rest
59
- } = props;
47
+ const BpkPopover = ({
48
+ children,
49
+ className = null,
50
+ closeButtonIcon = true,
51
+ closeButtonProps = {},
52
+ closeButtonText,
53
+ id,
54
+ isOpen = false,
55
+ label,
56
+ labelAsTitle = false,
57
+ onClose,
58
+ padded = true,
59
+ placement = 'bottom',
60
+ showArrow = true,
61
+ target,
62
+ ...rest
63
+ }) => {
60
64
  const [isOpenState, setIsOpenState] = useState(isOpen);
65
+ const arrowRef = useRef(null);
61
66
  const {
62
67
  context,
63
68
  floatingStyles,
@@ -65,7 +70,12 @@ const BpkPopover = props => {
65
70
  } = useFloating({
66
71
  open: isOpenState,
67
72
  onOpenChange: setIsOpenState,
68
- middleware: [offset(17), popperModifiers],
73
+ placement,
74
+ middleware: [showArrow && offset(14), flip({
75
+ fallbackAxisSideDirection: 'start'
76
+ }), arrow({
77
+ element: arrowRef
78
+ })],
69
79
  whileElementsMounted: autoUpdate
70
80
  });
71
81
  const click = useClick(context);
@@ -76,12 +86,7 @@ const BpkPopover = props => {
76
86
  getFloatingProps,
77
87
  getReferenceProps
78
88
  } = useInteractions([click, dismiss]);
79
-
80
- // const getTargetElement = () => typeof target === 'function' ? target() : (target as JSXElementWithRefProps)?.ref.current
81
-
82
- // const targetEl = cloneElement(getRenderTarget(renderTarget), { ...getReferenceProps(), ref: refs.setReference });
83
- // console.error('renderTarget', renderTarget());
84
- const targetEl = /*#__PURE__*/cloneElement(target, {
89
+ const targetElement = /*#__PURE__*/cloneElement(target, {
85
90
  ...getReferenceProps(),
86
91
  ref: refs.setReference
87
92
  });
@@ -89,7 +94,7 @@ const BpkPopover = props => {
89
94
  const bodyClassNames = getClassName(padded && 'bpk-popover__body--padded');
90
95
  const labelId = `bpk-popover-label-${id}`;
91
96
  return /*#__PURE__*/_jsxs(_Fragment, {
92
- children: [targetEl, isOpenState && /*#__PURE__*/_jsx(FloatingFocusManager, {
97
+ children: [targetElement, isOpenState && /*#__PURE__*/_jsx(FloatingFocusManager, {
93
98
  context: context,
94
99
  modal: false,
95
100
  children: /*#__PURE__*/_jsx("div", {
@@ -102,32 +107,38 @@ const BpkPopover = props => {
102
107
  transitionTimeout: 200,
103
108
  children: /*#__PURE__*/_jsxs("section", {
104
109
  id: id,
105
- tabIndex: "-1",
110
+ tabIndex: -1,
106
111
  role: "dialog",
107
112
  "aria-labelledby": labelId,
108
113
  className: classNames,
109
114
  ...rest,
110
- children: [labelAsTitle ? /*#__PURE__*/_jsxs("header", {
115
+ children: [showArrow && /*#__PURE__*/_jsx(FloatingArrow, {
116
+ ref: arrowRef,
117
+ context: context,
118
+ id: ARROW_ID
119
+ // eslint-disable-next-line @skyscanner/rules/forbid-component-props
120
+ ,
121
+ className: getClassName('bpk-popover__arrow'),
122
+ role: "presentation",
123
+ stroke: surfaceHighlightDay,
124
+ strokeWidth: 0.0625
125
+ }), labelAsTitle ? /*#__PURE__*/_jsxs("header", {
111
126
  className: getClassName('bpk-popover__header'),
112
127
  children: [/*#__PURE__*/_jsx(BpkText, {
113
128
  tagName: "h2",
114
129
  id: labelId,
115
130
  textStyle: TEXT_STYLES.label1,
116
131
  children: label
117
- }), "\xA0", closeButtonIcon ? /*#__PURE__*/_jsx(BpkCloseButton
118
- // TODO: className to be removed
119
- // eslint-disable-next-line @skyscanner/rules/forbid-component-props
120
- , {
121
- className: getClassName('bpk-popover__close-button'),
132
+ }), "\xA0", closeButtonIcon ? /*#__PURE__*/_jsx(BpkCloseButton, {
122
133
  label: closeButtonText,
123
134
  onClick: () => {
124
- bindEventSource(EVENT_SOURCES.CLOSE_BUTTON, props.onClose);
135
+ bindEventSource(EVENT_SOURCES.CLOSE_BUTTON, onClose);
125
136
  setIsOpenState(false);
126
137
  },
127
138
  ...closeButtonProps
128
139
  }) : /*#__PURE__*/_jsx(BpkButtonLink, {
129
140
  onClick: () => {
130
- bindEventSource(EVENT_SOURCES.CLOSE_LINK, props.onClose);
141
+ bindEventSource(EVENT_SOURCES.CLOSE_LINK, onClose);
131
142
  setIsOpenState(false);
132
143
  },
133
144
  ...closeButtonProps,
@@ -144,7 +155,7 @@ const BpkPopover = props => {
144
155
  className: getClassName('bpk-popover__footer'),
145
156
  children: /*#__PURE__*/_jsx(BpkButtonLink, {
146
157
  onClick: () => {
147
- bindEventSource(EVENT_SOURCES.CLOSE_LINK, props.onClose);
158
+ bindEventSource(EVENT_SOURCES.CLOSE_LINK, onClose);
148
159
  setIsOpenState(false);
149
160
  },
150
161
  ...closeButtonProps,
@@ -157,29 +168,4 @@ const BpkPopover = props => {
157
168
  })]
158
169
  });
159
170
  };
160
- export const propTypes = {
161
- children: PropTypes.node.isRequired,
162
- closeButtonText: PropTypes.string.isRequired,
163
- id: PropTypes.string.isRequired,
164
- label: PropTypes.string.isRequired,
165
- onClose: PropTypes.func.isRequired,
166
- className: PropTypes.string,
167
- closeButtonIcon: PropTypes.bool,
168
- closeButtonProps: PropTypes.object,
169
- labelAsTitle: PropTypes.bool,
170
- padded: PropTypes.bool
171
- };
172
- export const defaultProps = {
173
- className: null,
174
- closeButtonIcon: true,
175
- closeButtonProps: null,
176
- labelAsTitle: false,
177
- padded: true
178
- };
179
- BpkPopover.propTypes = {
180
- ...propTypes
181
- };
182
- BpkPopover.defaultProps = {
183
- ...defaultProps
184
- };
185
171
  export default BpkPopover;
@@ -15,4 +15,4 @@
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */
18
- .bpk-popover-portal{z-index:900}@media(max-width: 32rem){.bpk-popover-portal{margin-right:1rem;margin-left:1rem}}.bpk-popover{transition:opacity 200ms ease-in-out;outline:0;opacity:1;border:.0625rem solid #e0e4e9;background-color:#fff;border-radius:.5rem;box-shadow:0px 4px 14px 0px rgba(37,32,31,.25)}@media(min-width: 32.0625rem){.bpk-popover{max-width:32rem;transition:opacity 50ms ease-in-out}}.bpk-popover--appear{opacity:0}.bpk-popover--appear-active{opacity:1}.bpk-popover__arrow{position:absolute;width:1.5rem;height:1.5rem;transform:rotate(45deg);border:.0625rem solid rgba(0,0,0,0);background:inherit}.bpk-popover-portal[data-popper-placement=top] .bpk-popover__arrow{bottom:-0.6875rem;border-right-color:#e0e4e9;border-bottom-color:#e0e4e9}.bpk-popover-portal[data-popper-placement=right] .bpk-popover__arrow{left:-0.6875rem;border-bottom-color:#e0e4e9;border-left-color:#e0e4e9}.bpk-popover-portal[data-popper-placement=bottom] .bpk-popover__arrow{top:-0.6875rem;border-top-color:#e0e4e9;border-left-color:#e0e4e9}.bpk-popover-portal[data-popper-placement=left] .bpk-popover__arrow{right:-0.6875rem;border-top-color:#e0e4e9;border-right-color:#e0e4e9}.bpk-popover__arrow[data-hide]{visibility:hidden}.bpk-popover__body--padded{padding:1rem}.bpk-popover__header{display:flex;padding:1rem;justify-content:space-between;box-shadow:0 -1px 0 0 #e0e4e9 inset}.bpk-popover__label{position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0 0 0 0)}.bpk-popover__close-button{float:right}html[dir=rtl] .bpk-popover__close-button{float:left}.bpk-popover__footer{padding:.5rem 1rem;text-align:right;box-shadow:0 1px 0 0 #e0e4e9 inset}html[dir=rtl] .bpk-popover__footer{text-align:left}
18
+ .bpk-popover-portal{z-index:900}@media(max-width: 32rem){.bpk-popover-portal{margin-right:1rem;margin-left:1rem}}.bpk-popover{transition:opacity 200ms ease-in-out;outline:0;opacity:1;border:.0625rem solid #e0e4e9;background-color:#fff;border-radius:.5rem;box-shadow:0px 4px 14px 0px rgba(37,32,31,.25)}@media(min-width: 32.0625rem){.bpk-popover{max-width:32rem;transition:opacity 50ms ease-in-out}}.bpk-popover--appear{opacity:0}.bpk-popover--appear-active{opacity:1}.bpk-popover__arrow{width:1.5rem;height:1.5rem;fill:#fff}.bpk-popover__arrow[data-hide]{visibility:hidden}.bpk-popover__body--padded{padding:1rem}.bpk-popover__header{display:flex;padding:1rem;justify-content:space-between;box-shadow:0 -1px 0 0 #e0e4e9 inset}.bpk-popover__label{position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0 0 0 0)}.bpk-popover__footer{padding:.5rem 1rem;text-align:right;box-shadow:0 1px 0 0 #e0e4e9 inset}html[dir=rtl] .bpk-popover__footer{text-align:left}
@@ -14,5 +14,8 @@
14
14
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
- */import { themeAttributes as linkAttributes } from "../../bpk-component-link";
17
+ */
18
+
19
+ // @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
20
+ import { themeAttributes as linkAttributes } from "../../bpk-component-link";
18
21
  export default [...linkAttributes];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "34.0.0-premajor",
3
+ "version": "34.0.0-premajor.1",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,7 +22,6 @@
22
22
  "access": "public"
23
23
  },
24
24
  "dependencies": {
25
- "@floating-ui/dom": "^1.6.3",
26
25
  "@floating-ui/react": "^0.26.12",
27
26
  "@popperjs/core": "^2.11.8",
28
27
  "@react-google-maps/api": "^2.12.0",
@@ -1,222 +0,0 @@
1
- /*
2
- * Backpack - Skyscanner's Design System
3
- *
4
- * Copyright 2016 Skyscanner Ltd
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */import PropTypes from 'prop-types';
18
- import { Component } from 'react';
19
- import { createPopper } from '@popperjs/core';
20
- import focusStore from 'a11y-focus-store';
21
- import { Portal, cssModules } from "../../bpk-react-utils";
22
- import BpkPopover from "./BpkPopover";
23
- import keyboardFocusScope from "./keyboardFocusScope";
24
- import STYLES from "./BpkPopover.module.css";
25
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
26
- const getClassName = cssModules(STYLES);
27
- class BpkPopoverPortal extends Component {
28
- constructor() {
29
- super();
30
- this.popper = null;
31
- this.previousTargetElement = null;
32
- }
33
-
34
- // onRender = (popoverElement: HTMLElement, targetElement: ?HTMLElement) => {
35
- // this.position(popoverElement, targetElement);
36
- // };
37
-
38
- // The order of events here is as follows:
39
- // - `onClose` is called by `Portal`
40
- // - The consumer changes `isOpen` to `false`
41
- // - `beforeClose` is called by `Portal`
42
- // - `beforeClose` calls the `done` callback which closes the `Portal`
43
-
44
- // `onClose` is called by the `Portal` to inform the consumer that `isOpen` should be made false.
45
- // Before we pass this information to the consumer, we want to note if restoring focus should be suppressed
46
- // onClose = (event: Object, information: { source: string }) => {
47
- // // If the user has clicked outside the popover then we don't want focus to be restored
48
- // // otherwise it will be stolen back from the element they clicked on.
49
- // // Here we suppress restoring focus before the consumer is told about the close and updates state.
50
- // this.suppressRestoreFocus = information.source === 'DOCUMENT_CLICK';
51
-
52
- // if (this.props.onClose) {
53
- // this.props.onClose(event, information);
54
- // }
55
- // };
56
-
57
- // `beforeClose` is called by the `Portal` when `isOpen` is changed to false.
58
- // As a result, `onClose` is called first, followed by `beforeClose`.
59
- // beforeClose = (done: () => void) => {
60
- // if (this.popper) {
61
- // this.popper.destroy();
62
- // this.popper = null;
63
- // this.previousTargetElement = null;
64
- // }
65
-
66
- // keyboardFocusScope.unscopeFocus();
67
- // if (!this.suppressRestoreFocus) {
68
- // focusStore.restoreFocus();
69
- // this.suppressRestoreFocus = false;
70
- // }
71
-
72
- // done();
73
- // };
74
-
75
- // position(popoverElement: HTMLElement, targetElement: ?HTMLElement) {
76
- // if (!targetElement) {
77
- // return;
78
- // }
79
-
80
- // const targetElementHasChanged =
81
- // targetElement !== this.previousTargetElement;
82
-
83
- // if (targetElementHasChanged && this.popper) {
84
- // this.popper.destroy();
85
- // this.popper = null;
86
- // }
87
-
88
- // // Custom modifier that makes the arrow display at the edge of the target.
89
- // const applyArrowHide = {
90
- // name: 'applyArrowHide',
91
- // enabled: true,
92
- // phase: 'write',
93
- // fn({ state }) {
94
- // const { arrow } = state.elements;
95
- // if (arrow) {
96
- // if (state.modifiersData.arrow.centerOffset !== 0) {
97
- // arrow.setAttribute('data-hide', '');
98
- // } else {
99
- // arrow.removeAttribute('data-hide');
100
- // }
101
- // }
102
- // },
103
- // };
104
-
105
- // // The default modifiers for the popper
106
- // // Note that GPU acceleration should be disabled otherwise Popper will use `translate3d`
107
- // // which can cause blurriness in Safari and Chrome.
108
- // const stdModifiers = [
109
- // {
110
- // name: 'computeStyles',
111
- // options: {
112
- // gpuAcceleration: false,
113
- // },
114
- // },
115
- // {
116
- // name: 'offset',
117
- // options: {
118
- // offset: [0, 17],
119
- // },
120
- // },
121
- // applyArrowHide,
122
- // ];
123
-
124
- // if (!this.popper) {
125
- // this.popper = createPopper(targetElement, popoverElement, {
126
- // placement: this.props.placement,
127
- // onFirstUpdate: () => {
128
- // if (targetElement) {
129
- // targetElement.focus();
130
- // }
131
- // focusStore.storeFocus();
132
- // keyboardFocusScope.scopeFocus(popoverElement);
133
- // },
134
- // modifiers: this.props.popperModifiers
135
- // ? [...this.props.popperModifiers, ...stdModifiers]
136
- // : stdModifiers,
137
- // });
138
- // }
139
-
140
- // this.previousTargetElement = targetElement;
141
- // if (this.popper) {
142
- // this.popper.update();
143
- // }
144
- // }
145
-
146
- render() {
147
- const {
148
- // isOpen,
149
- // onClose,
150
- // placement,
151
- // popperModifiers,
152
- portalClassName,
153
- // portalStyle,
154
- // renderTarget,
155
- // target,
156
- ...rest
157
- } = this.props;
158
- const classNames = getClassName('bpk-popover-portal', portalClassName);
159
-
160
- // if (portalClassName) {
161
- // classNames.push(portalClassName);
162
- // }
163
-
164
- return /*#__PURE__*/_jsx(_Fragment, {
165
- children: /*#__PURE__*/_jsx(BpkPopover, {
166
- className: classNames,
167
- onClose: this.onClose,
168
- ...rest
169
- })
170
- });
171
- }
172
- }
173
- export const propTypes = {
174
- // BpkPopover props - when migrating the popover to TS, we can import the type from BpkPopover
175
- children: PropTypes.node.isRequired,
176
- closeButtonText: PropTypes.string.isRequired,
177
- id: PropTypes.string.isRequired,
178
- label: PropTypes.string.isRequired,
179
- onClose: PropTypes.func.isRequired,
180
- className: PropTypes.string,
181
- closeButtonIcon: PropTypes.bool,
182
- closeButtonProps: PropTypes.object,
183
- labelAsTitle: PropTypes.bool,
184
- padded: PropTypes.bool,
185
- // BpkPopoverPortal additional props
186
- /**
187
- * In order to attach the popover to a regular DOM element, provide a function which returns it to `target`.
188
- * `target` can be a DOM element with a `ref` attached to it or a function that returns a DOM element.
189
- */
190
- target: PropTypes.oneOfType([PropTypes.func, PropTypes.node]).isRequired,
191
- isOpen: PropTypes.bool.isRequired,
192
- placement: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
193
- portalStyle: PropTypes.object,
194
- portalClassName: PropTypes.string,
195
- renderTarget: PropTypes.func,
196
- /**
197
- * Please refer to the [documentation](https://popper.js.org/docs/v2/modifiers/) for the underlying positioning library "Popper.js".
198
- * You can achieve various behaviours such as allowing the popover to overflow the viewport etc.
199
- */
200
- popperModifiers: PropTypes.arrayOf(PropTypes.object)
201
- };
202
- export const defaultProps = {
203
- // BpkPopover props - when migrating the popover to TS, we can import the type from BpkPopover
204
- className: null,
205
- closeButtonIcon: true,
206
- closeButtonProps: null,
207
- labelAsTitle: false,
208
- padded: true,
209
- // BpkPopoverPortal additional props
210
- placement: 'bottom',
211
- portalStyle: null,
212
- portalClassName: null,
213
- renderTarget: null,
214
- popperModifiers: null
215
- };
216
- BpkPopoverPortal.propTypes = {
217
- ...propTypes
218
- };
219
- BpkPopoverPortal.defaultProps = {
220
- ...defaultProps
221
- };
222
- export default BpkPopoverPortal;
@@ -1,76 +0,0 @@
1
- /*
2
- * Backpack - Skyscanner's Design System
3
- *
4
- * Copyright 2016 Skyscanner Ltd
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
-
19
- // This code is based on that from `a11y-focus-scope`.
20
- // Instead of completely preventing focus leaving the target element,
21
- // it only prevents it leaving due to keyboard events.
22
- // Clicks outside the target element will move focus as normal.
23
-
24
- import focusin from 'focusin';
25
- import tabbable from 'tabbable';
26
- let polyfilled = false;
27
- let focusTrapped = false;
28
- const init = element => {
29
- // lazily polyfill focusin for firefox
30
- if (!polyfilled) {
31
- focusin.polyfill();
32
- polyfilled = true;
33
- }
34
- const focus = () => {
35
- (tabbable(element)[0] || element).focus();
36
- };
37
- const enableFocusTrapping = () => {
38
- focusTrapped = true;
39
- };
40
- const disableFocusTrapping = () => {
41
- focusTrapped = false;
42
- };
43
- const checkFocus = event => {
44
- if (!focusTrapped) {
45
- return;
46
- }
47
- if (element !== event.target && !element.contains(event.target)) {
48
- focus();
49
- }
50
- };
51
- focus();
52
-
53
- // As we only want to trap focus for keyboard navigation, we enable focus trapping on keydown and disable it again on keyup.
54
- // This means that focus is trapped when pressing the tab key, but not trapped for other navigation events such as mouse clicks.
55
- document.addEventListener('keydown', enableFocusTrapping);
56
- document.addEventListener('focusin', checkFocus);
57
- document.addEventListener('keyup', disableFocusTrapping);
58
- return () => {
59
- document.removeEventListener('keydown', enableFocusTrapping);
60
- document.removeEventListener('focusin', checkFocus);
61
- document.removeEventListener('keyup', disableFocusTrapping);
62
- };
63
- };
64
- let teardownFn;
65
- const scopeFocus = element => {
66
- if (teardownFn) teardownFn();
67
- teardownFn = init(element);
68
- };
69
- const unscopeFocus = () => {
70
- if (teardownFn) teardownFn();
71
- teardownFn = null;
72
- };
73
- export default {
74
- scopeFocus,
75
- unscopeFocus
76
- };