GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||
GeezerVison is showing html.spec.whatwg.org — HTML Standard
4.11 Interactive elements4.11.1 The |
| Keyword | State | Brief description |
|---|---|---|
any
| Any | Close requests or clicks outside close the dialog. |
closerequest
| Close Request | Close requests close the dialog. |
none
| None | No user actions automatically close the dialog. |
The closedby attribute's invalid value default and missing value
default are both the Auto state.
The Auto state behaves as
Close Request state when the
dialog was shown using its showModal()
method; otherwise the None state.
A dialog element without an open attribute
specified should not be shown to the user. This requirement may be implemented indirectly through
the style layer. For example, user agents that support the suggested
default rendering implement this requirement using the CSS rules described in the Rendering section.
Removing the open attribute will usually hide the
dialog. However, doing so has a number of strange additional consequences:
The close event will not be fired.
The close() method, and any close requests, will no longer be able to close the dialog.
If the dialog was shown using its showModal()
method, the Document will still be blocked.
For these reasons, it is generally better to never remove the open attribute manually. Instead, use the requestClose() or close() methods to close the dialog, or the hidden attribute to hide it.
The tabindex attribute must not be specified on
dialog elements.
dialog.show()Support in all current engines.
Displays the dialog element.
dialog.showModal()Support in all current engines.
Displays the dialog element and makes it the top-most modal dialog.
This method honors the autofocus attribute.
dialog.close([ result ])Support in all current engines.
Closes the dialog element.
The argument, if provided, provides a return value.
dialog.requestClose([ result ])Acts as if a close request was sent targeting
dialog, by first firing a cancel event, and if
that event is not canceled with preventDefault(),
proceeding to close the dialog in the same way as the close() method (including firing a close event).
This is a helper utility that can be used to consolidate cancelation and closing logic into
the cancel and close event
handlers, by having all non-close request closing
affordances call this method.
Note that this method ignores the closedby
attribute: that is, even if closedby is set to
"none", the same behavior will apply.
The argument, if provided, provides a return value.
dialog.returnValue [ = result ]Support in all current engines.
Returns the dialog's return value.
Can be set, to update the return value.
The show()
method steps are:
If this has an open attribute and
is modal of this is false, then return.
If this has an open attribute, then
throw an "InvalidStateError" DOMException.
If the result of firing an event named beforetoggle, using ToggleEvent, with the cancelable attribute initialized to true, the oldState attribute initialized to "closed", and the newState
attribute initialized to "open" at this is false, then
return.
Queue a dialog toggle event task given this, "closed", "open", and null.
Add an open attribute to this, whose
value is the empty string.
Set this's previously focused element to the focused element.
Let document be this's node document.
Let hideUntil be the result of running topmost popover ancestor given this, null, and false.
Run hide popovers until given document, hideUntil, false, and true.
Run the dialog focusing steps given this.
The showModal() method steps are to show a modal
dialog given this and null.
The close(returnValue) method steps are:
If returnValue is not given, then set it to null.
Close the dialog this with returnValue and null.
The requestClose(returnValue) method steps
are:
If returnValue is not given, then set it to null.
Request to close the dialog this with returnValue and null.
We use show/close as the verbs for dialog elements, as opposed to verb pairs that
are more commonly thought of as antonyms such as show/hide or open/close, due to the following
constraints:
Hiding a dialog is different from closing one. Closing a dialog gives it a return value,
fires an event, unblocks the page for other dialogs, and so on. Whereas hiding a dialog is a
purely visual property, and is something you can already do with the hidden attribute or by removing the open attribute. (See also the note above about removing the open attribute, and how hiding the dialog in that way is
generally not desired.)
Showing a dialog is different from opening one. Opening a dialog consists of creating
and showing that dialog (similar to how window.open() both
creates and shows a new window). Whereas showing the dialog is the process of taking a
dialog element that is already in the DOM, and making it interactive and visible
to the user.
If we were to have a dialog.open() method despite the above, it
would conflict with the dialog.open property.
Furthermore, a survey
of many other UI frameworks contemporary to the original design of the dialog
element made it clear that the show/close verb pair was reasonably common.
In summary, it turns out that the implications of certain verbs, and how they are used in technology contexts, mean that paired actions such as showing and closing a dialog are not always expressible as antonyms.
The returnValue IDL attribute, on getting, must return
the last value to which it was set. On setting, it must be set to the new value. When the element
is created, it must be set to the empty string.
The closedBy getter steps are to return the keyword
corresponding to the computed closed-by state given this.
Each Document has a dialog pointerdown target, which is an HTML dialog element or null, initially null.
Each HTML element has a previously focused
element which is null or an element, and it is initially null. When showModal() and show()
are called, this element is set to the currently focused element before running the
dialog focusing steps. Elements with the popover
attribute set this element to the currently focused element during the show popover algorithm.
Each dialog element has a dialog toggle task tracker, which is a
toggle task tracker or null, initially null.
Each dialog element has a close watcher,
which is a close watcher or null, initially null.
Each dialog element has a request close return value, which is a
string or null, initially null.
Each dialog element has a request close source element, which is an
Element or null, initially null.
Each dialog element has an enable close watcher for request close boolean,
initially false.
dialog's enable close watcher for request close is used
to force enable the dialog's close watcher while requesting to close it. A dialog whose computed
closed-by state is the None state
would otherwise have a disabled close watcher.
Each dialog element has an is modal boolean, initially false.
The dialog HTML element insertion steps, given
insertedNode, are:
If insertedNode's node document is not fully active, then return.
If insertedNode has an open attribute
and is connected, then run the dialog setup steps given
insertedNode.
The dialog HTML element removing steps, given
removedNode, isSubtreeRoot, and oldAncestor are:
If removedNode has an open attribute,
then run the dialog cleanup steps given removedNode.
If removedNode's node document's top layer contains removedNode, then remove an element from the top layer immediately given removedNode.
Set is modal of removedNode to false.
The following attribute change
steps, given element, localName, oldValue,
value, and namespace are used for dialog elements:
If namespace is not null, then return.
If localName is not open, then
return.
If value is null and oldValue is not null, then run the dialog cleanup steps given element.
If element's node document is not fully active, then return.
If element is not connected, then return.
This ensures that the dialog setup steps are not run on nodes that are disconnected, which would result in a close watcher being established. The dialog cleanup steps need no such guard.
If value is not null and oldValue is null, then run the dialog setup steps given element.
To show a modal dialog given a dialog element subject and an
Element or null source:
If subject has an open attribute and
is modal of subject is true, then return.
If subject has an open attribute, then
throw an "InvalidStateError" DOMException.
If subject's node document is not fully active, then
throw an "InvalidStateError" DOMException.
If subject is not connected, then throw an
"InvalidStateError" DOMException.
If subject is in the popover showing
state, then throw an "InvalidStateError"
DOMException.
If the result of firing an event named beforetoggle, using ToggleEvent, with the cancelable attribute initialized to true, the oldState attribute initialized to "closed", the newState
attribute initialized to "open", and the source attribute initialized to source at
subject is false, then return.
If subject has an open attribute,
then return.
If subject is not connected, then return.
If subject is in the popover showing state, then return.
Queue a dialog toggle event task given subject, "closed", "open", and source.
Add an open attribute to subject, whose
value is the empty string.
Assert: subject's close watcher is not null.
Set is modal of subject to true.
Set subject's node document to be blocked by the modal dialog subject.
This will cause the focused area of the document to become inert (unless that currently focused area is a shadow-including descendant of subject). In such cases, the focused area of the document will soon be reset to the viewport. In a couple steps we will attempt to find a better candidate to focus.
If subject's node document's top layer does not already contain subject, then add an element to the top layer given subject.
Set subject's previously focused element to the focused element.
Let document be subject's node document.
Let hideUntil be the result of running topmost popover ancestor given subject, null, and false.
Run hide popovers until given document, hideUntil, false, and true.
Run the dialog focusing steps given subject.
To set the dialog close watcher, given a dialog
element dialog:
Assert: dialog's close watcher is null.
Assert: dialog has an open
attribute and dialog's node document is fully active.
Set dialog's close watcher to the result of establishing a close watcher given dialog's relevant global object, with:
cancelAction given
canPreventClose being to return the result of firing an event named cancel at dialog, with the cancelable attribute initialized to
canPreventClose.
closeAction being to close the dialog given dialog, dialog's request close return value, and dialog's request close source element.
getEnabledState being to return true if dialog's enable close watcher for request close is true or dialog's computed closed-by state is not None; otherwise false.
The is valid command steps for dialog elements, given a command attribute command, are:
If command is in the Close state, the Request Close state, or the Show Modal state, then return true.
Return false.
The command steps for dialog elements, given an element
element, an element source, and a command attribute command, are:
If element is in the popover showing state, then return.
If command is in the Close state and element has an open attribute, then close the dialog
element with source's optional
value and source.
If command is in the Request Close state and
element has an open attribute, then request to close the dialog element with
source's optional value and
source.
If command is the Show Modal state and element does
not have an open attribute, then
show a modal dialog given element and source.
The following buttons use commandfor to open and
close a "confirm" dialog as modal when activated:
< button type = button
commandfor = "the-dialog"
command = "show-modal" >
Delete
</ button >
< dialog id = "the-dialog" >
< form action = "/delete" method = "POST" >
< button type = "submit" >
Delete
</ button >
< button commandfor = "the-dialog"
command = "close" >
Cancel
</ button >
</ form >
</ dialog >
When a dialog element subject is to be closed, with null or a string result and an Element or null
source, run these steps:
If subject does not have an open
attribute, then return.
Fire an event named beforetoggle, using ToggleEvent, with the oldState attribute initialized to "open", the newState attribute
initialized to "closed", and the source attribute initialized to source at
subject.
If subject does not have an open
attribute, then return.
Queue a dialog toggle event task given subject, "open", "closed", and source.
Remove subject's open
attribute.
If is modal of subject is true, then request an element to be removed from the top layer given subject.
Let wasModal be the value of subject's is modal flag.
Set is modal of subject to false.
If result is not null, then set subject's returnValue attribute to result.
Set subject's request close return value to null.
Set subject's request close source element to null.
If subject's previously focused element is not null:
Let element be subject's previously focused element.
Set subject's previously focused element to null.
If subject's node document's focused area of the document's DOM anchor is a shadow-including inclusive descendant of subject, or wasModal is true, then run the focusing steps for element; the viewport should not be scrolled by doing this step.
Queue an element task on the user interaction task source given the
subject element to fire an event named
close at subject.
To request to close dialog element
subject, given null or a string returnValue and null or an
Element source:
If subject does not have an open
attribute, then return.
If subject is not connected or subject's node document is not fully active, then return.
Assert: subject's close watcher is not null.
Set subject's enable close watcher for request close to true.
Set subject's request close return value to returnValue.
Set subject's request close source element to source.
Request to close subject's close watcher with false.
Set subject's enable close watcher for request close to false.
To queue a dialog toggle event task given a dialog element
element, a string oldState, a string newState, and an
Element or null source:
If element's dialog toggle task tracker is not null:
Set oldState to element's dialog toggle task tracker's old state.
Remove element's dialog toggle task tracker's task from its task queue.
Set element's dialog toggle task tracker to null.
Queue an element task given the DOM manipulation task source and element to run the following steps:
Fire an event named toggle at element, using ToggleEvent, with
the oldState attribute initialized to
oldState, the newState attribute
initialized to newState, and the source attribute initialized to
source.
Set element's dialog toggle task tracker to null.
Set element's dialog toggle task tracker to a struct with task set to the just-queued task and old state set to oldState.
To retrieve a dialog's computed closed-by state, given a dialog
dialog:
The dialog focusing steps, given a dialog element subject,
are as follows:
If the allow focus steps given subject's node document return false, then return.
Let control be null.
If subject has the autofocus
attribute, then set control to subject.
If control is null, then set control to the focus delegate of subject.
If control is null, then set control to subject.
Run the focusing steps for control.
If control is not focusable, this will do nothing. This
would only happen if subject had no focus delegate, and the user agent decided that
dialog elements were not generally focusable. In that case, any earlier modifications to the focused area of the
document will apply.
Let topDocument be control's node navigable's top-level traversable's active document.
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.
The dialog setup steps, given a dialog element subject, are
as follows:
Assert: subject's node document's open dialogs list does not contain subject.
Add subject to subject's node document's open dialogs list.
Set the dialog close watcher with subject.
The dialog cleanup steps, given a dialog element subject,
are as follows:
Remove subject from subject's node document's open dialogs list.
If subject's close watcher is not null:
Destroy subject's close watcher.
Set subject's close watcher to null.
"Light dismiss" means that clicking outside of a dialog element whose closedby attribute is in the Any state will close the dialog element. This
is in addition to how such dialogs respond to close requests.
To light dismiss open dialogs, given a PointerEvent event:
Let document be event's target's node document.
If document's open dialogs list is empty, then return.
Let ancestor be the result of running nearest clicked dialog given event.
If event's type is
"pointerdown", then set document's
dialog pointerdown target to ancestor.
If event's type is
"pointerup":
Let sameTarget be true if ancestor is document's dialog pointerdown target.
Set document's dialog pointerdown target to null.
If sameTarget is false, then return.
Let topmostDialog be the last element of document's open dialogs list.
If ancestor is topmostDialog, then return.
If topmostDialog's computed closed-by state is not Any, then return.
Assert: topmostDialog's close watcher is not null.
Request to close topmostDialog's close watcher with false.
To run light dismiss activities, given a PointerEvent
event:
Run light dismiss open popovers with event.
Run light dismiss open dialogs with event.
Run light dismiss activities will be called by the Pointer Events spec when the user clicks or touches anywhere on the page.
To find the nearest clicked dialog, given a PointerEvent
event:
Let target be event's target.
If target is a dialog element, target has an open attribute, target's is modal is
true, and event's clientX and
clientY are outside the bounds of target,
then return null.
The check for clientX and clientY is because a pointer event that hits the ::backdrop pseudo element of a dialog will result in event having a
target of the dialog element itself.
Let currentNode be target.
While currentNode is not null:
Return null.