1. 4.11 対話的な要素
      1. 4.11.1 details要素
      2. 4.11.2 summary要素
      3. 4.11.3 コマンド
        1. 4.11.3.1 ファセット
        2. 4.11.3.2 Using the a element to define a command
        3. 4.11.3.3 Using the button element to define a command
        4. 4.11.3.4 Using the input element to define a command
        5. 4.11.3.5 Using the option element to define a command
        6. 4.11.3.6 Using the accesskey attribute on a legend element to define a command
        7. 4.11.3.7 Using the accesskey attribute to define a command on other elements
      4. 4.11.4 dialog要素

4.11 対話的な要素

4.11.1 details要素

element.">Element/details

Support in all current engines.

Firefox49+Safari6+Chrome12+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android49+Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

HTMLDetailsElement

Support in all current engines.

Firefox49+Safari6+Chrome10+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android37+Samsung Internet?Opera Android?
カテゴリー
フローコンテンツ
インタラクティブコンテンツ
パルパブルコンテンツ
この要素を使用できるコンテキスト
フローコンテンツが期待される場所。
コンテンツモデル
1つのsummary要素に続くフローコンテンツ
text/htmlにおけるタグ省略
どちらのタグも省略不可。
コンテンツ属性
グローバル属性
name — Name of group of mutually-exclusive details elements
open — detailsが可視かどうか
アクセシビリティの考慮
著者向け
実装者向け
DOMインターフェイス
[Exposed=Window]
interface HTMLDetailsElement : HTMLElement {
  [HTMLConstructor] constructor();

  [CEReactions] attribute DOMString name;
  [CEReactions] attribute boolean open;
};

details要素は、ユーザーが追加情報やコントロールを得ることができるディスクロージャーウィジェットを表す

As with all HTML elements, it is not conforming to use the details element when attempting to represent another type of control. For example, tab widgets and menu widgets are not disclosure widgets, so abusing the details element to implement these patterns is incorrect.

details要素は、脚注には適さない。脚注をマークアップする方法の詳細については、脚注のセクションを参照のこと。

要素の子である最初のsummary要素がもしあれば、detailsの要約または凡例を表す。If there is no child summary element, the user agent should provide its own legend (e.g. "Details").

要素のコンテンツの残り部分は、追加情報やコントロールを表す

The name content attribute gives the name of the group of related details elements that the element is a member of. Opening one member of this group causes other members of the group to close. If the attribute is specified, its value must not be the empty string.

Before using this feature, authors should consider whether this grouping of related details elements into an exclusive accordion is helpful or harmful to to users. While using an exclusive accordion can reduce the maximum amount of space that a set of content can occupy, it can also frustrate users who have to open many items to find what they want or users who want to look at the contents of multiple items at the same time.

A document must not contain more than one details element in the same details name group that has the open attribute present. Authors must not use script to add details elements to a document in a way that would cause a details name group to have more than one details element with the open attribute present.

The group of elements that is created by a common name attribute is exclusive, meaning that at most one of the details elements can be open at once. While this exclusivity is enforced by user agents, the resulting enforcement immediately changes the open attributes in the markup. This requirement on authors forbids such misleading markup.

A document must not contain a details element that is a descendant of another details element in the same details name group.

Documents that use the name attribute to group multiple related details elements should keep those related elements together in a containing element (such as a section element or article element). When it makes sense for the group to be introduced with a heading, authors should put that heading in a heading element at the start of the containing element.

Visually and programmatically grouping related elements together can be important for accessible user experiences. This can help users understand the relationship between such elements. When related elements are in disparate sections of a web page rather than being grouped, the elements' relationships to each other can be less discoverable or understandable.

openコンテンツ属性は、真偽属性である。存在する場合、この属性は要約と追加情報の両方がユーザーに表示されることを示す。属性が存在しない場合、要約のみが表示されるようになる。

When the element is created, if the attribute is absent, the additional information should be hidden; if the attribute is present, that information should be shown. Subsequently, if the attribute is removed, then the information should be hidden; if the attribute is added, the information should be shown.

The user agent should allow the user to request that the additional information be shown or hidden. To honor a request for the details to be shown, the user agent must set the open attribute on the element to the empty string. To honor a request for the information to be hidden, the user agent must remove the open attribute from the element.

