@spectrum-web-components/overlay 0.36.0 → 0.37.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.
Files changed (156) hide show
  1. package/README.md +266 -149
  2. package/custom-elements.json +1678 -553
  3. package/package.json +49 -22
  4. package/sp-overlay.d.ts +6 -0
  5. package/sp-overlay.dev.js +5 -0
  6. package/{active-overlay.dev.js.map → sp-overlay.dev.js.map} +3 -3
  7. package/sp-overlay.js +2 -0
  8. package/{active-overlay.js.map → sp-overlay.js.map} +4 -4
  9. package/src/AbstractOverlay.d.ts +58 -0
  10. package/src/AbstractOverlay.dev.js +211 -0
  11. package/src/AbstractOverlay.dev.js.map +7 -0
  12. package/src/AbstractOverlay.js +2 -0
  13. package/src/AbstractOverlay.js.map +7 -0
  14. package/src/Overlay.d.ts +163 -0
  15. package/src/Overlay.dev.js +792 -0
  16. package/src/Overlay.dev.js.map +7 -0
  17. package/src/Overlay.js +33 -0
  18. package/src/Overlay.js.map +7 -0
  19. package/src/OverlayDialog.d.ts +4 -0
  20. package/src/OverlayDialog.dev.js +135 -0
  21. package/src/OverlayDialog.dev.js.map +7 -0
  22. package/src/OverlayDialog.js +2 -0
  23. package/src/OverlayDialog.js.map +7 -0
  24. package/src/OverlayNoPopover.d.ts +4 -0
  25. package/src/OverlayNoPopover.dev.js +109 -0
  26. package/src/OverlayNoPopover.dev.js.map +7 -0
  27. package/src/OverlayNoPopover.js +2 -0
  28. package/src/OverlayNoPopover.js.map +7 -0
  29. package/src/OverlayPopover.d.ts +4 -0
  30. package/src/OverlayPopover.dev.js +169 -0
  31. package/src/OverlayPopover.dev.js.map +7 -0
  32. package/src/OverlayPopover.js +2 -0
  33. package/src/OverlayPopover.js.map +7 -0
  34. package/src/OverlayStack.d.ts +43 -0
  35. package/src/OverlayStack.dev.js +150 -0
  36. package/src/OverlayStack.dev.js.map +7 -0
  37. package/src/OverlayStack.js +2 -0
  38. package/src/OverlayStack.js.map +7 -0
  39. package/src/OverlayTrigger.d.ts +26 -42
  40. package/src/OverlayTrigger.dev.js +172 -296
  41. package/src/OverlayTrigger.dev.js.map +3 -3
  42. package/src/OverlayTrigger.js +49 -25
  43. package/src/OverlayTrigger.js.map +3 -3
  44. package/src/PlacementController.d.ts +38 -0
  45. package/src/PlacementController.dev.js +199 -0
  46. package/src/PlacementController.dev.js.map +7 -0
  47. package/src/PlacementController.js +2 -0
  48. package/src/PlacementController.js.map +7 -0
  49. package/src/VirtualTrigger.dev.js +2 -1
  50. package/src/VirtualTrigger.dev.js.map +2 -2
  51. package/src/VirtualTrigger.js +1 -1
  52. package/src/VirtualTrigger.js.map +2 -2
  53. package/src/fullSizePlugin.d.ts +12 -0
  54. package/src/fullSizePlugin.dev.js +39 -0
  55. package/src/fullSizePlugin.dev.js.map +7 -0
  56. package/src/fullSizePlugin.js +2 -0
  57. package/src/fullSizePlugin.js.map +7 -0
  58. package/src/index.d.ts +2 -3
  59. package/src/index.dev.js +2 -3
  60. package/src/index.dev.js.map +2 -2
  61. package/src/index.js +1 -1
  62. package/src/index.js.map +2 -2
  63. package/src/loader.d.ts +1 -2
  64. package/src/loader.dev.js +2 -19
  65. package/src/loader.dev.js.map +2 -2
  66. package/src/loader.js +1 -1
  67. package/src/loader.js.map +3 -3
  68. package/src/overlay-timer.dev.js.map +2 -2
  69. package/src/overlay-timer.js.map +2 -2
  70. package/src/overlay-trigger.css.dev.js +1 -1
  71. package/src/overlay-trigger.css.dev.js.map +1 -1
  72. package/src/overlay-trigger.css.js +3 -3
  73. package/src/overlay-trigger.css.js.map +1 -1
  74. package/src/overlay-types.d.ts +25 -31
  75. package/src/overlay-types.dev.js +1 -0
  76. package/src/overlay-types.dev.js.map +3 -3
  77. package/src/overlay-types.js +1 -1
  78. package/src/overlay-types.js.map +3 -3
  79. package/src/overlay.css.dev.js +9 -0
  80. package/src/overlay.css.dev.js.map +7 -0
  81. package/src/overlay.css.js +6 -0
  82. package/src/overlay.css.js.map +7 -0
  83. package/src/topLayerOverTransforms.d.ts +2 -0
  84. package/src/topLayerOverTransforms.dev.js +91 -0
  85. package/src/topLayerOverTransforms.dev.js.map +7 -0
  86. package/src/topLayerOverTransforms.js +2 -0
  87. package/src/topLayerOverTransforms.js.map +7 -0
  88. package/stories/overlay-element.stories.js +476 -0
  89. package/stories/overlay-element.stories.js.map +7 -0
  90. package/stories/overlay-story-components.js +9 -8
  91. package/stories/overlay-story-components.js.map +2 -2
  92. package/stories/overlay.stories.js +824 -680
  93. package/stories/overlay.stories.js.map +2 -2
  94. package/sync/overlay-trigger.d.ts +5 -0
  95. package/sync/overlay-trigger.dev.js +2 -4
  96. package/sync/overlay-trigger.dev.js.map +2 -2
  97. package/sync/overlay-trigger.js +1 -1
  98. package/sync/overlay-trigger.js.map +3 -3
  99. package/test/benchmark/basic-test.js +2 -2
  100. package/test/benchmark/basic-test.js.map +1 -1
  101. package/test/index.js +414 -377
  102. package/test/index.js.map +3 -3
  103. package/test/overlay-element.test-vrt.js +5 -0
  104. package/test/overlay-element.test-vrt.js.map +7 -0
  105. package/test/overlay-element.test.js +682 -0
  106. package/test/overlay-element.test.js.map +7 -0
  107. package/test/overlay-lifecycle.test.js +36 -106
  108. package/test/overlay-lifecycle.test.js.map +2 -2
  109. package/test/overlay-trigger-click.test.js +11 -5
  110. package/test/overlay-trigger-click.test.js.map +2 -2
  111. package/test/overlay-trigger-extended.test.js +46 -36
  112. package/test/overlay-trigger-extended.test.js.map +2 -2
  113. package/test/overlay-trigger-hover-click.test.js +38 -25
  114. package/test/overlay-trigger-hover-click.test.js.map +2 -2
  115. package/test/overlay-trigger-hover.test.js +41 -35
  116. package/test/overlay-trigger-hover.test.js.map +2 -2
  117. package/test/overlay-trigger-longpress.test.js +211 -82
  118. package/test/overlay-trigger-longpress.test.js.map +2 -2
  119. package/test/overlay-trigger-sync.test.js +1 -1
  120. package/test/overlay-trigger-sync.test.js.map +2 -2
  121. package/test/overlay-trigger.test.js +1 -1
  122. package/test/overlay-trigger.test.js.map +2 -2
  123. package/test/overlay-update.test.js +5 -5
  124. package/test/overlay-update.test.js.map +2 -2
  125. package/test/overlay-v1.test.js +547 -0
  126. package/test/overlay-v1.test.js.map +7 -0
  127. package/test/overlay.test.js +385 -269
  128. package/test/overlay.test.js.map +3 -3
  129. package/active-overlay.d.ts +0 -6
  130. package/active-overlay.dev.js +0 -5
  131. package/active-overlay.js +0 -2
  132. package/src/ActiveOverlay.d.ts +0 -84
  133. package/src/ActiveOverlay.dev.js +0 -517
  134. package/src/ActiveOverlay.dev.js.map +0 -7
  135. package/src/ActiveOverlay.js +0 -16
  136. package/src/ActiveOverlay.js.map +0 -7
  137. package/src/active-overlay.css.dev.js +0 -13
  138. package/src/active-overlay.css.dev.js.map +0 -7
  139. package/src/active-overlay.css.js +0 -10
  140. package/src/active-overlay.css.js.map +0 -7
  141. package/src/overlay-stack.d.ts +0 -50
  142. package/src/overlay-stack.dev.js +0 -515
  143. package/src/overlay-stack.dev.js.map +0 -7
  144. package/src/overlay-stack.js +0 -34
  145. package/src/overlay-stack.js.map +0 -7
  146. package/src/overlay-utils.d.ts +0 -3
  147. package/src/overlay-utils.dev.js +0 -31
  148. package/src/overlay-utils.dev.js.map +0 -7
  149. package/src/overlay-utils.js +0 -2
  150. package/src/overlay-utils.js.map +0 -7
  151. package/src/overlay.d.ts +0 -59
  152. package/src/overlay.dev.js +0 -127
  153. package/src/overlay.dev.js.map +0 -7
  154. package/src/overlay.js +0 -2
  155. package/src/overlay.js.map +0 -7
  156. /package/src/{active-overlay.css.d.ts → overlay.css.d.ts} +0 -0
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## Description
2
2
 
