+ New! I’m some sort of educational UI…
+ …
+
+```
+
+#### Option C: the `show()` method
+
+Suppose that an author instead wants to show their teaching UI upon some app-internal logic. Such an author could instead call `show()` on the `popup` from script:
```javascript
-document.getElementById('menuButton').addEventListener('click', () => {
- document.getElementById('menuPopup').show()
-})
+if (upsellNewFeature) {
+ document.getElementById('newFeatureUI').show();
+}
```
-Until `show` is called, the `popup` does not display (has a computed value of `none` for its `display` property). Calling `show` places the `popup` into a browser-managed stack of top-layer elements that allow the `popup` to produce a box in accordance with author-supplied styles. Initial styles from the user agent stylesheet consist of:
+#### What happens when a popup is shown
+
+Until the author has used the `popup` attribute, `open` attribute, or `show()` method, the `popup` does not display (has a computed value of `none` for its `display` property). Showing a popup places the `popup` into a browser-managed stack of top-layer elements that allow the `popup` to produce a box in accordance with author-supplied styles. Initial styles from the user agent stylesheet consist of:
```css
popup {
@@ -93,12 +123,20 @@ popup {
}
```
-Only one “top-level” `popup` may be displayed at a time. When a `popup` is shown and placed on the stack, it will remove all `popup`s from the stack until it encounters a `popup` that is an ancestor of the new `popup`'s anchoring element, or the list is empty. In this way, the user agent will ensure that only one `popup` and its child `popup`s are ever displayed at a time—even across uncoordinated code.
+Only one “top-level” `popup` may be displayed at a time. When a `popup` is shown and placed on the stack, it will remove all `popup`s from the stack until it encounters an “ancestral” `popup`, or the list is empty. In this way, the user agent will ensure that only one `popup` and its child `popup`s are ever displayed at a time—even across uncoordinated code.
+
+The following would be considered an “ancestral” `popup`:
+
+* A `popup` ancestor of the new `popup`’s invoking element (based on the `popup` attribute)
+* A `popup` ancestor of the new `popup`’s anchoring element (based on the `anchor` attribute)
+* A `popup` ancestor of the new `popup` itself
Other events also remove a `popup` from the stack, including loss of focus, or hitting `ESC` (often referred to as [light dimiss](#light-dismiss) behaviors). Interactions with other elements like `dialog`, or other future types of popup-like elements, for example, showing a menu, must also remove the `popup`s from the top-layer stack. [Dismissing a `popup`](#dismissing-the-popup) will also remove any child `popup`s from the stack.
`popup`s in the stack are laid out and rendered from the bottom of the stack to the top. Each `popup` will paint atomically as its own stacking context.
+Showing a `popup` via options A (`popup` attribute) or C (calling the `show()`) method will also cause the `open` attribute to be set on the `popup`.
+
### `autofocus` logic
By default, focus remains on the current active element when the `popup` is invoked. If this element is somehow destroyed, focus moves to a focusable ancestral element.
@@ -123,7 +161,7 @@ These `autofocus` rules will be processed each time `show` is called, as opposed
### `delegatesfocus`
-Some authors may need to automatically focus the popup's first focusable descendent, and may not wish to write script to determine at runtime which element that is. In such cases the `delegatesfocus` attribute can be applied to the popup:
+Some authors may need to automatically focus the popup’s first focusable descendent, and may not wish to write script to determine at runtime which element that is. In such cases the `delegatesfocus` attribute can be applied to the popup:
```html