You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/overlay/imperative-api.md
+23-25
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
## Description
1
+
## Overview
2
2
3
3
While an `<sp-overlay>` element is the recommended entry point to the Spectrum Web Components Overlay API, you can also interact with this set of features via an imperative API, `Overlay.open`.
4
4
@@ -7,19 +7,21 @@ While an `<sp-overlay>` element is the recommended entry point to the Spectrum W
7
7
[](https://www.npmjs.com/package/@spectrum-web-components/overlay)
8
8
[](https://bundlephobia.com/result?p=@spectrum-web-components/overlay)
9
9
10
-
```
10
+
```zsh
11
11
yarn add @spectrum-web-components/overlay
12
12
```
13
13
14
14
Import the `Overlay` class to leverage its capabilities within your application or custom element:
Primarily, this class gives you access to the `open` method that will allow you to open an overlay:
21
23
22
-
```js
24
+
```ts
23
25
Overlay.open(
24
26
(overlayElement:HTMLElement), // the element that will be projected into the overlay, "content",
25
27
(options?:OverlayOptions)
@@ -28,7 +30,7 @@ Overlay.open(
28
30
29
31
`Overlay.open()` is an asynchronous method that returns an `<sp-overlay>` element that wraps the `HTMLElement` provided as the `overlayElement`. While this process will set the `<sp-overlay>` element to `open`, consumers of this API will need to choose where to append this element to the DOM in order for the content to be made available in the browser.
Keep in mind that a changing DOM tree is likely to alter the relationship between existing content. Without proper care this can negatively effect the CSS that you have applied to existing content. DOM events and DOM selection methods can also perform differently than expected as the tree shape changes.
46
48
47
-
##OverlayOptions
49
+
### Options
48
50
49
51
When leveraging `Overlay.open()`, you can provide an optional second argument of `OverlayOptions`, with the following type:
50
52
@@ -60,33 +62,39 @@ type OverlayOptions = {
60
62
};
61
63
```
62
64
63
-
### delayed
65
+
####delayed
64
66
65
67
An Overlay that is `delayed` will wait until a warm-up period of 1000ms has completed before opening. Once the warmup period has completed, all subsequent Overlays will open immediately. When no Overlays are opened, a cooldown period of 1000ms will begin. Once the cooldown has completed, the next Overlay to be opened will be subject to the warm-up period if provided that option.
66
68
67
-
### notImmediatelyCloseable
69
+
####notImmediatelyCloseable
68
70
69
71
When an Overlay is `notImmediatelyCloseable` that means that the first interaction that would lead to the closure of the Overlay in question will be ignored. This is useful when working with non-"click" mouse interactions, like `contextmenu`, where the trigger event (e.g. `contextmenu`) occurs _before_ an event that would close said overlay (e.g. `pointerup`).
70
72
71
-
### offset
73
+
####offset
72
74
73
75
The `offset` property accepts either a single number, to define the offset of the Overlay along the main axis from the trigger, or 2-tuple, to define the offset along the main axis and the cross axis. This option has no effect when there is no trigger element.
74
76
75
-
### placement
77
+
####placement
76
78
77
79
A `placement` of `"auto-start" | "auto-end" | "top" | "bottom" | "right" | "left" | "top-start" | "top-end" | "bottom-start" | "bottom-end" | "right-start" | "right-end" | "left-start" | "left-end"` will instruct the Overlay where to place itself in relationship to the trigger element.
78
80
79
-
### receivesFocus
81
+
####receivesFocus
80
82
81
83
Some Overlays will always be passed focus (e.g. modal or page Overlays). When this is not true, the `receivesFocus` option will inform the API whether to attempt to pass focus into the Overlay once it is open. `'true'` will pass focus, `'false'` will not (when possible), and `"auto"` (the default), will make a decision based on the `type` of the Overlay.
82
84
83
-
### trigger
85
+
####trigger
84
86
85
87
The `trigger` option accepts an `HTMLElement` or a `VirtualTrigger` from which to position the Overlay.
86
88
87
89
- You can import the `VirtualTrigger` class from the overlay package to create a virtual trigger that can be used to position an Overlay. This is useful when you want to position an Overlay relative to a point on the screen that is not an element in the DOM, like the mouse cursor.
88
90
89
-
### Using a virtual trigger
91
+
#### Types
92
+
93
+
The `type` of an Overlay outlines a number of things about the interaction model within which it works which are described in the [Overlay Types](https://opensource.adobe.com/spectrum-web-components/components/overlay/#overlay-types).
94
+
95
+
### Advanced Topics
96
+
97
+
#### Using a virtual trigger
90
98
91
99
```html-live
92
100
<style>
@@ -163,11 +171,11 @@ The `trigger` option accepts an `HTMLElement` or a `VirtualTrigger` from which t
@@ -218,13 +226,3 @@ The `trigger` option accepts an `HTMLElement` or a `VirtualTrigger` from which t
218
226
});
219
227
});
220
228
</script>
221
-
222
-
### type
223
-
224
-
The `type` of an Overlay outlines a number of things about the interaction model within which is works.
225
-
226
-
-`'modal'` Overlays create a modal context that traps focus within the content and prevents interaction with the rest of the page. The overlay manages focus trapping and accessibility features like `aria-modal="true"` to ensure proper screen reader behavior.
227
-
-`'page'` Overlays behave similarly to `'modal'` Overlays by creating a modal context and trapping focus, but they will not be allowed to close via the "light dismiss" algorithm (e.g. the Escape key).
228
-
-`'hint'` Overlays are much like tooltips so they are not just ephemeral, but they are delivered primarily as a visual helper and exist outside of the tab order. In this way, be sure _not_ to place interactive content within this type of Overlay.
229
-
-`'auto'` Overlays provide a place for content that is ephemeral _and_ interactive. These Overlays can accept focus but will close when losing that focus, or when interacting with other parts of the page.
230
-
-`'manual'` Overlays act much like `"auto"` Overlays, but do not close when losing focus or interacting with other parts of the page. When a `"manual"` Overlay is at the top of the "overlay stack", it will still respond to the Escape key and close.
Copy file name to clipboardExpand all lines: packages/overlay/overlay-trigger.md
+18-56
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@
17
17
</div>
18
18
</div>
19
19
20
-
## Description
20
+
## Overview
21
21
22
22
An `<overlay-trigger>` element supports the delivery of temporary overlay content based on interaction with a persistent trigger element. An element prepared to receive accessible interactions (e.g. an `<sp-button>`, or `<button>`, etc.) is addressed to `slot="trigger"`, and the content to display (either via `click` or `hover`/`focus` interactions) is addressed to `slot="click-content"` or `slot="hover-content"`, respectively. A trigger element can be linked to the delivery of content, intended for a single interaction, or both. Content addressed to `slot="hover-content"` is made available when the mouse enters or leaves the target element. Keyboard navigation will make this content available when focus enters or leaves the target element. Be thoughtful with what content you address to `slot="hover-content"`, as the content available via "hover" will be transient and non-interactive.
23
23
@@ -27,80 +27,32 @@ An `<overlay-trigger>` element supports the delivery of temporary overlay conten
27
27
[](https://bundlephobia.com/result?p=@spectrum-web-components/overlay)
28
28
[](https://webcomponents.dev/edit/collection/fO75441E1Q5ZlI0e9pgq/bu0sOBIfyW7wnHkXtGzL/src/index.ts)
29
29
30
-
```
30
+
```zsh
31
31
yarn add @spectrum-web-components/overlay
32
32
```
33
33
34
34
Import the side-effectful registration of `<overlay-trigger>` via:
The default of `<overlay-trigger>` will load dependencies in `@spectrum-web-components/overlay` asynchronously via a dynamic import. In the case that you would like to import those tranverse dependencies statically, import the side effectful registration of `<overlay-trigger>` as follows:
When using the `placement` attribute of an `<overlay-trigger>` (`"top" |"top-start" | "top-end" | "bottom" | "bottom-start" | "bottom-end" | "right" | "right-start" | "right-end" | "left" | "left-start" | "left-end"`), you can suggest to the overlay in which direction relative to the trigger that the content should display. When there is adequate room for the content to display in the specified direction, it will do so. When adequate room is not available, the overlaid content will calculate the direction in which it has the most room to be displayed and use that direction.
55
-
56
-
### Type
57
-
58
-
The `type` attribute of an `<overlay-trigger>` element outlines how the element's "click" content should appear in the tab order. `inline` will insert the overlay after the trigger; from here, forward tabbing targets the next logical element, and backward/shift tabbing returns to the target. `replace` will insert the overlay into the page as if it were the trigger; from here, forward tabbing targets the next logical element, and backward/shift tabbing targets the logical element prior to the target. Finally, `modal` will open the content in a tab order fully separate from the original content flow and trap the tab order within that content until the required interaction is complete.
59
-
60
-
## Examples
52
+
### Example
61
53
62
54
Here a default `<overlay-trigger>` manages content that is triggered by click and "hover" interactions.
This example only delivers content via the "click" interaction and leverages both `placement` and `type` attributes to customize the visual relationship of the content to the page and its position in the tab order.
@@ -123,7 +75,17 @@ This example only delivers content via the "click" interaction and leverages bot
123
75
</overlay-trigger>
124
76
```
125
77
126
-
### "Hover" content only
78
+
### Options
79
+
80
+
#### Placement
81
+
82
+
When using the `placement` attribute of an `<overlay-trigger>` (`"top" |"top-start" | "top-end" | "bottom" | "bottom-start" | "bottom-end" | "right" | "right-start" | "right-end" | "left" | "left-start" | "left-end"`), you can suggest to the overlay in which direction relative to the trigger that the content should display. When there is adequate room for the content to display in the specified direction, it will do so. When adequate room is not available, the overlaid content will calculate the direction in which it has the most room to be displayed and use that direction.
83
+
84
+
#### Type
85
+
86
+
The `type` attribute of an `<overlay-trigger>` element outlines how the element's "click" content should appear in the tab order. `inline` will insert the overlay after the trigger; from here, forward tabbing targets the next logical element, and backward/shift tabbing returns to the target. `replace` will insert the overlay into the page as if it were the trigger; from here, forward tabbing targets the next logical element, and backward/shift tabbing targets the logical element prior to the target. Finally, `modal` will open the content in a tab order fully separate from the original content flow and trap the tab order within that content until the required interaction is complete.
87
+
88
+
#### "Hover" content only
127
89
128
90
The delivery of hover content can be customized via the `placement` attribute. However, this content can not be interacted with, so the `type` attribute will not customize its delivery in any way.
129
91
@@ -170,6 +132,6 @@ The `triggered-by` attribute accepts a space-separated string of overlay types:
170
132
171
133
When not specified, the component will automatically detect which content types are present, but this may result in additional rendering cycles. For optimal performance, especially in applications with many overlay triggers, explicitly declaring the content types you plan to use is recommended.
172
134
173
-
## Accessibility
135
+
###Accessibility
174
136
175
137
When using an `<overlay-trigger>` element, it is important to be sure the that content you project into `slot="trigger"` is "interactive". This means that an element within that branch of DOM will be able to receive focus, and said element will appropriately convert keyboard interactions to `click` events, similar to what you'd find with `<a href="#">Anchors</a>`, `<button>Buttons</button>`, etc. You can find further reading on the subject of accessible keyboard interactions at [https://www.w3.org/WAI/WCAG21/Understanding/keyboard](https://www.w3.org/WAI/WCAG21/Understanding/keyboard).
Copy file name to clipboardExpand all lines: packages/overlay/slottable-request.md
+74-10
Original file line number
Diff line number
Diff line change
@@ -1,31 +1,36 @@
1
-
## Description
1
+
## Overview
2
2
3
-
When working with a large amount of content that lives whithin an overlay, a page may encounter performance issues for placing a large amount of content within `<sp-overlay>` or `<overlay-trigger>` elements. To avoid this, an empty `<sp-overlay>`could be used instead. When triggered, the `<sp-overlay>` element will dispatch `slottable-request` just before it begins to open and just after it finished closing. When handling these events the contents of an overlay can be lazily rendered into the `<sp-overlay>` element as it opens and then, as needed, removed from the DOM once the overlay has closed.
3
+
The `slottable-request` event provides a performance optimization mechanism for overlays with large content. Instead of keeping large amounts of content in the DOM at all times, an empty `<sp-overlay>`can be used initially. The overlaywill dispatch `slottable-request`events just before opening and after closing, allowing content to be lazily rendered and removed as needed.
4
4
5
5
### Usage
6
6
7
-
```
7
+
[](https://www.npmjs.com/package/@spectrum-web-components/overlay)
8
+
[](https://bundlephobia.com/result?p=@spectrum-web-components/overlay)
9
+
10
+
```zsh
8
11
yarn add @spectrum-web-components/overlay
9
12
```
10
13
11
-
Import the side effectful registration of `<sp-overlay>`as follows:
14
+
Import the side effectful registration of `<sp-overlay>`via:
When leveraging the `<sp-overlay>` in a javascript only context, you can leverage the `slottable-request`event and its `data` property to decide whether and what to render into the `<sp-overlay>` event.
33
+
Here's a basic example of using `slottable-request`with vanilla JavaScript:
29
34
30
35
```html-live
31
36
<sp-button id="js-trigger">Trigger</sp-button>
@@ -82,4 +87,63 @@ When leveraging the `<sp-overlay>` in a javascript only context, you can leverag
82
87
});
83
88
</script>
84
89
85
-
Starting with no DOM in the `<sp-overlay>` element and returning to that when the Overlay element is no longer showing can support an application in releasing memory back to other activities.
90
+
### Options
91
+
92
+
#### Event Data
93
+
94
+
The `SlottableRequestEvent` includes the following properties:
95
+
96
+
-`data`: Contains either an empty object (when opening) or the `removeSlottableRequest` symbol (when closing)
97
+
-`name`: The name of the request
98
+
-`slotName`: The slot name, optionally with a key appended
99
+
100
+
### Advanced Topics
101
+
102
+
#### Event Timing
103
+
104
+
The `slottable-request` event is dispatched at specific times:
105
+
106
+
1. Just before the overlay begins to open
107
+
2. Just after the overlay finishes closing
108
+
109
+
This timing ensures proper coordination with overlay transitions and animations.
110
+
111
+
#### Memory Management
112
+
113
+
By starting with an empty overlay and removing content when closed, applications can better manage memory usage, especially when dealing with:
114
+
115
+
- Large DOM trees
116
+
- Complex components
117
+
- Multiple overlays
118
+
- Resource-intensive content
119
+
120
+
#### Integration with Lit
121
+
122
+
For Lit-based applications, a directive is available for handling slottable requests:
The <code>slottable-request</code> event system is experimental. Its shape and presence in the library may change. For stable overlay content management, consider using <code>sp-overlay</code> or <code>Overlay.open()</code>.
0 commit comments