3
- Overlays in Spectrum Web Components are created via the `Overlay` class system, which prepares an "overlay stack" that can manage the deployment of one or more overlays onto a page. Whether it's needed for transient content like a tooltip, for extended interactions like selecting a value from a picker, or for blocking content like a modal, the imperative APIs outlined below or the declarative APIs delivered by `<overlay-trigger>` should cover your overlay delivery needs.
3
+ An `<sp-overlay>` element is used to decorate content that you would like to present to your visitors as "overlaid" on the rest of the application. This includes dialogs (modal and not), pickers, tooltips, context menus, et al.
4
4
 
5
5
  ### Usage
6
6
 
@@ -11,190 +11,307 @@ Overlays in Spectrum Web Components are created via the `Overlay` class system,
11
11
  yarn add @spectrum-web-components/overlay
12
12
  ```
13
13
 
14
- Import the `Overlay` class to leverage its capabilities within your application or custom element:
14
+ Import the side effectful registration of `<sp-overlay>` as follows:
15
15
 
16
- ```js
17
- import { Overlay } from '@spectrum-web-components/overlay';
16
+ ```
17
+ import '@spectrum-web-components/overlay/sp-overlay.js';
18
18
  ```
19
19
 
20
- Primarily, this class gives you access to the `open` method that will allow you to open an overlay:
20
+ When looking to leverage the `Overlay` base class as a type and/or for extension purposes, do so via:
21
21
 