This ability to request that additional information be shown or hidden may simply be the activation behavior of the appropriate summary element, in the case such an element exists. However, if no such element exists, user agents can still provide this ability through some other user interface affordance.

The details name group that contains a details element a also contains all the other details elements b that fulfill all of the following conditions:

Every details element has a details toggle task tracker, which is a toggle task tracker or null, initially null.

The following attribute change steps, given element, localName, oldValue, value, and namespace, are used for all details elements:

  1. If namespace is not null, then return.

  2. If localName is name, then ensure details exclusivity by closing the given element if needed given element.

  3. If localName is open, then:

    1. If one of oldValue or value is null and the other is not null, run the following steps, which are known as the details notification task steps, for this details element:

      When the open attribute is toggled several times in succession, the resulting tasks essentially get coalesced so that only one event is fired.

      1. If oldValue is null, queue a details toggle event task given the details element, "closed", and "open".

      2. Otherwise, queue a details toggle event task given the details element, "open", and "closed".

    2. If oldValue is null and value is not null, then ensure details exclusivity by closing other elements if needed given element.

The details HTML element insertion steps, given insertedNode, are:

  1. Ensure details exclusivity by closing the given element if needed given insertedNode.

To be clear, these attribute change and insertion steps also run when an attribute or element is inserted via the parser.

To queue a details toggle event task given a details element element, a string oldState, and a string newState:

  1. If element's details toggle task tracker is not null, then:

    1. Set oldState to element's details toggle task tracker's old state.

    2. Remove element's details toggle task tracker's task from its task queue.

    3. Set element's details toggle task tracker to null.

  2. Queue an element task given the DOM manipulation task source and element to run the following steps:

    1. Fire an event named toggle at element, using ToggleEvent, with the oldState attribute initialized to oldState and the newState attribute initialized to newState.

    2. Set element's details toggle task tracker to null.

  3. Set element's details toggle task tracker to a struct with task set to the just-queued task and old state set to oldState.

To ensure details exclusivity by closing other elements if needed given a details element element:

  1. Assert: element has an open attribute.

  2. If element does not have a name attribute, or its name attribute is the empty string, then return.

  3. Let document be element's node document.

  4. Let oldFlag be the value of document's fire mutation events flag.

  5. Set document's fire mutation events flag to false.

  6. Let groupMembers be a list of elements, containing all elements in element's details name group except for element, in tree order.

  7. For each element otherElement of groupMembers:

    1. If the open attribute is set on otherElement, then:

      1. Assert: otherElement is the only element in groupMembers that has the open attribute set.

      2. Remove the open attribute on otherElement.

      3. Break.

  8. Set document's fire mutation events flag to oldFlag.

To ensure details exclusivity by closing the given element if needed given a details element element:

  1. If element does not have an open attribute, then return.

  2. If element does not have a name attribute, or its name attribute is the empty string, then return.

  3. Let document be element's node document.

  4. Let oldFlag be the value of document's fire mutation events flag.

  5. Set document's fire mutation events flag to false.

  6. Let groupMembers be a list of elements, containing all elements in element's details name group except for element, in tree order.

  7. For each element otherElement of groupMembers:

    1. If the open attribute is set on otherElement, then:

      1. Remove the open attribute on element.

      2. Break.

  8. Set document's fire mutation events flag to oldFlag.

HTMLDetailsElement/open

Support in all current engines.

Firefox49+Safari6+Chrome10+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android37+Samsung Internet?Opera Android?

The name and open IDL attributes must reflect the respective content attributes of the same name.

The ancestor details revealing algorithm is to run the following steps on currentNode:

  1. While currentNode has a parent node within the flat tree:

    1. If currentNode is slotted into the second slot of a details element:

      1. Set currentNode to the details element which currentNode is slotted into.

      2. If the open attribute is not set on currentNode, then set the open attribute on currentNode to the empty string.

    2. Otherwise, set currentNode to the parent node of currentNode within the flat tree.

次の例は、details要素が進捗報告書で技術的な詳細を非表示にするために使用される様子を示す。

