Edition for Web Developers — Last Updated 31 January 2025
details
要素Support in all current engines.
summary
要素に続くフローコンテンツ。name
— 相互に排他的なdetails
要素のグループの名前open
— detailsが可視かどうかHTMLDetailsElement
を使用する。details
要素は、ユーザーが追加情報やコントロールを得ることができるディスクロージャーウィジェットを表す。
すべてのHTML要素と同様に、別のタイプのコントロールを表現しようとするときにdetails
要素を使用することは適合しない。例えば、タブウィジェットとメニューウィジェットはディスクロージャーウィジェットではないため、details
要素を乱用してこれらのパターンを実装するのは誤りである。
details
要素は、脚注には適さない。脚注をマークアップする方法の詳細については、脚注のセクションを参照のこと。
要素の子summary
要素がもしあれば、detailsの要約または凡例を表す。
要素のコンテンツの残り部分は、追加情報やコントロールを表す。
name
コンテンツ属性は、要素がメンバーである関連する details
要素のグループの名前を与える。このグループの1つのメンバーを開くと、グループの他のメンバーは閉じる。この属性が指定される場合、その値は空文字列であってはならない。
この機能を使用する前に、著者は、関連するdetails
要素を排他的なアコーディオンにグループ化することが、ユーザーにとって有用であるか有害であるかを考慮すべきである。排他的なアコーディオンを使用すると、コンテンツのセットが占有できるスペースの最大量を減らすことができるが、必要なものを見つけるために多くのアイテムを開かなければならないユーザー、または同時に複数のアイテムのコンテンツを見たいユーザーをイライラさせることもある。
文書には、open
属性が存在する同じdetails name group内に複数のdetails
要素を含めてはならない。著者は、open
属性をもつ複数のdetails
要素をdetails name groupに持たせるような方法で、スクリプトを使用して details
要素を文書に追加してはならない。
共通のname
属性によって作成される要素のグループは排他的である。つまり、多くとも一度に開くことができるdetails
要素は1つのだけである。この排他性はユーザーエージェントによって強制されるが、その結果、マークアップ内のopen
属性が即座に変更される。著者に対するこの要件は、そのような誤解を招くようなマークアップを禁止している。
文書には、同じdetails name group内の別のdetails
要素の子孫であるdetails
要素を含めてはならない。
name
を使用して、複数の関連するdetails
要素をグループ化する文書では、それらの関連する要素を包含要素(section
要素、article
要素など)にまとめるべきである。グループを見出しで導入することに意味がある場合、著者はその見出しを見出し要素内の包含要素の先頭に配置すべきである。
関連する要素を視覚的およびプログラム的にグループ化することは、アクセシブルなユーザーエクスペリエンスにとって重要である。これは、ユーザーがそのような要素間の関係を理解するのに役立つ。関連する要素がグループ化されるのではなく、ウェブページの異なるセクションにある場合、要素間の関係が発見しにくくなったり、理解しにくくなったりすることがある。
open
コンテンツ属性は、真偽属性である。存在する場合、この属性は要約と追加情報の両方がユーザーに表示されることを示す。属性が存在しない場合、要約のみが表示されるようになる。
The ancestor details revealing algorithm is to run the following steps on currentNode:
While currentNode has a parent node 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
とともにこれを使用できる。
これらの例において、要約はコントロールが変更できるものをまとめたものであり、理想に満たない実際値ではない。
次の例は、排他的なアコーディオンの作成に使用されているdetails
要素のname
属性を示す。このアコーディオンは、ユーザーが1つのdetails
要素を開くと、開いているdetails
が閉じるdetails
要素のセットである。
< 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 >
次の例は、要素セットの一部であるdetails
要素にopen
属性を設定し、name
属性を使用して排他的アコーディオンを作成した場合の結果を示している。
最初のマークアップの場合:
< 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 >
スクリプト:
document. getElementById( "d2" ). setAttribute( "open" , "" );
スクリプトの実行後に生成されるツリーは、マークアップと同じになる:
< 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 >
なぜなら、open
属性をd2
に設定すると、d1
から削除されるからである。
ユーザーがd2
内のsummary
要素をアクティブにした場合も同様である。
ユーザーがコントロールを操作するために自動的にopen
属性が追加および削除されるので、この属性の状態に基づく異なる、この属性CSSで要素に使用できる。ここでは、スタイルシートを使用して、要素を開いたり閉じたりしたときのsummaryの色をアニメーションさせている:
< style >
details > summary { transition : color 1 s ; color : black ; }
details [ open ] > summary { color : red ; }
</ style >
< details >
< summary > Automated Status: Operational</ summary >
< p > Velocity: 12m/s</ p >
< p > Direction: North</ p >
</ details >
summary
要素Support in all current engines.
details
要素の最初の子として。HTMLElement
を使用する。summary
要素はsummary
要素の親details
要素に属する残りの内容のキャプションまたは凡例を表す。
コマンドは、メニュー項目、ボタン、リンクの背後に抽象化したものである。一度コマンドが定義されると、インターフェイスの他の部分は、Disabled状態のようなファセットを共有するために単一の機能へ多くのアクセスポイントを許可し、同じコマンドを参照できる。
コマンドは、次のファセットを持つように定義される:
ユーザーエージェントは、次の条件に一致するコマンドを公開してもよい:
のファセットはfalseである(可視)。
要素は、nullでないブラウジングコンテキストをもつ文書内である。
要素もその祖先のいずれも指定された
属性を持たない。ユーザーエージェントは、ユーザーにこれらのキーを通知するための方法として、アクセスキーを持つコマンドのために特にこれを行うことが推奨される。
たとえば、そのようなコマンドは、ユーザーエージェントのメニューバーにリストされるかもしれない。
dialog
要素Support in all current engines.
closedby
— Which user actions will close the dialogopen
— ダイアログボックスが見えるかどうかHTMLDialogElement
を使用する。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
要素が選択されるが、直前の例と同様に、将来の変更に対してより明確で堅牢になるように、autofocus
をdiv
に配置した。
対照的に、利用規約を表すp
要素にそのようなラッパーdiv
要素がない場合、dialog
自身がスクロール可能になり、上記のアドバイスに違反する。さらに、autofocus
属性が存在しない場合、そのようなマークアップパターンは上記のアドバイスに違反し、ダイアログフォーカスステップのデフォルト動作を中断させ、フォーカスがAgree button
にジャンプする原因となる。これは、悪いユーザー体験となる。
このダイアログボックスは、いくつかの小さなプリントを持つ。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 >
open
属性は、真偽属性である。指定される場合、dialog
要素はアクティブであり、ユーザーが操作できることを示す。
The closedby
content attribute is an enumerated attribute with the following keywords and states:
キーワード | 状態 | 概要 |
---|---|---|
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.
open
属性を削除すると、通常ダイアログが非表示になる。しかし、そのようにすると、いくつかの奇妙な追加の結果となる:
close
イベントは発火しない。
showModal()
メソッドを使用してダイアログが表示された場合、Document
はブロックされる。
これらの理由から、open
属性を手動で削除しない方が一般的には良い方法である。代わりに、ダイアログを閉じるためにclose()
メソッドを使用する、または非表示にするために 属性を使用する。
tabindex
属性は、dialog
要素で指定されてはならない。
dialog.show()
dialog
要素を表示する。
dialog.showModal()
dialog
要素を表示し、一番上のモーダルダイアログにする。
この方法は、autofocus
属性を履行する。
dialog.close([ result ])
dialog
要素を閉じる。
引数が与えられた場合、戻り値を提供する。
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).
これは、キャンセルおよびクローズロジックをcancel
およびclose
イベントハンドラーに統合するために使用できるヘルパーユーティリティであり、非close requestのすべてのクローズアフォーダンスでこのメソッドを呼び出すことができる。
Note that this method ignores the closedby
attribute: that is, even if closedby
is set to "none
", the same behavior will apply.
引数が与えられた場合、戻り値を提供する。
dialog.returnValue [ = result ]
dialog
の戻り値を返す。
戻り値を更新する設定が可能である。
次の制約により、表示する/隠す(show/hide)や開く/閉じる(open/close)などの対義語として一般的に考えられている動詞のペアとは対照的に、dialog
要素の動詞として表示する/閉じる(show/close)を使用する:
ダイアログを非表示にすることは、ダイアログを閉じることとは異なる。ダイアログを閉じると、戻り値が返され、イベントが発火し、他のダイアログのページのブロックが解除される、などする。ダイアログを非表示にすることは純粋に視覚的なプロパティであり、open
属性を削除することですでに実行できることである。(open
属性を削除すること、およびそのようにダイアログを非表示にすることは一般的に望ましくないことについては、上記の注も参照。)
ダイアログを表示することは、ダイアログを開くこととは異なる。ダイアログを開くことは、そのダイアログを作成して、表示することである(window.open()
が新しいウィンドウを作成して表示する方法と同様である)。ダイアログの表示は、すでにDOMにあるdialog
要素を取得し、それをインタラクティブにしてユーザーに可視にするプロセスである。
上記にもかかわらずdialog.open()
メソッドがあるとすれば、dialog.open
プロパティと競合するだろう。
さらに、dialog
要素のもとのデザインと同時代の他の多くのUIフレームワークの調査により、表示する/閉じる(show/close)の動詞のペアがかなり一般的であることが明らかになった。
要約すると、特定の動詞の意味、およびそれらの動詞が技術的なコンテキストでどのように使用されるかは、ダイアログの表示と閉じるなどのペアの動作が必ずしも対義語として表現できるとは限らないことがわかる。
"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 dialog
s 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
", then:
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.