22
- ```js
23
- Overlay.open(
24
- (owner: HTMLElement), // the element to open the overlay in reference to, "trigger"
25
- (interaction: TriggerInteractions), // the type of interaction type that opened the overlay
26
- (overlayElement: HTMLElement), // the element that will be projected into the overlay, "content"
27
- (options: OverlayOptions) // options to customize the overlay
28
- );
29
22
  ```
30
-
31
- `Overlay.open()` is an asynchronous method that returns a function for closing the overlay, so it is common to leverage this functionality like the following:
32
-
33
- ```js
34
- (async () => {
35
- const trigger = document.querySelector('#trigger');
36
- const interaction = 'click';
37
- const content = document.querySelector('#content');
38
- const options = {
39
- offset: 0,
40
- placement: 'bottom',
41
- };
42
- const closeOverlay = await Overlay.open(
43
- trigger,
44
- interaction,
45
- content,
46
- options
47
- );
48
- })();
23
+ import {
24
+ Overlay
25
+ } from '@spectrum-web-components/overlay';
49
26
  ```
50
27
 
51
- ## Types
28
+ ## Example
29
+
30
+ By leveraging the `trigger` attribute to pass an ID reference to another element with in the same DOM tree, your overlay will be positioned in relation to this element. When the ID reference is followed by an `@` symbol and interaction type, like `click`, `hover`, or `longpress`, the overlay will bind itself to the referenced element via the DOM events associated with that interaction. For example, the `<sp-button>` below has an id of `trigger`, and the `<sp-overlay>` is provided the `trigger` attribute with the value `trigger@click`. This creates an association between the overlay and the `<sp-button>` that opens the overlay when the button is clicked.
52
31
 
53
- ### TriggerInteractions
32
+ ```html
33
+ <sp-button id="trigger">Overlay Trigger</sp-button>
34
+ <sp-overlay trigger="trigger@click">
35
+ <sp-popover>
36
+ <sp-dialog>
37
+ <h2 slot="heading">Clicking opens this popover...</h2>
38
+ <p>But, it really could be anything. Really.</p>
39
+ </sp-dialog>
40
+ </sp-popover>
41
+ </sp-overlay>
42
+ ```
54
43
 
