Commit 66acfb1
authored
Support overlays in react portals in different document (#12445)
### WHY are these changes introduced?
Fix issues related to overlays not working correct in App Bridge modals
as outlined in this
[doc](https://docs.google.com/document/d/1eocCl07pk8xt7rvUaGDWZzfJxxeJ2yRi1ul0x0ezkDM/edit).
These specific issues will be fixed
- Shopify/shopify-app-bridge#316
-
Shopify/shopify-app-bridge#264 (comment)
-
Shopify/shopify-app-bridge#238 (comment)
- Shopify/shopify-app-bridge#301
### WHAT is this pull request doing?
Currently Overlays are broken when rendered using React portals. This PR
fixes the issue by doing the following:
- ensuring all references to `document` are updated to be
`node.ownerDocument` instead so the positioning can be calculated
correctly inside of iframes
- ensuring wherever we do `instanceOf HTMLElement` we instead just check
to see if the node is present or try to call the related methods
(`getBoundingClientRect`) with a fallback as the `instanceof` check will
fail when using React portals for iframe content since iframes have
their own globals
This PR only touches the related utils for Overlays but there are other
references to `document` and `instanceOf HTMLElement` we should also
update.
Expected usage with App Bridge v4, note that you have to wrap the
modal's content with the AppProvider from Polaris so that the portals
are created in the correct place.
For example, here's a modal with tooltips inside:
```jsx
import {AppProvider} from '@shopify/polaris';
import {Modal} from '@shopify/app-bridge-react';
function App() {
return (
<Modal>
<AppProvider i18n={{}}>
<div style={{padding: '75px 0'}}>
<Tooltip content="This order has shipping labels.">
<Text fontWeight="bold" as="span">
Order #1001
</Text>
</Tooltip>
<ButtonGroup variant="segmented" fullWidth>
<Tooltip content="Bold" dismissOnMouseOut>
<Button>B</Button>
</Tooltip>
<Tooltip content="Italic" dismissOnMouseOut>
<Button>I</Button>
</Tooltip>
<Tooltip content="Underline" dismissOnMouseOut>
<Button>U</Button>
</Tooltip>
<Tooltip content="Strikethrough" dismissOnMouseOut>
<Button>S</Button>
</Tooltip>
</ButtonGroup>
</div>
</AppProvider>
</Modal>
);
}
```
**Before**
https://github.com/user-attachments/assets/f7b7a7df-f25f-422c-a5bc-d1a8d7f12167
**After**
https://github.com/user-attachments/assets/6c1bf97a-e8f4-4715-9960-9f5709222f75
https://github.com/user-attachments/assets/ebc4755e-cc3b-413a-aaf5-9f39cc7b7ad0
### How to 🎩
🖥 [Local development
instructions](https://github.com/Shopify/polaris/blob/main/README.md#install-dependencies-and-build-workspaces)
🗒 [General tophatting
guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md)
📄 [Changelog
guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog)
1. Open the App Bridge Playground:
https://admin.shopify.com/store/trish-dev/apps/app-bridge-next-playground-4/react/index.html
2. Open all the custom content modals and do a smoke test to verify
overlay components are rendered on top with correct sizing and click
events are working
### 🎩 checklist
- [X] Tested a
[snapshot](https://github.com/Shopify/polaris/blob/main/documentation/Releasing.md#-snapshot-releases)
- [X] Tested on
[mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing)
- [X] Tested on [multiple
browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers)
~- [ ] Tested for
[accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md)~
~- [ ] Updated the component's `README.md` with documentation changes~
~- [ ] [Tophatted
documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md)
changes in the style guide~1 parent e7e5bd6 commit 66acfb1
File tree
26 files changed
+899
-80
lines changed- .changeset
- polaris-react
- src
- components
- ColorPicker
- components
- AlphaPicker
- tests
- HuePicker
- tests
- Slidable
- tests
- tests
- DropZone
- tests
- EventListener
- tests
- KeypressListener
- tests
- Popover
- components/PopoverOverlay
- tests
- tests
- PositionedOverlay
- utilities
- Tooltip
- utilities
- tests/setup
26 files changed
+899
-80
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | 8 | | |
11 | 9 | | |
12 | 10 | | |
| |||
67 | 65 | | |
68 | 66 | | |
69 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
70 | 74 | | |
71 | 75 | | |
72 | | - | |
| 76 | + | |
73 | 77 | | |
74 | 78 | | |
75 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
76 | 83 | | |
77 | 84 | | |
78 | 85 | | |
| |||
135 | 142 | | |
136 | 143 | | |
137 | 144 | | |
138 | | - | |
139 | 145 | | |
140 | 146 | | |
141 | 147 | | |
| |||
Lines changed: 30 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
28 | 46 | | |
29 | 47 | | |
30 | 48 | | |
| |||
33 | 51 | | |
34 | 52 | | |
35 | 53 | | |
36 | | - | |
| 54 | + | |
37 | 55 | | |
38 | 56 | | |
39 | 57 | | |
| |||
45 | 63 | | |
46 | 64 | | |
47 | 65 | | |
48 | | - | |
49 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
50 | 77 | | |
51 | 78 | | |
52 | 79 | | |
| |||
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
82 | 116 | | |
83 | 117 | | |
84 | 118 | | |
Lines changed: 31 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
25 | 43 | | |
26 | 44 | | |
27 | 45 | | |
28 | 46 | | |
29 | 47 | | |
30 | 48 | | |
31 | | - | |
| 49 | + | |
32 | 50 | | |
33 | 51 | | |
34 | 52 | | |
| |||
39 | 57 | | |
40 | 58 | | |
41 | 59 | | |
42 | | - | |
43 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
44 | 72 | | |
45 | 73 | | |
46 | 74 | | |
| |||
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
70 | 104 | | |
71 | 105 | | |
72 | 106 | | |
Lines changed: 63 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
52 | 58 | | |
53 | 59 | | |
54 | | - | |
55 | | - | |
| 60 | + | |
56 | 61 | | |
57 | 62 | | |
58 | 63 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
63 | 79 | | |
64 | | - | |
| 80 | + | |
65 | 81 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 82 | + | |
71 | 83 | | |
72 | 84 | | |
73 | 85 | | |
74 | | - | |
| 86 | + | |
75 | 87 | | |
76 | 88 | | |
77 | 89 | | |
| |||
83 | 95 | | |
84 | 96 | | |
85 | 97 | | |
| 98 | + | |
86 | 99 | | |
87 | 100 | | |
88 | 101 | | |
| |||
91 | 104 | | |
92 | 105 | | |
93 | 106 | | |
| 107 | + | |
94 | 108 | | |
95 | 109 | | |
96 | 110 | | |
97 | 111 | | |
98 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
99 | 117 | | |
100 | 118 | | |
101 | 119 | | |
102 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
103 | 125 | | |
104 | 126 | | |
105 | 127 | | |
106 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
107 | 133 | | |
108 | 134 | | |
109 | 135 | | |
| |||
127 | 153 | | |
128 | 154 | | |
129 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
130 | 177 | | |
131 | 178 | | |
132 | 179 | | |
| |||
0 commit comments