<section class="progress window">
 <h1>Copying "Really Achieving Your Childhood Dreams"</h1>
 <details>
  <summary>Copying... <progress max="375505392" value="97543282"></progress> 25%</summary>
  <dl>
   <dt>Transfer rate:</dt> <dd>452KB/s</dd>
   <dt>Local filename:</dt> <dd>/home/rpausch/raycd.m4v</dd>
   <dt>Remote filename:</dt> <dd>/var/www/lectures/raycd.m4v</dd>
   <dt>Duration:</dt> <dd>01:16:27</dd>
   <dt>Color profile:</dt> <dd>SD (6-1-6)</dd>
   <dt>Dimensions:</dt> <dd>320×240</dd>
  </dl>
 </details>
</section>

以下は、details要素がデフォルトで一部のコントロールを非表示にするために使用できる様子を示す:

<details>
 <summary><label for=fn>Name & Extension:</label></summary>
 <p><input type=text id=fn name=fn value="Pillar Magazine.pdf">
 <p><label><input type=checkbox name=ext checked> Hide extension</label>
</details>

これは、ユーザーがそれぞれを開くことができる機能とともに、見出しの小さな集合にフィールドの集合を折りたたむことができるよう、リスト内の他のdetailsとともにこれを使用できる。

これらの例において、要約はコントロールが変更できるものをまとめたものであり、理想に満たない実際値ではない。

The following example shows the name attribute of the details element being used to create an exclusive accordion, a set of details elements where a user action to open one details element causes any open details to close.

<section class="characteristics">
 <details name="frame-characteristics">
  <summary>Material</summary>
  The picture frame is made of solid oak wood.
 </details>
 <details name="frame-characteristics">
  <summary>Size</summary>
  The picture frame fits a photo 40cm tall and 30cm wide.
  The frame is 45cm tall, 35cm wide, and 2cm thick.
 </details>
 <details name="frame-characteristics">
  <summary>Color</summary>
  The picture frame is available in its natural wood
  color, or with black stain.
 </details>
</section>

The following example shows what happens when the open attribute is set on a details element that is part of a set of elements using the name attribute to create an exclusive accordion.

Given the initial markup:

<section class="characteristics">
 <details name="frame-characteristics" id="d1" open>...</details>
 <details name="frame-characteristics" id="d2">...</details>
 <details name="frame-characteristics" id="d3">...</details>
</section>

and the script:

document.getElementById("d2").setAttribute("open", "");

then the resulting tree after the script executes will be equivalent to the markup:

<section class="characteristics">
 <details name="frame-characteristics" id="d1">...</details>
 <details name="frame-characteristics" id="d2" open>...</details>
 <details name="frame-characteristics" id="d3">...</details>
</section>

because setting the open attribute on d2 removes it from d1.

The same happens when the user activates the summary element inside of d2.

ユーザーがコントロールを操作するために自動的にopen属性が追加および削除されるので、この属性の状態に基づく異なる、この属性CSSで要素に使用できる。ここでは、スタイルシートを使用して、要素を開いたり閉じたりしたときのsummaryの色をアニメーションさせている:

<style>
 details > summary { transition: color 1s; color: black; }
 details[open] > summary { color: red; }
</style>
<details>
 <summary>Automated Status: Operational</summary>
 <p>Velocity: 12m/s</p>
 <p>Direction: North</p>
</details>

4.11.2 summary要素

Element/summary

Support in all current engines.

Firefox49+Safari6+Chrome12+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android4+Samsung Internet?Opera Android?
カテゴリー
なし。
この要素を使用できるコンテキスト
details要素の最初の子として。
コンテンツモデル
フレージングコンテンツ、オプションでヘディングコンテンツと混合される。
text/htmlにおけるタグ省略
どちらのタグも省略不可。
コンテンツ属性
グローバル属性
アクセシビリティの考慮
著者向け
実装者向け
DOMインターフェイス
HTMLElementを使用する。

summary要素は、もしあれば、summary要素の親details要素に属する残りの内容のキャプションまたは凡例を表す

A summary element is a summary for its parent details if the following algorithm returns true:

  1. If this summary element has no parent, then return false.

  2. Let parent be this summary element's parent.

  3. If parent is not a details element, then return false.

  4. If parent's first summary element child is not this summary element, then return false.

  5. Return true.

The activation behavior of summary elements is to run the following steps:

  1. If this summary element is not the summary for its parent details, then return.

  2. Let parent be this summary element's parent.

  3. If the open attribute is present on parent, then remove it. Otherwise, set parent's open attribute to the empty string.

    This will then run the details notification task steps.