55
- This outlines the user experience that is to be delivered through the process of opening and closing an overlay.
44
+ ### Action bar
56
45
 
46
+ ```html
47
+ <style>
48
+ .overlay-demo-popover sp-action-group {
49
+ padding: var(--spectrum-actiongroup-vertical-spacing-regular);
50
+ }
51
+ #overlay-demo {
52
+ position: static;
53
+ }
54
+ #overlay-demo:not(:defined),
55
+ #overlay-demo *:not(:defined) {
56
+ display: none;
57
+ }
58
+ </style>
59
+ <sp-popover id="overlay-demo" class="overlay-demo-popover" open>
60
+ <sp-action-group vertical quiet emphasized selects="single">
61
+ <sp-action-button id="trigger-1" hold-affordance>
62
+ <sp-icon-anchor-select slot="icon"></sp-icon-anchor-select>
63
+ </sp-action-button>
64
+ <sp-action-button id="trigger-2" hold-affordance>
65
+ <sp-icon-polygon-select slot="icon"></sp-icon-polygon-select>
66
+ </sp-action-button>
67
+ <sp-action-button id="trigger-3" hold-affordance>
68
+ <sp-icon-rect-select slot="icon"></sp-icon-rect-select>
69
+ </sp-action-button>
70
+ </sp-action-group>
71
+ <sp-overlay trigger="trigger-1@hover" type="hint">
72
+ <sp-tooltip>Hover</sp-tooltip>
73
+ </sp-overlay>
74
+ <sp-overlay
75
+ trigger="trigger-1@longpress"
76
+ type="auto"
77
+ placement="right-start"
78
+ >
79
+ <sp-popover class="overlay-demo-popover" tip>
80
+ <sp-action-group vertical quiet>
81
+ <sp-action-button>
82
+ <sp-icon-anchor-select slot="icon"></sp-icon-anchor-select>
83
+ </sp-action-button>
84
+ <sp-action-button>
85
+ <sp-icon-polygon-select
86
+ slot="icon"
87
+ ></sp-icon-polygon-select>
88
+ </sp-action-button>
89
+ <sp-action-button>
90
+ <sp-icon-rect-select slot="icon"></sp-icon-rect-select>
91
+ </sp-action-button>
92
+ </sp-action-group>
93
+ </sp-popover>
94
+ </sp-overlay>
95
+ <sp-overlay trigger="trigger-2@hover" type="hint">
96
+ <sp-tooltip>Hover</sp-tooltip>
97
+ </sp-overlay>
98
+ <sp-overlay
99
+ trigger="trigger-2@longpress"
100
+ type="auto"
101
+ placement="right-start"
102
+ >
103
+ <sp-popover class="overlay-demo-popover" tip>
104
+ <sp-action-group vertical quiet>
105
+ <sp-action-button>
106
+ <sp-icon-anchor-select slot="icon"></sp-icon-anchor-select>
107
+ </sp-action-button>
108
+ <sp-action-button>
109
+ <sp-icon-polygon-select
110
+ slot="icon"
111
+ ></sp-icon-polygon-select>
112
+ </sp-action-button>
113
+ <sp-action-button>
114
+ <sp-icon-rect-select slot="icon"></sp-icon-rect-select>
115
+ </sp-action-button>
116
+ </sp-action-group>
117
+ </sp-popover>
118
+ </sp-overlay>
119
+ <sp-overlay trigger="trigger-3@hover" type="hint">
120
+ <sp-tooltip>Hover</sp-tooltip>
121
+ </sp-overlay>
122
+ <sp-overlay
123
+ trigger="trigger-3@longpress"
124
+ type="auto"
125
+ placement="right-start"
126
+ >
127
+ <sp-popover class="overlay-demo-popover" tip>
128
+ <sp-action-group vertical quiet>
129
+ <sp-action-button>
130
+ <sp-icon-anchor-select slot="icon"></sp-icon-anchor-select>
131
+ </sp-action-button>
132
+ <sp-action-button>
133
+ <sp-icon-polygon-select
134
+ slot="icon"
135
+ ></sp-icon-polygon-select>
136
+ </sp-action-button>
137
+ <sp-action-button>
138
+ <sp-icon-rect-select slot="icon"></sp-icon-rect-select>
139
+ </sp-action-button>
140
+ </sp-action-group>
141
+ </sp-popover>
142
+ </sp-overlay>
143
+ </sp-popover>
57
144
  ```
