popup attributeAll HTML elements may have the popup content attribute set. When specified, the element won't be
rendered until it becomes shown, at which point it will be rendered on top of other page
content.
The popup attribute is an enumerated attribute.
The following table lists the states for this attribute:
| State | Keywords | Description |
|---|---|---|
| Auto state | auto
| Closes other pop-ups when opened; has light dismiss. |
| The empty string | ||
| Manual state | manual
| Does not close other pop-ups; does not light dismiss. |
The popUp IDL attribute
must reflect the popup attribute, limited to
only known values.
The attribute may be omitted. The invalid value default is the manual state. The missing value default is the no pop-up state.
Every HTML element has a pop-up visibility state, initially , with these potential values:
hidden
transitioning
showing
The pop-up visibility transitioning state and :open pseudo selectors exist to allow pop-ups to animate open or
closed because animating between display: none and other
'display' values is not possible.
The following is an example of an animated pop-up:
<div popup="auto" id="foo">
A fancy pop-up with no Javascript
</div>
<style>
[popup] {
opacity: 0;
transform: translate(-100px,100px);
transition: all 1.5s;
}
[popup]:open {
transform: translate(0,0);
opacity: 1;
}
</style>
The Document has an auto pop-up list, which is a list,
initially empty.
The Document has pop-ups waiting to hide, which is a set,
initially empty.
The Document has a pop-up pointerdown target, which is an HTML element or null, initially null.
Every HTML element has the following members:
A pop-up previously focused element, which is an HTML element or null, initially set to null.
A pop-up invoker, which is an HTML element or null, initially set to null.
Waiting to hide pop-up, which is a boolean, initially set to false.
The following attribute change steps are used for all HTML elements:
If localName is not popup, then
return.
If oldValue is in the no pop-up state, then return.
If value is not in the no pop-up state, then return.
Run the hide pop-up algorithm given element, true, and false.
element.showPopUp()popup attribute is in the auto state, then this will also close all other auto pop-ups unless they are an ancestor of
element according to the nearest open ancestral pop-up algorithm.element.hidePopUp()display: none to it.The showPopUp() method steps
are:
Run show pop-up given this.
To show pop-up, given an HTML element element:
Run check pop-up validity given element.
If the result of firing an event named popupshow at element is false, then return.
Run check pop-up validity given element.
Check pop-up validity is called again because firing the popupshow event could have disconnected this element or changed
its popup attribute.
Let document be element's node document.
Let shouldRestoreFocus be false.
If element's popup attribute is in the auto state, then:
Let ancestor be the result of running the nearest open ancestral
pop-up algorithm given element and "new-pop-up".
Run hide all pop-ups until given ancestor, false, and false.
Run check pop-up validity given element.
Check pop-up validity is called again because running hide all pop-ups until above could have fired the
popuphide event, and an event handler could have
disconnected this element or changed its popup
attribute.
If the result of running topmost auto pop-up on document is null, then set shouldRestoreFocus to true.
This ensures that focus is returned to the previously-focused element only for the first pop-up in a stack.
Add element to document's auto pop-up list.
Set element's waiting to hide pop-up to false.
Set element's pop-up previously focused element to null.
Let originallyFocusedElement be document's focused area of the document's DOM anchor.
Add element to document's top layer.
Set element's pop-up visibility state to transitioning.
Recalculate styles and update layout for document.
Set element's pop-up visibility state to showing.
Run the pop-up focusing steps given element.
If shouldRestoreFocus is true, element's popup attribute is not in the no
pop-up state, and originallyFocusedElement is not the focused
element, then set element's pop-up previously focused element to
originallyFocusedElement.
The hidePopUp() method steps
are:
If this's popup attribute is in the no pop-up state, then throw a
"NotSupportedError" DOMException.
If this's pop-up visibility state is not showing, then throw an
"InvalidStateError" DOMException.
Run the hide pop-up algorithm given this, true, and false.
To hide a pop-up given an HTML element element, a boolean focusPreviousElement, and a boolean hideImmediately:
Let document be element's node document.
If element's popup attribute is in the auto state, then:
Run hide all pop-ups until given element, focusPreviousElement, and hideImmediately.
Run check pop-up validity given element.
Check pop-up validity is called again because running hide all pop-ups until above could have fired the
popuphide event, and an event handler could have
disconnected this element or changed its popup
attribute.
If element's popup attribute is in the auto state, then remove
the last item from document's auto pop-up list.
Add element to document's pop-ups waiting to hide.
Let previousAnimations be the set of all relevant Animation objects that contain at least one
animation effect whose effect target is element.
Set element's pop-up invoker to null.
Set element's pop-up visibility state to transitioning.
If hideImmediately is true, then:
Queue an element task given user interaction task source and
element to fire an event named popuphide at element.
Run pop-up hide finish if needed given element.
Return.
Fire an event named popuphide at element.
Run check pop-up validity given element.
Check pop-up validity is called again because firing the popuphide event could have disconnected this element or changed
its popup attribute.
Let animations be the set of all relevant Animation objects that contain at least one
animation effect whose effect target is element.
Remove all items in animations which exist in previousAnimations.
If animations is empty, then run pop-up hide finish if needed given element.
Let previouslyFocusedElement be element's previously focused element.
If previouslyFocusedElement is not null, then:
Set element's previously focused element to null.
If focusPreviousElement is true, then run the focusing steps for previouslyFocusedElement.
If animations is not empty, then run these steps in parallel:
Set element's waiting to hide pop-up to true.
Wait for each animation in animations to fire either a trusted cancel event or a trusted finish event.
If element's waiting to hide pop-up is true, then run pop-up hide finish if needed given element.
To finish hiding a pop-up if needed, given an HTML element element:
Remove element from element's node document's pop-ups waiting to hide.
Remove element from the top layer.
Set element's pop-up visibility state to .
Set element's waiting to hide pop-up to false.
To hide all pop-ups until, given an HTML element endpoint, a boolean focusPreviousElement, and a boolean hideImmediately:
Let document be endpoint's node document.
If hideImmediately is true, then:
For each elementWaitingToHide in document's pop-ups waiting to hide:
Run pop-up hide finish if needed given elementWaitingToHide.
Clear document's pop-ups waiting to hide.
Let closeAllOpenPopUps be an algorithm which performs the following steps:
Let popUp be document's topmost auto pop-up.
While popUp is not null:
Run the hide pop-up algorithm given popUp, focusPreviousElement, and hideImmediately.
Set popUp to document's topmost auto pop-up.
If endpoint is null, then run closeAllOpenPopUps and return.
Let lastToHide be null.
Let foundEndpoint be false.
For each popUp in document's auto pop-up list:
If popUp is endpoint, then set foundEndpoint to true.
Otherwise, if foundEndpoint is true, then set lastToHide to popUp and break.
If foundEndpoint is false, then run closeAllOpenPopUps and return.
While lastToHide is not null and lastToHide's pop-up visibility state is showing and document's auto pop-up list is not empty:
Run the hide pop-up algorithm given document's auto pop-up list's last element, focusPreviousElement, and hideImmeidately.
The hide all pop-ups until algorithm is used in several cases to hide all pop-ups that don't stay open when something happens. For example, during light-dismiss of a pop-up, this algorithm ensures that we close only the pop-ups that aren't related to the node clicked by the user.
To find the nearest open ancestral pop-up,
given a Node node and a string ancestorType, perform the
following steps. They return an HTML element or null.
Let document be node's node document.
Let anchorsToPopUps be an empty map.
For each popUp in document's auto pop-up list:
Let anchor be the result of getting the pop-up anchor element of popUp.
If anchor is not null, then set anchorsToPopUps[anchor] to popUp.
Let popUpPositions be an empty map.
Let index be 0.
For each popUp in document's auto pop-up list:
Set popUpPositions[popUp] to index.
Increment index by 1.
If ancestorType is "new-pop-up", then:
Set popUpPositions[node] to index.
Let upperBound be 2147483647.
If popUpPositions[node] exists, then set upperBound to popUpPositions[node].
If ancestorType is "inclusive", then:
Let currentNode be node.
While currentNode has a parent node within the flat tree:
If currentNode's popup attribute is not in
the no pop-up state and currentNode's
pop-up visibility state is showing
and currentNode's popup attribute is not in the
manual state, then:
If popUpPositions[currentNode] + 1 is greater than upperBound, then set upperBound to popUpPositions[currentNode] + 1.
Let targetPopUp be currentNode's pop-up target element.
If targetPopUp's popup attribute is not
null and targetPopUp's pop-up visibility state is showing and targetPopUp's popup attribute is not in the manual state, then:
If popUpPositions[targetPopUp] + 1 is greater than upperBound, then set upperBound to popUpPositions[targetPopUp] + 1.
Set currentNode to the parent node of currentNode within the flat tree.
Let seen be an empty set.
Return the result of finding the nearest open ancestral pop-up recursively given node, popUpPositions, anchorsToPopUps, upperBound, and seen.
To find the nearest open ancestral pop-up
recursively, given a Node node, a map
popUpPositions, a map anchorsToPopUps, an integer upperBound, and
a set seen, perform the following steps. They return an HTML element or null.
If node is null, then return null.
If seen contains node, then return null.
Add node to seen.
Let ancestor be null.
Let position be −1.
Let update be an algorithm which performs the following steps given popUp:
If popUp is not null and popUp's pop-up visibility state
is not showing and popUp's popup attribute is not in the manual state, then:
Let newPosition be popUpPositions[popUp].
If newPosition is greater than position and newPosition is less than upperBound, then:
Set ancestor to popUp.
Set position to newPosition.
Let recurseAndUpdate be an algorithm which performs the following steps given node:
Let nearestOpenAncestor be the result of finding the nearest open ancestral pop-up recursively given node, popUpPositions, anchorsToPopUps, upperBound, and seen.
Run update given nearestOpenAncestor.
Run update given node.
If popUpPositions[node] exists, then:
Run recurseAndUpdate given node's pop-up anchor element.
Run recurseAndUpdate given node's pop-up invoker.
If node has a pop-up target element, then run recurseAndUpdate given node's pop-up target element.
If anchorsToPopUps[node] exists, then run recurseAndUpdate given anchorsToPopUps[node].
Run recurseAndUpdate given node's parent node in the flat tree.
Return ancestor.
To get the pop-up anchor element of an HTML element element, perform the following steps. They return an HTML element or null.
If element's popup attribute is in the no pop-up state, then return null.
Let anchorAttribute be the result of running get an attribute by
name given element and anchor.
If anchorAttribute is null, then return null.
Return the first HTML element in tree order, within element's root's descendants, whose ID is anchorAttribute; otherwise, if there is no such element, null.
To find the topmost auto pop-up given a
Document document, perform the following steps. They return an HTML element or null.
If document's auto pop-up list is not empty, then return document's auto pop-up list's last element.
Return null.
To perform the pop-up focusing steps for an HTML element subject:
Let control be the focus delegate of subject.
If control is null, then return.
Run the focusing steps given control.
Let topDocument be the active document of control's node document's browsing context's top-level browsing context.
If control's node document's origin is not the same as the origin of topDocument, then return.
Empty topDocument's autofocus candidates.
Set topDocument's autofocus processed flag to true.
To check pop-up validity for an HTML element element:
If element's popup attribute is in the no pop-up state, then throw an
"InvalidStateError" DOMException.
If element's pop-up visibility state is not , then throw an
"InvalidStateError" DOMException.
If element is not connected, then throw an
"InvalidStateError" DOMException.
Supported elements may have the following content attributes, known as the pop-up target attributes:
popuptoggletarget
popuphidetarget
popupshowtarget
The pop-up target attributes allow certain types of buttons to show and hide
element with the popup attribute. If a pop-up target attribute is
specified, then that attribute's value must be the ID of element with the popup attribute.
The following shows how popupshowtarget can be
used to open a pop-up:
<div popup=auto id="foo">
This is a pop-up!
</div>
<button popupshowtarget="foo">
Show a pop-up
</button>
The following shows how popuptoggletarget can
open and close a manual pop-up, which can't be closed with light dismiss:
<div popup=manual id="foo">
This is a pop-up!
</div>
<button popuptoggletarget="foo">
Show or hide a pop-up
</button>
The pop-up target attributes are only supported on the following elements:
button elements
input elements in the Submit
Button state.
input elements in the Image
Button state.
input elements in the Reset
Button state.
interface mixin PopUpTargetElement {
[CEReactions] attribute DOMString? popUpToggleTarget;
[CEReactions] attribute DOMString? popUpHideTarget;
[CEReactions] attribute DOMString? popUpShowTarget;
};
The popUpToggleTarget IDL attribute must
reflect the popuptoggletarget
attribute.
The popUpHideTarget IDL attribute must reflect
the popuphidetarget attribute.
The popUpShowTarget IDL attribute must reflect
the popupshowtarget attribute.
To run the pop-up target attribute activation behavior given a Node
node:
If node is disabled, then return.
If node is not supported by the pop-up target attributes, then return.
Let popUp be node's pop-up target element.
If popUp is null, then return.
If node doesn't have the popuptoggletarget attribute, then:
If node has the popupshowtarget
attribute and popUp's pop-up visibility state is showing, then return.
If node has the popuphidetarget
attribute and popUp's pop-up visibility state is , then return.
If node doesn't have the popupshowtarget attribute and node doesn't
have the popuphidetarget attribute, then
return.
If node has a form owner and node is in any of the following states, then return:
node is a button element in the submit state.
node is an input element in the submit state.
node is an input element in the image state.
If popUp's pop-up visibility state is showing, then run the hide pop-up algorithm given popUp, true, and false.
Otherwise:
Set popUp's pop-up invoker to node.
Run show pop-up given popUp.
To get the pop-up target element given a Node node, perform
the following steps. They return an HTML element or null.
If node is not supported, then return null.
Let idref be null.
If node has the popuptoggletarget attribute, then set idref
to the value of node's popuptoggletarget attribute.
Otherwise, if node has the popupshowtarget attribute, then set idref to
the value of node's popupshowtarget
attribute.
Otherwise, if node has the popuphidetarget attribute, then set idref to
the value of node's popuphidetarget
attribute.
If idref is null, then return null.
Let popupElement be the first HTML element in tree order, within node's root's descendants, whose ID is idref; otherwise, if there is no such HTML element, null.
If popupElement is null, then return null.
If popupElement's popup attribute is in the
no pop-up state, then return null.
Return popupElement.
"Light dismiss" means that pressing the Esc key or clicking outside of a pop-up
whose popup attribute is in the auto state will close the pop-up.
To light dismiss open pop-ups, given an Event event and a
Node node:
If node is not a Document, then return.
Let topmostPopup be the result of running topmost auto pop-up given node.
If topmostPopup is null, then return.
Let target be event's target.
If event is a pointerdown event, then:
Set node's pop-up pointerdown target to the result of running
nearest open ancestral pop-up given target and "inclusive".
If event is a pointerup event, then:
Let ancestor be the result of running nearest open ancestral
pop-up given target and "inclusive".
Let sameTarget be true if ancestor is node's pop-up pointerdown target.
Set node's pop-up pointerdown target to null.
If sameTarget is true, then run hide all pop-ups until given ancestor, false, false, and true.
If event is a keydown event for the
Escape key, then:
Run the hide pop-up algorithm given topmostPopup, true, and false.
defaultopen attributeAll HTML elements may have the defaultopen content attribute set. When specified on an
element whose popup attribute is not in the no pop-up state, it makes the element shown automatically
when the page is loaded. defaultopen is a boolean
attribute.
The defaultOpen
IDL attribute must reflect the defaultopen
content attribute.
anchor attributeAll HTML elements may have the anchor attribute set. When specified on an element whose popup attribute is not in the no
pop-up state, the value of the attribute is used as an ID to refer to another element. The
other element is considered to be a parent in the pop-up hierarchy. This means, for example, that
if the element and parent element's popup attributes are in the
auto state, then both of them can be open at the same
time even though only one auto pop-up is supposed to
be open at a time.