4.11.3 コマンド

4.11.3.1 ファセット

コマンドは、メニュー項目、ボタン、リンクの背後に抽象化したものである。一度コマンドが定義されると、インターフェイスの他の部分は、Disabled状態のようなファセットを共有するために単一の機能へ多くのアクセスポイントを許可し、同じコマンドを参照できる。

コマンドは、次のファセットを持つように定義される:

ラベル
ユーザーから見たコマンドの名前。
アクセスキー
コマンドを切り替えるユーザーエージェントによって選択されたキーの組み合わせ。コマンドはアクセスキーを持たないかもしれない。
Hidden状態
コマンドが非表示にされたかどうか(基本的に、メニューに表示するかどうか)。
Disabled状態
コマンドが関連するおよび切り替え可能かどうか。
アクション
コマンドを切り替える実際の効果がもつもの。これは、スクリプト化されたイベントハンドラー、どのようにナビゲートするためのURL、またはフォーム送信であるかもしれない。

ユーザーエージェントは、次の条件に一致するコマンドを公開してもよい:

ユーザーエージェントは、ユーザーにこれらのキーを通知するための方法として、アクセスキーを持つコマンドのために特にこれを行うことが推奨される。

たとえば、そのようなコマンドは、ユーザーエージェントのメニューバーにリストされるかもしれない。

4.11.3.2 Using the a element to define a command

An a element with an href attribute defines a command.

The Label of the command is the element's descendant text content.

The Access Key of the command is the element's assigned access key, if any.

The Hidden State of the command is true (hidden) if the element has a hidden attribute, and false otherwise.

The Disabled State facet of the command is true if the element or one of its ancestors is inert, and false otherwise.

The Action of the command is to fire a click event at the element.

4.11.3.3 Using the button element to define a command

A button element always defines a command.

The Label, Access Key, Hidden State, and Action facets of the command are determined as for a elements (see the previous section).

The Disabled State of the command is true if the element or one of its ancestors is inert, or if the element's disabled state is set, and false otherwise.

4.11.3.4 Using the input element to define a command

An input element whose type attribute is in one of the Submit Button, Reset Button, Image Button, Button, Radio Button, or Checkbox states defines a command.

The Label of the command is determined as follows:

Even though the value attribute on input elements in the Image Button state is non-conformant, the attribute can still contribute to the Label determination, if it is present and the Image Button's alt attribute is missing.

The Access Key of the command is the element's assigned access key, if any.

The Hidden State of the command is true (hidden) if the element has a hidden attribute, and false otherwise.

The Disabled State of the command is true if the element or one of its ancestors is inert, or if the element's disabled state is set, and false otherwise.

The Action of the command is to fire a click event at the element.

4.11.3.5 Using the option element to define a command

An option element with an ancestor select element and either no value attribute or a value attribute that is not the empty string defines a command.

The Label of the command is the value of the option element's label attribute, if there is one, or else the option element's descendant text content, with ASCII whitespace stripped and collapsed.

The Access Key of the command is the element's assigned access key, if any.

The Hidden State of the command is true (hidden) if the element has a hidden attribute, and false otherwise.

The Disabled State of the command is true if the element is disabled, or if its nearest ancestor select element is disabled, or if it or one of its ancestors is inert, and false otherwise.

If the option's nearest ancestor select element has a multiple attribute, the Action of the command is to toggle the option element. Otherwise, the Action is to pick the option element.

4.11.3.6 Using the accesskey attribute on a legend element to define a command

A legend element defines a command if all of the following are true:

The Label of the command is the element's descendant text content.

The Access Key of the command is the element's assigned access key.

The Hidden State, Disabled State, and Action facets of the command are the same as the respective facets of the legend element's accesskey delegatee.

In this example, the legend element specifies an accesskey, which, when activated, will delegate to the input element inside the legend element.

<fieldset>
 <legend accesskey=p>
  <label>I want <input name=pizza type=number step=1 value=1 min=0>
   pizza(s) with these toppings</label>
 </legend>
 <label><input name=pizza-cheese type=checkbox checked> Cheese</label>
 <label><input name=pizza-ham type=checkbox checked> Ham</label>
 <label><input name=pizza-pineapple type=checkbox> Pineapple</label>
</fieldset>
4.11.3.7 Using the accesskey attribute to define a command on other elements