58
- type TriggerInteractions =
59
- | 'click'
60
- | 'custom',
61
- | 'hover'
62
- | 'inline'
63
- | 'modal'
64
- | 'replace';
145
+
146
+ ## API
147
+
148
+ ```ts
149
+ <sp-overlay
150
+ ?open=${boolean}
151
+ ?delayed=${boolean}
152
+ offset=${Number | [Number, Number]}
153
+ placement=${Placement}
154
+ receives-focus=${'true' | 'false' | 'auto' (default)
155
+ trigger=${string | ${string}@${string}}
156
+ .triggerElement=${HTMLElement}
157
+ .triggerInteraction=${'click' | 'longpress' | 'hover'}
158
+ type=${'auto' | 'hint' | 'manual' | 'modal' | 'page'}
159
+ ></sp-overlay>
65
160
  ```
66
161
 
67
- `click` will open an overlay that will close immediately on the next click that is not on an element within the overlay.
162
+ ### API value interactions
68
163
 
69
- `custom` is less opinionated and allows for some customization of the process from the outside.
164
+ When a `triggerElement` is present, either through an ID reference established via the `trigger` attribute or by directly setting the `triggerElement` property, a chain on configuration begins:
70
165
 
71
- `hover` will close the overlay as soon as the pointer leaves the trigger to which the overlay is connected.
166
+ - **if a `triggerInteraction` is available**, either through the `id@interaction` IDL on the `trigger` attribute or directly setting the `triggerInteraction` property, the `<sp-overlay>` will be bound to the resolved `triggerElement` via the `triggerInteraction` provided
167
+ - **if a `placement` is available** when the `<sp-overlay>` is `open` and displaying its contents, those contents will be positioned relative to the `triggerElement` as per that `placement`
168
+ - **if an `offset` is also available** the `<sp-overlay>` will distance itself from the `triggerElement` in accordance with the value of the `offset`
169
+ - **if you have a `placement` but not a `triggerElement`** the `<sp-overlay>` will not be positioned due to their being nothing for the `plaement` to reference when so doing
170
+ - **if no `placement` is available** the content will not be placed with the expectation that the content itself or the consuming application will handle placement of the overlaid content. This is commonly what will happen for `type="modal"` and `type="page"` overlays as they are likely meant to cover the entire screen, whether visibly (via an `<sp-underlay>`, an element that includes one, or similar) or figuratively (as when modal content is not delivered with a backdrop or scrim).
72
171
 
73
- `inline` places the overlay after the trigger but before the next element in the logical tab order. This means the `shift + tab` keyboard stroke will return to the trigger.
172
+ ### Events
74
173
 
75
- `modal` manages the overlay like a modal and will trap the tab order within its contents only.
174
+ When fully open the `<sp-overlay>` element will dispatch the `sp-opened` event, and when fully closed the `sp-closed` event will be dispatched. "Fully" in this context means that all CSS transitions that have dispatched `transitionrun` events on the direct children of the `<sp-overlay>` element have successfully dispatched their `transitionend` or `transitioncancel` event. Keep in mind the following:
76
175
 
77
- `replace` will position the overlay directly in the position of the trigger in the logical tab order. This means the `shift + tab` keyboard stroke will return the focusable element immediately prior to the trigger.
176
+ - `transition*` events bubble; this means that while transition events on light DOM content of those direct children will be heard, those events will not be taken into account
177
+ - `transition*` events are not composed; this means that transition events on shadow DOM content of the direct children will not propagate to a level in the DOM where they can be heard
78
178
 
79
- ### OverlayOptions
179
+ This means that in both cases, if the transition is meant to be a part of the opening or closing of the overlay in question you will need to redispatch the `transitionrun`, `transitionend`, and `transitioncancel` events from that transition from the closest direct child of the `<sp-overlay>`.
80
180
 
81
- ```
82
- type OverlayOptions = {
83
- delayed?: boolean;
84
- placement?: Placement;
85
- offset?: number;
86
- receivesFocus?: 'auto';
87
- notImmediatelyClosable?: boolean;
88
- }
89
- ```
181
+ ## Styling
90
182
 
