@skyscanner/backpack-web 22.2.0 → 22.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.
@@ -26,30 +26,28 @@ class MyComponent extends Component {
26
26
  this.state = {
27
27
  isOpen: false,
28
28
  };
29
-
30
29
  }
31
30
 
32
31
  onOpen = () => {
33
32
  this.setState({
34
33
  isOpen: true,
35
34
  });
36
- }
35
+ };
37
36
 
38
37
  onClose = () => {
39
38
  this.setState({
40
39
  isOpen: false,
41
40
  });
42
- }
41
+ };
43
42
 
44
43
  render() {
45
44
  return (
46
45
  <div>
47
46
  <BpkButton onClick={this.onOpen}>Open portal</BpkButton>
48
- <Portal
49
- isOpen={this.state.isOpen}
50
- onClose={this.onClose}
51
- >
52
- <div>I'm now appended to <BpkCode>document.body</BpkCode></div>
47
+ <Portal isOpen={this.state.isOpen} onClose={this.onClose}>
48
+ <div>
49
+ I'm now appended to <BpkCode>document.body</BpkCode>
50
+ </div>
53
51
  </Portal>
54
52
  </div>
55
53
  );
@@ -57,19 +55,25 @@ class MyComponent extends Component {
57
55
  }
58
56
  ```
59
57
 
58
+ **NOTE:** Events used to bubble up from the portal into the parent component. Due to the way React works, events do not
59
+ bubble up into the component in the DOM where the portal is rendered (i.e. render target), but instead they bubble up
60
+ into the parent component in the shadow DOM, that is the component where you added the `Portal` in your React code. To
61
+ avoid confusion and bugs caused by this behaviour, we have prevented mouse and keyboard events from bubbling up outside
62
+ the portal.
63
+
60
64
  ### Props
61
65
 
62
- | Property | PropType | Required | Default Value |
63
- | --------------------- | ----------------------- | -------- | ------------- |
64
- | children | node | true | - |
65
- | isOpen | bool | true | - |
66
- | beforeClose | func | false | null |
67
- | onClose | func | false | noop |
68
- | onOpen | func | false | noop |
69
- | onRender | func | false | noop |
70
- | renderTarget | func | false | null |
71
- | target | oneOf([function, node]) | false | null |
72
- | closeOnEscPressed | bool | false | true |
66
+ | Property | PropType | Required | Default Value |
67
+ | ----------------- | ----------------------- | -------- | ------------- |
68
+ | children | node | true | - |
69
+ | isOpen | bool | true | - |
70
+ | beforeClose | func | false | null |
71
+ | onClose | func | false | noop |
72
+ | onOpen | func | false | noop |
73
+ | onRender | func | false | noop |
74
+ | renderTarget | func | false | null |
75
+ | target | oneOf([function, node]) | false | null |
76
+ | closeOnEscPressed | bool | false | true |
73
77
 
74
78
  ## `cssModules.js`
75
79
 
@@ -86,9 +90,7 @@ const getClassName = cssModules(STYLES);
86
90
 
87
91
  const MyComponent = (props) => (
88
92
  <div className={getClassName('MyComponent')}>
89
- <div className={getClassName('MyComponent__inner')}>
90
- {props.children}
91
- </div>
93
+ <div className={getClassName('MyComponent__inner')}>{props.children}</div>
92
94
  </div>
93
95
  );
94
96
  ```
@@ -97,9 +99,7 @@ With CSS modules:
97
99
 
98
100
  ```html
99
101
  <div class="_35WloynrPDta8fhSfoHEgE">
100
- <div class="_1ghNYY7jOYzUneVCT4piQ9">
101
- Some text.
102
- </div>
102
+ <div class="_1ghNYY7jOYzUneVCT4piQ9">Some text.</div>
103
103
  </div>
104
104
  ```
105
105
 
@@ -107,9 +107,7 @@ Without CSS modules:
107
107
 
108
108
  ```html
109
109
  <div class="MyComponent">
110
- <div class="MyComponent__inner">
111
- Some text.
112
- </div>
110
+ <div class="MyComponent__inner">Some text.</div>
113
111
  </div>
114
112
  ```
115
113
 
@@ -123,8 +121,13 @@ import STYLES from './MyComponent.scss';
123
121
  const getClassNames = cssModules(STYLES);
124
122
 
125
123
  const MyComponent = (props) => (
126
- <div className={getClassName('MyComponent', props.disabled && 'MyComponent--disabled')}>
127
- {props.children}
124
+ <div
125
+ className={getClassName(
126
+ 'MyComponent',
127
+ props.disabled && 'MyComponent--disabled',
128
+ )}
129
+ >
130
+ {props.children}
128
131
  </div>
129
132
  );
130
133
  ```
@@ -263,7 +263,22 @@ class Portal extends Component {
263
263
  return null;
264
264
  }
265
265
 
266
- return createPortal(children, portalElement);
266
+ const stopPropagationHandler = (e) => e.stopPropagation();
267
+
268
+ return createPortal(
269
+ <div
270
+ onClick={stopPropagationHandler}
271
+ onMouseDown={stopPropagationHandler}
272
+ onMouseUp={stopPropagationHandler}
273
+ onKeyDown={stopPropagationHandler}
274
+ onKeyUp={stopPropagationHandler}
275
+ tabIndex={-1}
276
+ role="none"
277
+ >
278
+ {children}
279
+ </div>,
280
+ portalElement,
281
+ );
267
282
  }
268
283
  }
269
284
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "22.2.0",
3
+ "version": "22.3.0",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",