An element that has an assigned access key defines a command.

If one of the earlier sections that define elements that define commands define that this element defines a command, then that section applies to this element, and this section does not. Otherwise, this section applies to that element.

The Label of the command depends on the element. If the element is a labeled control, the descendant text content of the first label element in tree order whose labeled control is the element in question is the Label (in JavaScript terms, this is given by element.labels[0].textContent). Otherwise, the Label is the element's descendant text content.

The Access Key of the command is the element's assigned access key.

The Hidden State of the command is true (hidden) if the element has a hidden attribute, and false otherwise.

The Disabled State of the command is true if the element or one of its ancestors is inert, and false otherwise.

The Action of the command is to run the following steps:

  1. Run the focusing steps for the element.
  2. Fire a click event at the element.

4.11.4 dialog要素

Element/dialog

Support in all current engines.

Firefox98+Safari15.4+Chrome37+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

HTMLDialogElement

Support in all current engines.

Firefox98+Safari15.4+Chrome37+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?
カテゴリー
フローコンテンツ
この要素を使用できるコンテキスト
フローコンテンツが期待される場所。
コンテンツモデル
フローコンテンツ
text/htmlにおけるタグ省略
どちらのタグも省略不可。
コンテンツ属性
グローバル属性
open — ダイアログボックスが見えるかどうか
アクセシビリティの考慮
著者向け
実装者向け
DOMインターフェイス
[Exposed=Window]
interface HTMLDialogElement : HTMLElement {
  [HTMLConstructor] constructor();

  [CEReactions] attribute boolean open;
  attribute DOMString returnValue;
  [CEReactions] undefined show();
  [CEReactions] undefined showModal();
  [CEReactions] undefined close(optional DOMString returnValue);
};

dialog要素は、小さいウィンドウ("ダイアログボックス")の形式で、ユーザーはこのウィンドウを操作してタスクを実行したり、情報を収集したりする、アプリケーションの一時的な部分を表す。ユーザーが終了すると、ダイアログはアプリケーションによって自動的に閉じる、またはユーザーによって手動で閉じることができる。

すべてのタイプのアプリケーションでおなじみのパターンである、特にモーダルダイアログの場合、著者は、ウェブアプリケーション内のダイアログが、非ウェブアプリケーションのユーザーにも馴染みのある方法で動作するように保証すべきである。

すべてのHTML要素と同様に、別のタイプのコントロールを表現しようとするときにdialog要素を使用することは適合しない。たとえば、コンテキストメニュー、ツールチップ、ポップアップリストボックスは、ダイアログボックスではないため、これらのパターンを実装するためにdialog要素を乱用することは正しくない。

ユーザー向けダイアログの動作で重要な部分は、初期のフォーカスの配置である。ダイアログフォーカスステップは、ダイアログが表示されたときに初期のフォーカスの適切な候補を選択しようするが、特定のダイアログに対するユーザーの期待に沿う正確な選択を慎重に検討する著者の代わりにはならないかもしれない。そのため、著者は、ダイアログが開いた後にユーザーがすぐに対話することが期待されるダイアログの子孫要素に対して、autofocus属性を使用すべきである。そのような要素がない場合、著者はdialog要素自体にautofocus属性を使用すべきである。

次の例では、在庫管理ウェブアプリケーションで製品の詳細を編集するためにダイアログが使用される。

<dialog>
  <label>Product Number <input type="text" readonly></label>
  <label>Product Name <input type="text" autofocus></label>
</dialog>

autofocus属性が存在しない場合、Product Numberフィールドはダイアログフォーカスステップによってフォーカスされる。これは合理的な動作であるが、Product Numberフィールドは読み取り専用であり、ユーザー入力を想定していないため、Product Nameフィールドにフォーカスを当てる方が適切であると著者は判断した。そこで、著者はデフォルトを上書きするためにオートフォーカスを使用した。

たとえ著者がデフォルトでProduct Numberフィールドにフォーカスしたいとしても、input要素にオートフォーカスを使用して明示的に指定するのが最良である。これは、コードの将来の読者に対して意図を明確にし、将来の更新に対してコードが堅牢であり続けることを保証する。(たとえば、別の開発者が閉じるボタンを追加し、ノードツリーのProduct Numberフィールドの前に配置した場合)。