91
- `delayed` allows for the overlay to open the overlay with warmup/cooldown behaviors as described at https://spectrum.adobe.com/page/tooltip/#Immediate-or-delayed-appearance
183
+ `<sp-overlay>` element will use the `<dialog>` element or `popover` attribute to project your content onto the top-layer of the browser, without being moved in the DOM tree. That means that you can style your overlay content with whatever techniques you are already leveraging to style the content that doesn't get overlaid. This means standard CSS selectors, CSS Custom Properties, and CSS Parts applied in your parent context will always apply to your overlaid content.
92
184
 
93
- `placement` outlines where the overlay system should attempt to position the overlay in relation to the trigger. When the layout of the page and/or current scroll positioning prevents the successful placement of the content in this way, the `placement` will be automatically applied as the value best suited for those conditions. Placements available include: `"auto" | "auto-start" | "auto-end" | "top" | "bottom" | "right" | "left" | "top-start" | "top-end" | "bottom-start" | "bottom-end" | "right-start" | "right-end" | "left-start" | "left-end" | "none"`.
185
+ ## Top Layer over Complex CSS
94
186
 
95
- `offset` defines the distance of the overlay content from the trigger, measured in pixels.
187
+ There are some complex CSS values that have not yet been covered by the positioning API that the `<sp-overlay>` element leverages to associate overlaid content with their trigger elements. In specific, properties like `filter`, when applied to a trigger element within which lives the related content to be overlaid, are not currently supported by the relationship created herein. If support for this is something that you and the work you are addressing would require, we'd love to hear from you in [an issue](https://github.com/adobe/spectrum-web-components/issues). We'd be particularly interested in speaking with you if you were interested in contributing support/testing to ensure this capability for all consumers of the library.
96
188
 
97
- `receivesFocus` tells the overlay stack to throw focus into the overlay after it has opened.
189
+ ## Fallback support
98
190
 
99
- `notImmediatelyClosable` prevents immediate clicks from closing the overlay. If you find that a trigger event is immediately overridden with a subsequent click (for instance, a `focus` trigger that should be closed on `click`), set `notImmediatelyClosable: true` to disregard clicks that coincide with the opening trigger.
191
+ While the [`<dialog>` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog) is widely supported by browsers, the [`popover` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/popover) is still quite new. When leveraged in browsers that do not yet support the `popover` attribute, there may be additional intervention required to ensure your content is delivered to your visitors as expected.
100
192
 
101
- ### Events
193
+ ### Complex layered
102
194
 
103
- The work to both open and close an overlay is asynchronous. This asynchrony is surfaced into the application via DOM events dispatched from the `trigger` element of your overlay. An `sp-opened` event will be dispatched once the overlay has finished opening, and an `sp-closed` event will be dispatched once the overlay has finished closing. In both cases, the dispatched event will include a `detail` property with an `interaction: TriggerInteractions` key to support associating the event/overlay with its originating `interaction`.
195
+ When an overlay is placed within a page with complex layering, the content therein can fall behind other content in the `z-index` stack. The following example is somewhat contrived but, imagine a toolbar next to a properties panel. If the toolbar has a lower `z-index` than the properties panel, any overlaid content (tooltips, etc.) within that toolbar will display underneath any content in the properties panel with which it may share pixels.
104
196
 