ユーザー動作のもう1つの重要な側面は、ダイアログがスクロール可能かどうかということである。場合によっては、オーバーフロー(つまりスクロール可能性)は、例えば、ユーザーの高いテキストズーム設定によって引き起こされる場合、回避することができない。しかし一般に、スクロール可能なダイアログはユーザーには期待されない。大きなテキストノードをダイアログ要素に直接追加すると、ダイアログ要素自体がオーバーフローする可能性があるため、特に問題が多い。著者はそれらを避けるのが最善である。

次のサービス条件のダイアログでは、上記の提案を尊重する。

<dialog style="height: 80vh;">
  <div style="overflow: auto; height: 60vh;" autofocus>
    <p>By placing an order via this Web site on the first day of the fourth month of the year
    2010 Anno Domini, you agree to grant Us a non-transferable option to claim, for now and for
    ever more, your immortal soul.</p>
    <p>Should We wish to exercise this option, you agree to surrender your immortal soul,
    and any claim you may have on it, within 5 (five) working days of receiving written
    notification from  this site or one of its duly authorized minions.</p>
    <!-- ... etc., with many more <p> elements ... -->
  </div>
  <form method="dialog">
    <button type="submit" value="agree">Agree</button>
    <button type="submit" value="disagree">Disagree</button>
  </form>
</dialog>

ダイアログフォーカスステップは、デフォルトでスクロール可能なdiv要素が選択されるが、直前の例と同様に、将来の変更に対してより明確で堅牢になるように、autofocusdivに配置した。

対照的に、利用規約を表すp要素にそのようなラッパーdiv要素がない場合、dialog自身がスクロール可能になり、上記のアドバイスに違反する。さらに、autofocus属性が存在しない場合、そのようなマークアップパターンは上記のアドバイスに違反し、ダイアログフォーカスステップのデフォルト動作を中断させ、フォーカスがAgree buttonにジャンプする原因となる。これは、悪いユーザー体験となる。

open属性は、真偽属性である。指定される場合、dialog要素はアクティブであり、ユーザーが操作できることを示す。

open属性が指定されないdialog要素は、ユーザーに表示されるべきでない。この要件は、スタイルレイヤーを通して間接的に実装されてもよい。たとえば、推奨されるデフォルトのレンダリングをサポートするユーザーエージェントは、Renderingセクションで説明されるCSSルールを使用してこの要件を実装する。

open属性を削除すると、通常ダイアログが非表示になる。しかし、そのようにすると、いくつかの奇妙な追加の結果となる:

これらの理由から、open属性を手動で削除しない方が一般的には良い方法である。代わりに、ダイアログを閉じるためにclose()メソッドを使用する、または非表示にするためにhidden属性を使用する。

tabindex属性は、dialog要素で指定されてはならない。

dialog.show()

HTMLDialogElement/show

Support in all current engines.

Firefox98+Safari15.4+Chrome37+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

dialog要素を表示する。

dialog.showModal()

HTMLDialogElement/showModal

Support in all current engines.

Firefox98+Safari15.4+Chrome37+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

dialog要素を表示し、一番上のモーダルダイアログにする。

この方法は、autofocus属性を履行する。

dialog.close([ result ])

HTMLDialogElement/close

Support in all current engines.

Firefox98+Safari15.4+Chrome37+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

dialog要素を閉じる。

引数が与えられた場合、戻り値を提供する。

dialog.returnValue [ = result ]

HTMLDialogElement/returnValue

Support in all current engines.

Firefox98+Safari15.4+Chrome37+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

dialogの戻り値を返す。

戻り値を更新する設定が可能である。

The show() method steps are:

  1. If this has an open attribute and the is modal flag of this is false, then return.

  2. If this has an open attribute, then throw an "InvalidStateError" DOMException.

  3. Add an open attribute to this, whose value is the empty string.

  4. Set this's previously focused element to the focused element.

  5. Let hideUntil be the result of running topmost popover ancestor given this, null, and false.

  6. If hideUntil is null, then set hideUntil to this's node document.

  7. Run hide all popovers until given hideUntil, false, and true.

  8. Run the dialog focusing steps given this.

The showModal() method steps are:

  1. If this has an open attribute and the is modal flag of this is true, then return.

  2. If this has an open attribute, then throw an "InvalidStateError" DOMException.

  3. If this is not connected, then throw an "InvalidStateError" DOMException.

  4. If this is in the popover showing state, then throw an "InvalidStateError" DOMException.

  5. Add an open attribute to this, whose value is the empty string.

  6. Set the is modal flag of this to true.

  7. Let this's node document be blocked by the modal dialog this.

    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.

  8. If this's node document's top layer does not already contain this, then add an element to the top layer given this.

  9. Set this's close watcher to the result of establishing a close watcher given this's relevant global object, with:

  10. Set this's previously focused element to the focused element.

  11. Let hideUntil be the result of running topmost popover ancestor given this, null, and false.

  12. If hideUntil is null, then set hideUntil to this's node document.

  13. Run hide all popovers until given hideUntil, false, and true.

  14. Run the dialog focusing steps given this.

The dialog focusing steps, given a dialog element subject, are as follows:

  1. Let control be null.

  2. If subject has the autofocus attribute, then set control to subject.

  3. If control is null, then set control to the focus delegate of subject.

  4. If control is null, then set control to subject.

  5. 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.

  6. Let topDocument be control's node navigable's top-level traversable's active document.

  7. If control's node document's origin is not the same as the origin of topDocument, then return.

  8. Empty topDocument's autofocus candidates.

  9. Set topDocument's autofocus processed flag to true.

The dialog HTML element removing steps, given removedNode and oldParent, are:

  1. If removedNode's close watcher is not null, then:

    1. Destroy removedNode's close watcher.

    2. Set removedNode's close watcher to null.

  2. If removedNode's node document's top layer contains removedNode, then remove an element from the top layer immediately given removedNode.

The close(returnValue) method steps are:

  1. If returnValue is not given, then set it to null.

  2. Close the dialog this with returnValue.

When a dialog element subject is to be closed, with null or a string result, run these steps:

  1. If subject does not have an open attribute, then return.

  2. Remove subject's open attribute.

  3. If the is modal flag of subject is true, then request an element to be removed from the top layer given subject.

  4. Let wasModal be the value of subject's is modal flag.

  5. Set the is modal flag of subject to false.

  6. If result is not null, then set the returnValue attribute to result.

  7. If subject's previously focused element is not null, then:

    1. Let element be subject's previously focused element.

    2. Set subject's previously focused element to null.

    3. If subject's node document's focused area of the document's DOM anchor is a shadow-including inclusive descendant of element, or wasModal is true, then run the focusing steps for element; the viewport should not be scrolled by doing this step.

  8. Queue an element task on the user interaction task source given the subject element to fire an event named close at subject.

  9. If subject's close watcher is not null, then:

    1. Destroy subject's close watcher.

    2. Set subject's close watcher to null.

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.

次の制約により、表示する/隠す(show/hide)や開く/閉じる(open/close)などの対義語として一般的に考えられている動詞のペアとは対照的に、dialog要素の動詞として表示する/閉じる(show/close)を使用する:

さらに、dialog要素のもとのデザインと同時代の他の多くのUIフレームワークの調査により、表示する/閉じる(show/close)の動詞のペアがかなり一般的であることが明らかになった。

要約すると、特定の動詞の意味、およびそれらの動詞が技術的なコンテキストでどのように使用されるかは、ダイアログの表示と閉じるなどのペアの動作が必ずしも対義語として表現できるとは限らないことがわかる。


Each dialog element has a close watcher, which is a close watcher or null, initially null.

Each dialog element has an is modal flag. When a dialog element is created, this flag must be set to false.

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.


HTMLDialogElement/open

Support in all current engines.

Firefox98+Safari15.4+Chrome37+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

open IDL属性は、openコンテンツ属性を反映しなければならない。

このダイアログボックスは、いくつかの小さなプリントを持つ。strong要素は、より重要な部分にユーザーの注意を引くために使用される。

<dialog>
 <h1>Add to Wallet</h1>
 <p><strong><label for=amt>How many gold coins do you want to add to your wallet?</label></strong></p>
 <p><input id=amt name=amt type=number min=0 step=0.01 value=100></p>
 <p><small>You add coins at your own risk.</small></p>
 <p><label><input name=round type=checkbox> Only add perfectly round coins</label></p>
 <p><input type=button onclick="submit()" value="Add Coins"></p>
</dialog>