105
- ## Example
197
+ ```html
198
+ <div class="complex-layered-demo">
199
+ <div class="complex-layered-holder">
200
+ <sp-action-button id="complex-layered">Trigger</sp-action-button>
201
+ <sp-overlay
202
+ trigger="complex-layered@hover"
203
+ type="hint"
204
+ placement="bottom-start"
205
+ >
206
+ <sp-tooltip>
207
+ I can be partially blocked when [popover] is not available
208
+ </sp-tooltip>
209
+ </sp-overlay>
210
+ </div>
211
+ <div class="complex-layered-blocker"></div>
212
+ </div>
213
+ <style>
214
+ .complex-layered-demo {
215
+ position: relative;
216
+ }
217
+ .complex-layered-holder {
218
+ z-index: 1;
219
+ position: relative;
220
+ }
221
+ .complex-layered-blocker {
222
+ position: relative;
223
+ z-index: 10;
224
+ background: white;
225
+ width: 100%;
226
+ height: 40px;
227
+ }
228
+ </style>
229
+ ```
230
+
231
+ Properly managed `z-index` values will support working around this issue while browsers work to adopt the `popover` attribute. In this demo, you can achieve the same output by sharing one `z-index` between the various pieces of content, removing `z-index` values altogether, or raising the `.complex-layered-holder` element to a higher `z-index` than the `.complex-layered-blocker` element.
232
+
233
+ ### Contained
234
+
235
+ [CSS Containment](https://developer.mozilla.org/en-US/docs/Web/CSS/contain) gives a developer direct control over how the internals of one element affect the paint and layout of the internals of other elements on the same page. While leveraging some of its values can offer performance gains, they can interrupt the delivery of your overlaid content.
106
236
 
107
237
  ```html
108
- <sp-button
109
- onclick="
110
- const trigger = this;
111
- const interaction = 'click';
112
- const content = this.nextElementSibling;
113
- if (!content) return;
114
- const options = {
115
- offset: 0,
116
- placement: 'right',
117
- };
118
- content.open = true;
119
- const closeOverlayPromise = Overlay.open(
120
- trigger,
121
- interaction,
122
- content,
123
- options
124
- );
125
- setTimeout(function () {
126
- closeOverlayPromise.then(function(close) {
127
- close();
128
- content.open = false;
129
- });
130
- }, 5000);
131
- "
132
- >
133
- Click me for a 5 second overlay!
134
- </sp-button>
135
- <sp-popover>
136
- <sp-dialog size="medium">
137
- <h2 slot="heading">Demo</h2>
138
- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
139
- tempor incididunt ut labore et dolore magna aliqua. Auctor augue mauris
140
- augue neque gravida. Libero volutpat sed ornare arcu. Quisque egestas
141
- diam in arcu cursus euismod quis viverra. Posuere ac ut consequat semper
142
- viverra nam libero justo laoreet. Enim ut tellus elementum sagittis
143
- vitae et leo duis ut. Neque laoreet suspendisse interdum consectetur
144
- libero id faucibus nisl. Diam volutpat commodo sed egestas egestas.
145
- Dolor magna eget est lorem ipsum dolor. Vitae suscipit tellus mauris a
146
- diam maecenas sed. Turpis in eu mi bibendum neque egestas congue.
147
- Rhoncus est pellentesque elit ullamcorper dignissim cras lobortis.
148
- </sp-dialog>
149
- </sp-popover>
238
+ <div class="contained-demo">
239
+ <sp-action-button id="contained">Trigger</sp-action-button>
240
+ <sp-overlay trigger="contained@hover" type="hint" placement="bottom-start">
241
+ <sp-tooltip>
242
+ I can be blocked when [popover] is not available
243
+ </sp-tooltip>
244
+ </sp-overlay>
245
+ </div>
246
+ <style>
247
+ .contained-demo {
248
+ contain: content;
249
+ }
250
+ </style>
150
251
  ```
151
252
 
152
- ## Styling
253
+ You could just _remove_ the `contain` rule. But, if you are not OK with simply removing the `contain` value, you still have options. If you would like to continue to leverage `contain`, you can place your "contained" content separately from your overlaid content, like so:
153
254
 
154
- When an overlay is opened from within a styled DOM scope as created by an `<sp-theme>` element, this scope will be resolved and recreated with in the `<active-overlay>` element that is created to host the overlaid content directly in the `<body>`. By default, the generated `<sp-theme>` element will be supplied with settings of the scope from which the overlay is triggered, including any "app" centric CSS Custom Properties that might be applied via `Theme.registerThemeFragment('app', 'app', themeFragment)` therein. In the case that you have set CSS Custom Properties for the scope created by an `<sp-theme>` element via other methods, you can specify that those values should also be applied to overlay content using the `theme` part on the `<active-overlay>` element via the `active-overlay::part(theme) { /* styles */ }` selector.
255
+ ```html
256
+ <div class="contained-demo">
257
+ <sp-action-button id="contained-working">Trigger</sp-action-button>
258
+ </div>
259
+ <sp-overlay
260
+ trigger="contained-working@hover"
261
+ type="hint"
262
+ placement="bottom-start"
263
+ >
264
+ <sp-tooltip>I can be blocked when [popover] is not available</sp-tooltip>
265
+ </sp-overlay>
266
+ <style>
267
+ .contained-demo {
268
+ contain: content;
269
+ }
270
+ </style>
271
+ ```
155
272
 
156
- ## Advanced Usage
273
+ `<sp-overlay>` accepts an ID reference via the `trigger` attribute to relate it to interactions and positioning in the DOM. To fulfill this reference the two elements need to be in the same DOM tree. However, `<sp-overlay>` alternatively accepts a `triggerElement` _property_ that opens even more flexibility in addressing this situation.
157
274
 
158
- When working with the DOM-based APIs of custom elements, it is sometimes preferred to project content into an overlay from a different shadow root (eg projecting a single-slotted element into the overlay). To ensure that the content can be marshalled through any number of `<slot>` elements which are addressed into subsequent `<slot>` elements, be sure to use the `flatten: true` option when querying `slot.asignedNodes()`:
275
+ ### Clip pathed
159
276
 
160
- ```js
161
- const trigger = shadowRoot.querySelector('#trigger');
162
- const slot = shadowRoot.querySelector('slot');
163
- const interaction = 'click';
164
- const content = slot
165
- .assignedNodes({ flatten: true })
166
- .find((node) => node instanceof HTMLElement);
167
- const options = {
168
- offset: 0,
169
- placement: 'bottom',
170
- };
171
- const closeOverlay = await Overlay.open(trigger, interaction, content, options);
277
+ `clip-path` can also restrict how content in an element is surfaced at paint time. When overlaid content should display outside of the `clip-path`, without the `popover` attribute, that content could be _clipped_.
278
+
279
+ ```html
280
+ <div class="clip-pathed-demo">
281
+ <sp-action-button id="clip-pathed">Trigger</sp-action-button>
282
+ <sp-overlay
283
+ trigger="clip-pathed@hover"
284
+ type="hint"
285
+ placement="bottom-start"
286
+ >
287
+ <sp-tooltip>
288
+ I can be blocked when [popover] is not available
289
+ </sp-tooltip>
290
+ </sp-overlay>
291
+ </div>
292
+ <style>
293
+ .clip-pathed-demo {
294
+ clip-path: inset(0 0);
295
+ }
296
+ </style>
172
297
  ```
173
298
 
174
- Other times, you may want to compose content from multiple shadow roots into a single overlay. This is a pattern seen in the `<sp-dropdown>` element: its `<sp-menu>` light DOM child is wrapped by its `<sp-popover>` shadow DOM child before being projected into an overlay. What follows is a more trivial example, where content in the light DOM of an element is injected into an element in the shadow DOM of the same element and then projected into an overlay. Notice the added work here of setting a comment node into the light DOM as a placeholder for the "stolen" content, and then swapping that content back into the light DOM when the overlay is closed.
175
-
176
- ```js
177
- const trigger = this.shadowRoot.querySelector('#trigger');
178
- const outterContent = this.shadowRoot.querySelector('#outter-content');
179
- const innerContent = this.querySelector('#inner-content');
180
- const innerContentParent =
181
- innerContent.parentElement || innerContent.getRootNode();
182
- const placeholder = document.createComment('placeholder for inner content');
183
- innerContentParent.replaceChild(placeholder, innerContent);
184
- outterContent.append(innerContent);
185
- const interaction = 'click';
186
- const options = {
187
- offset: 0,
188
- placement: 'bottom',
189
- };
190
- const closeOverlayPromise = Overlay.open(
191
- trigger,
192
- interaction,
193
- outterContent,
194
- options
195
- );
196
- const closeOverlay = function () {
197
- closeOverlayPromise.then((close) => close());
198
- innerContentParent.replaceChild(innerContent, placeholder);
199
- };
299
+ Here, again, working with your content needs (whether or not you want to leverage `clip-path`) or DOM structure (not colocating clipped and non-clipped content) will allow you to avoid this issue:
300
+
301
+ ```html
302
+ <div class="clip-pathed-demo">
303
+ <sp-action-button id="clip-pathed-working">Trigger</sp-action-button>
304
+ </div>
305
+ <sp-overlay
306
+ trigger="clip-pathed-working@hover"
307
+ type="hint"
308
+ placement="bottom-start"
309
+ >
310
+ <sp-tooltip>I can be blocked when [popover] is not available</sp-tooltip>
311
+ </sp-overlay>
312
+ <style>
313
+ .clip-pathed-demo {
314
+ clip-path: inset(0 0);
315
+ }
316
+ </style>
200
317
  ```