ダイアログ
オーバーレイとして表示され、スクリプトなしで開閉できるネイティブのモーダルです。
このページの内容
ダイアログは表示階層の最上位にあるオーバーレイです。背後のページを暗くしてぼかす背景幕の上に表示されます。ネイティブの<dialog>に.dialogを指定します。commandforとcommand="show-modal"を指定したボタンで開くと、ブラウザーがダイアログをトップレイヤーに表示し、フォーカスをダイアログ内に保ち、Escで閉じる操作も処理するため、スクリプトは不要です。
ダイアログ
<button type="button" class="btn" commandfor="delete-project" command="show-modal"> Delete project</button><dialog id="delete-project" class="dialog" closedby="any" aria-labelledby="delete-project-title"> <header class="dialog-header"> <h2 class="dialog-title" id="delete-project-title">Delete this project?</h2> <p class="dialog-description"> Atlas and its 14 deployments are removed, and its domains stop resolving at once. </p> </header> <footer class="dialog-footer"> <button type="button" class="btn" commandfor="delete-project" command="close">Cancel</button> <button type="button" class="btn btn-primary" commandfor="delete-project" command="close"> Delete project </button> </footer></dialog><> <button type="button" className="btn" {...{ commandfor: 'delete-project', command: 'show-modal' }}> Delete project </button> <dialog id="delete-project" className="dialog" closedby="any" aria-labelledby="delete-project-title"> <header className="dialog-header"> <h2 className="dialog-title" id="delete-project-title">Delete this project?</h2> <p className="dialog-description"> Atlas and its 14 deployments are removed, and its domains stop resolving at once. </p> </header> <footer className="dialog-footer"> <button type="button" className="btn" {...{ commandfor: 'delete-project', command: 'close' }}> Cancel </button> <button type="button" className="btn btn-primary" {...{ commandfor: 'delete-project', command: 'close' }}> Delete project </button> </footer> </dialog></><button type="button" class="btn" commandfor="delete-project" command="show-modal"> Delete project</button><dialog id="delete-project" class="dialog" closedby="any" aria-labelledby="delete-project-title"> <header class="dialog-header"> <h2 class="dialog-title" id="delete-project-title">Delete this project?</h2> <p class="dialog-description"> Atlas and its 14 deployments are removed, and its domains stop resolving at once. </p> </header> <footer class="dialog-footer"> <button type="button" class="btn" commandfor="delete-project" command="close">Cancel</button> <button type="button" class="btn btn-primary" commandfor="delete-project" command="close"> Delete project </button> </footer></dialog><template> <button type="button" class="btn" commandfor="delete-project" command="show-modal"> Delete project </button> <dialog id="delete-project" class="dialog" closedby="any" aria-labelledby="delete-project-title"> <header class="dialog-header"> <h2 class="dialog-title" id="delete-project-title">Delete this project?</h2> <p class="dialog-description"> Atlas and its 14 deployments are removed, and its domains stop resolving at once. </p> </header> <footer class="dialog-footer"> <button type="button" class="btn" commandfor="delete-project" command="close">Cancel</button> <button type="button" class="btn btn-primary" commandfor="delete-project" command="close"> Delete project </button> </footer> </dialog></template>#開閉
従来はスクリプトが必要だったモーダルの開閉を、3つの属性で設定できます。
- ボタンに
commandfor="id"とcommand="show-modal"を指定すると、ダイアログがモーダルとして開きます。command="close"で閉じると、開いたボタンにフォーカスが戻ります。 - ダイアログに
closedby="any"を指定すると、常に使えるEscに加えて、背景幕をクリックして閉じられます。誤クリックで作業内容を失ってはいけない場合は、この属性を省略します。属性に未対応のブラウザーでも、Escと閉じるボタンは使えます。 - ダイアログ内の
<form method="dialog">を送信するとダイアログが閉じ、どのボタンで送信したかをダイアログのreturnValueで取得できます。
モーダルダイアログが開いている間は、背後のページを操作したりスクロールしたりできません。
#フォーム付き
dialog-bodyはヘッダーとフッターの間にコンテンツを配置します。残りの高さを使い、コンテンツがビューポート内に収まりきらない場合は、ダイアログ内でスクロールします。dialog-closeは隅に控えめな正方形のボタンを配置します。このボタンにはアクセシブルな名前を付けます。
フォーム付き
<button type="button" class="btn btn-primary" commandfor="invite" command="show-modal"> Invite member</button><dialog id="invite" class="dialog" aria-labelledby="invite-title"> <header class="dialog-header"> <h2 class="dialog-title" id="invite-title">Invite a member</h2> <p class="dialog-description">They receive an email with a link that expires in seven days.</p> </header> <form class="dialog-body flex flex-col gap-md" method="dialog" id="invite-form"> <label class="field"> Email <input class="input" type="email" placeholder="ada@example.com" required autofocus> </label> <label class="field"> Role <select class="select"> <option class="select-option">Member</option> <option class="select-option">Admin</option> <option class="select-option">Billing</option> </select> </label> </form> <footer class="dialog-footer"> <button type="button" class="btn" commandfor="invite" command="close">Cancel</button> <button type="submit" class="btn btn-primary" form="invite-form">Send invite</button> </footer> <button type="button" class="btn btn-quiet btn-square btn-sm dialog-close" commandfor="invite" command="close" aria-label="Close"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 4L12 12" /><path d="M4 12L12 4" /> </svg> </button></dialog>import XIcon from '@master/icons-react/native/16/soft/x'<> <button type="button" className="btn btn-primary" {...{ commandfor: 'invite', command: 'show-modal' }}> Invite member </button> <dialog id="invite" className="dialog" aria-labelledby="invite-title"> <header className="dialog-header"> <h2 className="dialog-title" id="invite-title">Invite a member</h2> <p className="dialog-description"> They receive an email with a link that expires in seven days. </p> </header> <form className="dialog-body flex flex-col gap-md" method="dialog" id="invite-form"> <label className="field"> Email <input className="input" type="email" placeholder="ada@example.com" required autoFocus /> </label> <label className="field"> Role <select className="select"> <option className="select-option">Member</option> <option className="select-option">Admin</option> <option className="select-option">Billing</option> </select> </label> </form> <footer className="dialog-footer"> <button type="button" className="btn" {...{ commandfor: 'invite', command: 'close' }}> Cancel </button> <button type="submit" className="btn btn-primary" form="invite-form">Send invite</button> </footer> <button type="button" className="btn btn-quiet btn-square btn-sm dialog-close" {...{ commandfor: 'invite', command: 'close' }} aria-label="Close"> <XIcon className="icon" /> </button> </dialog></><script> import XIcon from '@master/icons-svelte/native/16/soft/x'</script><button type="button" class="btn btn-primary" commandfor="invite" command="show-modal"> Invite member</button><dialog id="invite" class="dialog" aria-labelledby="invite-title"> <header class="dialog-header"> <h2 class="dialog-title" id="invite-title">Invite a member</h2> <p class="dialog-description">They receive an email with a link that expires in seven days.</p> </header> <form class="dialog-body flex flex-col gap-md" method="dialog" id="invite-form"> <label class="field"> Email <input class="input" type="email" placeholder="ada@example.com" required autofocus> </label> <label class="field"> Role <select class="select"> <option class="select-option">Member</option> <option class="select-option">Admin</option> <option class="select-option">Billing</option> </select> </label> </form> <footer class="dialog-footer"> <button type="button" class="btn" commandfor="invite" command="close">Cancel</button> <button type="submit" class="btn btn-primary" form="invite-form">Send invite</button> </footer> <button type="button" class="btn btn-quiet btn-square btn-sm dialog-close" commandfor="invite" command="close" aria-label="Close"> <XIcon class="icon" /> </button></dialog><script setup>import XIcon from '@master/icons-vue/native/16/soft/x'</script><template> <button type="button" class="btn btn-primary" commandfor="invite" command="show-modal"> Invite member </button> <dialog id="invite" class="dialog" aria-labelledby="invite-title"> <header class="dialog-header"> <h2 class="dialog-title" id="invite-title">Invite a member</h2> <p class="dialog-description"> They receive an email with a link that expires in seven days. </p> </header> <form class="dialog-body flex flex-col gap-md" method="dialog" id="invite-form"> <label class="field"> Email <input class="input" type="email" placeholder="ada@example.com" required autofocus> </label> <label class="field"> Role <select class="select"> <option class="select-option">Member</option> <option class="select-option">Admin</option> <option class="select-option">Billing</option> </select> </label> </form> <footer class="dialog-footer"> <button type="button" class="btn" commandfor="invite" command="close">Cancel</button> <button type="submit" class="btn btn-primary" form="invite-form">Send invite</button> </footer> <button type="button" class="btn btn-quiet btn-square btn-sm dialog-close" commandfor="invite" command="close" aria-label="Close"> <XIcon class="icon" /> </button> </dialog></template>#サイズ
ダイアログの既定幅は28remです。1文で済む確認には幅22remのdialog-smを使えます。dialog-lgの幅は40remです。画面が狭い場合は、どのサイズでもビューポートの左右に1remずつ余白を確保します。フッターはコンテナークエリーでダイアログ自体の幅に対応し、22rem未満では、主操作を先頭にしてボタンを全幅で縦に並べます。
サイズ
<button type="button" class="btn" commandfor="size-sm" command="show-modal">Small</button><button type="button" class="btn" commandfor="size-lg" command="show-modal">Large</button><dialog id="size-sm" class="dialog dialog-sm" closedby="any" aria-labelledby="size-sm-title"> <header class="dialog-header"> <h2 class="dialog-title" id="size-sm-title">Sign out?</h2> <p class="dialog-description">Unsaved drafts stay on this device.</p> </header> <footer class="dialog-footer"> <button type="button" class="btn" commandfor="size-sm" command="close">Stay</button> <button type="button" class="btn btn-primary" commandfor="size-sm" command="close"> Sign out </button> </footer></dialog><dialog id="size-lg" class="dialog dialog-lg" closedby="any" aria-labelledby="size-lg-title"> <header class="dialog-header"> <h2 class="dialog-title" id="size-lg-title">Release notes</h2> <p class="dialog-description"> Version 2.1 adds overlays that need no script: dialogs, popovers, menus and tooltips. </p> </header> <footer class="dialog-footer"> <button type="button" class="btn btn-primary" commandfor="size-lg" command="close">Done</button> </footer></dialog><> <button type="button" className="btn" {...{ commandfor: 'size-sm', command: 'show-modal' }}> Small </button> <button type="button" className="btn" {...{ commandfor: 'size-lg', command: 'show-modal' }}> Large </button> <dialog id="size-sm" className="dialog dialog-sm" closedby="any" aria-labelledby="size-sm-title"> <header className="dialog-header"> <h2 className="dialog-title" id="size-sm-title">Sign out?</h2> <p className="dialog-description">Unsaved drafts stay on this device.</p> </header> <footer className="dialog-footer"> <button type="button" className="btn" {...{ commandfor: 'size-sm', command: 'close' }}> Stay </button> <button type="button" className="btn btn-primary" {...{ commandfor: 'size-sm', command: 'close' }}> Sign out </button> </footer> </dialog> <dialog id="size-lg" className="dialog dialog-lg" closedby="any" aria-labelledby="size-lg-title"> <header className="dialog-header"> <h2 className="dialog-title" id="size-lg-title">Release notes</h2> <p className="dialog-description"> Version 2.1 adds overlays that need no script: dialogs, popovers, menus and tooltips. </p> </header> <footer className="dialog-footer"> <button type="button" className="btn btn-primary" {...{ commandfor: 'size-lg', command: 'close' }}> Done </button> </footer> </dialog></><button type="button" class="btn" commandfor="size-sm" command="show-modal">Small</button><button type="button" class="btn" commandfor="size-lg" command="show-modal">Large</button><dialog id="size-sm" class="dialog dialog-sm" closedby="any" aria-labelledby="size-sm-title"> <header class="dialog-header"> <h2 class="dialog-title" id="size-sm-title">Sign out?</h2> <p class="dialog-description">Unsaved drafts stay on this device.</p> </header> <footer class="dialog-footer"> <button type="button" class="btn" commandfor="size-sm" command="close">Stay</button> <button type="button" class="btn btn-primary" commandfor="size-sm" command="close"> Sign out </button> </footer></dialog><dialog id="size-lg" class="dialog dialog-lg" closedby="any" aria-labelledby="size-lg-title"> <header class="dialog-header"> <h2 class="dialog-title" id="size-lg-title">Release notes</h2> <p class="dialog-description"> Version 2.1 adds overlays that need no script: dialogs, popovers, menus and tooltips. </p> </header> <footer class="dialog-footer"> <button type="button" class="btn btn-primary" commandfor="size-lg" command="close">Done</button> </footer></dialog><template> <button type="button" class="btn" commandfor="size-sm" command="show-modal">Small</button> <button type="button" class="btn" commandfor="size-lg" command="show-modal">Large</button> <dialog id="size-sm" class="dialog dialog-sm" closedby="any" aria-labelledby="size-sm-title"> <header class="dialog-header"> <h2 class="dialog-title" id="size-sm-title">Sign out?</h2> <p class="dialog-description">Unsaved drafts stay on this device.</p> </header> <footer class="dialog-footer"> <button type="button" class="btn" commandfor="size-sm" command="close">Stay</button> <button type="button" class="btn btn-primary" commandfor="size-sm" command="close"> Sign out </button> </footer> </dialog> <dialog id="size-lg" class="dialog dialog-lg" closedby="any" aria-labelledby="size-lg-title"> <header class="dialog-header"> <h2 class="dialog-title" id="size-lg-title">Release notes</h2> <p class="dialog-description"> Version 2.1 adds overlays that need no script: dialogs, popovers, menus and tooltips. </p> </header> <footer class="dialog-footer"> <button type="button" class="btn btn-primary" commandfor="size-lg" command="close"> Done </button> </footer> </dialog></template>#ドロワー
dialog-drawerはインライン方向の終端に配置するパネルです。ページを表示したまま、フィルターや詳細、設定を開けます。角丸や影が切れないようにビューポートの端から8px内側に配置し、その端からスライドして現れます。
ドロワー
<button type="button" class="btn" commandfor="filters" command="show-modal">Filters</button><dialog id="filters" class="dialog dialog-drawer" closedby="any" aria-labelledby="filters-title"> <header class="dialog-header"> <h2 class="dialog-title" id="filters-title">Filters</h2> <p class="dialog-description">Narrow the list of deployments.</p> </header> <div class="dialog-body flex flex-col gap-md"> <label class="field">Branch <input class="input" value="main"></label> <label class="check"><input type="checkbox" class="checkbox" checked> Production only</label> </div> <footer class="dialog-footer"> <button type="button" class="btn" commandfor="filters" command="close">Reset</button> <button type="button" class="btn btn-primary" commandfor="filters" command="close"> Apply </button> </footer></dialog><> <button type="button" className="btn" {...{ commandfor: 'filters', command: 'show-modal' }}> Filters </button> <dialog id="filters" className="dialog dialog-drawer" closedby="any" aria-labelledby="filters-title"> <header className="dialog-header"> <h2 className="dialog-title" id="filters-title">Filters</h2> <p className="dialog-description">Narrow the list of deployments.</p> </header> <div className="dialog-body flex flex-col gap-md"> <label className="field">Branch <input className="input" defaultValue="main" /></label> <label className="check"> <input type="checkbox" className="checkbox" defaultChecked /> Production only </label> </div> <footer className="dialog-footer"> <button type="button" className="btn" {...{ commandfor: 'filters', command: 'close' }}> Reset </button> <button type="button" className="btn btn-primary" {...{ commandfor: 'filters', command: 'close' }}> Apply </button> </footer> </dialog></><button type="button" class="btn" commandfor="filters" command="show-modal">Filters</button><dialog id="filters" class="dialog dialog-drawer" closedby="any" aria-labelledby="filters-title"> <header class="dialog-header"> <h2 class="dialog-title" id="filters-title">Filters</h2> <p class="dialog-description">Narrow the list of deployments.</p> </header> <div class="dialog-body flex flex-col gap-md"> <label class="field">Branch <input class="input" value="main"></label> <label class="check"><input type="checkbox" class="checkbox" checked> Production only</label> </div> <footer class="dialog-footer"> <button type="button" class="btn" commandfor="filters" command="close">Reset</button> <button type="button" class="btn btn-primary" commandfor="filters" command="close"> Apply </button> </footer></dialog><template> <button type="button" class="btn" commandfor="filters" command="show-modal">Filters</button> <dialog id="filters" class="dialog dialog-drawer" closedby="any" aria-labelledby="filters-title"> <header class="dialog-header"> <h2 class="dialog-title" id="filters-title">Filters</h2> <p class="dialog-description">Narrow the list of deployments.</p> </header> <div class="dialog-body flex flex-col gap-md"> <label class="field">Branch <input class="input" value="main"></label> <label class="check"><input type="checkbox" class="checkbox" checked> Production only</label> </div> <footer class="dialog-footer"> <button type="button" class="btn" commandfor="filters" command="close">Reset</button> <button type="button" class="btn btn-primary" commandfor="filters" command="close"> Apply </button> </footer> </dialog></template>#始端への配置
dialog-drawer-startを追加すると、幅18remのドロワーをインライン方向の始端に配置でき、ナビゲーションに使えます。幅の狭いレイアウトでサイドバーを格納した場合は、このドロワーで表示できます。アプリシェルを参照してください。
始端に配置したドロワー
<button type="button" class="btn" commandfor="nav-drawer" command="show-modal"> Open navigation</button><dialog id="nav-drawer" class="dialog dialog-drawer dialog-drawer-start" closedby="any" aria-label="Navigation"> <div class="dialog-body"> <nav class="nav" aria-label="Workspace"> <a class="nav-item" href="#" aria-current="page">Overview</a> <a class="nav-item" href="#">Projects</a> <a class="nav-item" href="#">Domains</a> <a class="nav-item" href="#">Settings</a> </nav> </div></dialog><> <button type="button" className="btn" {...{ commandfor: 'nav-drawer', command: 'show-modal' }}> Open navigation </button> <dialog id="nav-drawer" className="dialog dialog-drawer dialog-drawer-start" closedby="any" aria-label="Navigation"> <div className="dialog-body"> <nav className="nav" aria-label="Workspace"> <a className="nav-item" href="#" aria-current="page">Overview</a> <a className="nav-item" href="#">Projects</a> <a className="nav-item" href="#">Domains</a> <a className="nav-item" href="#">Settings</a> </nav> </div> </dialog></><button type="button" class="btn" commandfor="nav-drawer" command="show-modal"> Open navigation</button><dialog id="nav-drawer" class="dialog dialog-drawer dialog-drawer-start" closedby="any" aria-label="Navigation"> <div class="dialog-body"> <nav class="nav" aria-label="Workspace"> <a class="nav-item" href="#" aria-current="page">Overview</a> <a class="nav-item" href="#">Projects</a> <a class="nav-item" href="#">Domains</a> <a class="nav-item" href="#">Settings</a> </nav> </div></dialog><template> <button type="button" class="btn" commandfor="nav-drawer" command="show-modal"> Open navigation </button> <dialog id="nav-drawer" class="dialog dialog-drawer dialog-drawer-start" closedby="any" aria-label="Navigation"> <div class="dialog-body"> <nav class="nav" aria-label="Workspace"> <a class="nav-item" href="#" aria-current="page">Overview</a> <a class="nav-item" href="#">Projects</a> <a class="nav-item" href="#">Domains</a> <a class="nav-item" href="#">Settings</a> </nav> </div> </dialog></template>#シート
dialog-sheetは画面の下端からせり上がります。小さな画面で、親指が届きやすい位置に短い操作や選択肢の一覧を表示できます。--dialog-widthを上限として横幅いっぱいに広がり、画面の下端に接する左右の角は直角になります。env(safe-area-inset-bottom)でホームインジケーターとの間に余白を確保します。
シート
<button type="button" class="btn" commandfor="share-sheet" command="show-modal">Share</button><dialog id="share-sheet" class="dialog dialog-sheet" closedby="any" aria-labelledby="share-sheet-title"> <header class="dialog-header"> <h2 class="dialog-title" id="share-sheet-title">Share this project</h2> <p class="dialog-description">Anyone with the link can view the latest deployment.</p> </header> <div class="dialog-body"> <div class="input-group"> <input class="input-group-field" value="https://atlas.dev/p/9f2c" readonly aria-label="Link"> <button type="button" class="btn">Copy</button> </div> </div> <footer class="dialog-footer"> <button type="button" class="btn btn-primary" commandfor="share-sheet" command="close"> Done </button> </footer></dialog><> <button type="button" className="btn" {...{ commandfor: 'share-sheet', command: 'show-modal' }}> Share </button> <dialog id="share-sheet" className="dialog dialog-sheet" closedby="any" aria-labelledby="share-sheet-title"> <header className="dialog-header"> <h2 className="dialog-title" id="share-sheet-title">Share this project</h2> <p className="dialog-description">Anyone with the link can view the latest deployment.</p> </header> <div className="dialog-body"> <div className="input-group"> <input className="input-group-field" defaultValue="https://atlas.dev/p/9f2c" readOnly aria-label="Link" /> <button type="button" className="btn">Copy</button> </div> </div> <footer className="dialog-footer"> <button type="button" className="btn btn-primary" {...{ commandfor: 'share-sheet', command: 'close' }}> Done </button> </footer> </dialog></><button type="button" class="btn" commandfor="share-sheet" command="show-modal">Share</button><dialog id="share-sheet" class="dialog dialog-sheet" closedby="any" aria-labelledby="share-sheet-title"> <header class="dialog-header"> <h2 class="dialog-title" id="share-sheet-title">Share this project</h2> <p class="dialog-description">Anyone with the link can view the latest deployment.</p> </header> <div class="dialog-body"> <div class="input-group"> <input class="input-group-field" value="https://atlas.dev/p/9f2c" readonly aria-label="Link"> <button type="button" class="btn">Copy</button> </div> </div> <footer class="dialog-footer"> <button type="button" class="btn btn-primary" commandfor="share-sheet" command="close"> Done </button> </footer></dialog><template> <button type="button" class="btn" commandfor="share-sheet" command="show-modal">Share</button> <dialog id="share-sheet" class="dialog dialog-sheet" closedby="any" aria-labelledby="share-sheet-title"> <header class="dialog-header"> <h2 class="dialog-title" id="share-sheet-title">Share this project</h2> <p class="dialog-description">Anyone with the link can view the latest deployment.</p> </header> <div class="dialog-body"> <div class="input-group"> <input class="input-group-field" value="https://atlas.dev/p/9f2c" readonly aria-label="Link"> <button type="button" class="btn">Copy</button> </div> </div> <footer class="dialog-footer"> <button type="button" class="btn btn-primary" commandfor="share-sheet" command="close"> Done </button> </footer> </dialog></template>#スワイプ
ドロワーやシートにdialog-swipeを追加すると、指、トラックパッド、マウスの動きに追従し、手を離すと閉じるようになります。ダイアログはパネルが移動するトラックになり、透明でビューポートと同じ大きさになります。ダイアログの内容はすべて、質感をまとうdialog-panelに入れます。シートには、つかむ位置を示す上端の短い溝dialog-handleを付けます。drawerビヘイビアを適用してください。attach()はすべてのdialog-swipeを見つけます。
スワイプで閉じるシート
<button type="button" class="btn" commandfor="share-swipe" command="show-modal">Share</button><dialog id="share-swipe" class="dialog dialog-sheet dialog-swipe" closedby="any" aria-labelledby="share-swipe-title"> <div class="dialog-panel"> <div class="dialog-handle" aria-hidden="true"></div> <header class="dialog-header"> <h2 class="dialog-title" id="share-swipe-title">Share this project</h2> <p class="dialog-description">Anyone with the link can view the latest deployment.</p> </header> <div class="dialog-body"> <div class="input-group"> <input class="input-group-field" value="https://atlas.dev/p/9f2c" readonly aria-label="Link"> <button type="button" class="btn">Copy</button> </div> </div> <footer class="dialog-footer"> <button type="button" class="btn btn-primary" commandfor="share-swipe" command="close"> Done </button> </footer> </div></dialog><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => attach(root.current!), []) return ( <div ref={root}> <button type="button" className="btn" {...{ commandfor: 'share-swipe', command: 'show-modal' }}> Share </button> <dialog id="share-swipe" className="dialog dialog-sheet dialog-swipe" closedby="any" aria-labelledby="share-swipe-title"> <div className="dialog-panel"> <div className="dialog-handle" aria-hidden="true"></div> <header className="dialog-header"> <h2 className="dialog-title" id="share-swipe-title">Share this project</h2> <p className="dialog-description">Anyone with the link can view the latest deployment.</p> </header> <div className="dialog-body"> <div className="input-group"> <input className="input-group-field" defaultValue="https://atlas.dev/p/9f2c" readOnly aria-label="Link" /> <button type="button" className="btn">Copy</button> </div> </div> <footer className="dialog-footer"> <button type="button" className="btn btn-primary" {...{ commandfor: 'share-swipe', command: 'close' }}> Done </button> </footer> </div> </dialog> </div> )}<script> import { attach } from '@master/ui/behaviors'</script><div {@attach attach}> <button type="button" class="btn" commandfor="share-swipe" command="show-modal">Share</button> <dialog id="share-swipe" class="dialog dialog-sheet dialog-swipe" closedby="any" aria-labelledby="share-swipe-title"> <div class="dialog-panel"> <div class="dialog-handle" aria-hidden="true"></div> <header class="dialog-header"> <h2 class="dialog-title" id="share-swipe-title">Share this project</h2> <p class="dialog-description">Anyone with the link can view the latest deployment.</p> </header> <div class="dialog-body"> <div class="input-group"> <input class="input-group-field" value="https://atlas.dev/p/9f2c" readonly aria-label="Link"> <button type="button" class="btn">Copy</button> </div> </div> <footer class="dialog-footer"> <button type="button" class="btn btn-primary" commandfor="share-swipe" command="close"> Done </button> </footer> </div> </dialog></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <div ref="root"> <button type="button" class="btn" commandfor="share-swipe" command="show-modal">Share</button> <dialog id="share-swipe" class="dialog dialog-sheet dialog-swipe" closedby="any" aria-labelledby="share-swipe-title"> <div class="dialog-panel"> <div class="dialog-handle" aria-hidden="true"></div> <header class="dialog-header"> <h2 class="dialog-title" id="share-swipe-title">Share this project</h2> <p class="dialog-description">Anyone with the link can view the latest deployment.</p> </header> <div class="dialog-body"> <div class="input-group"> <input class="input-group-field" value="https://atlas.dev/p/9f2c" readonly aria-label="Link"> <button type="button" class="btn">Copy</button> </div> </div> <footer class="dialog-footer"> <button type="button" class="btn btn-primary" commandfor="share-swipe" command="close"> Done </button> </footer> </div> </dialog> </div></template>ドロワーも同じように、配置された端に向かってスワイプします。ハンドルは不要で、パネル全体をつかめます。
スワイプで閉じるドロワー
<button type="button" class="btn" commandfor="filters-swipe" command="show-modal">Filters</button><dialog id="filters-swipe" class="dialog dialog-drawer dialog-swipe" closedby="any" aria-labelledby="filters-swipe-title"> <div class="dialog-panel"> <header class="dialog-header"> <h2 class="dialog-title" id="filters-swipe-title">Filters</h2> <p class="dialog-description">Narrow the list of deployments.</p> </header> <div class="dialog-body flex flex-col gap-md"> <label class="field">Branch <input class="input" value="main"></label> <label class="check"><input type="checkbox" class="checkbox" checked> Production only</label> </div> <footer class="dialog-footer"> <button type="button" class="btn" commandfor="filters-swipe" command="close">Reset</button> <button type="button" class="btn btn-primary" commandfor="filters-swipe" command="close"> Apply </button> </footer> </div></dialog><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => attach(root.current!), []) return ( <div ref={root}> <button type="button" className="btn" {...{ commandfor: 'filters-swipe', command: 'show-modal' }}> Filters </button> <dialog id="filters-swipe" className="dialog dialog-drawer dialog-swipe" closedby="any" aria-labelledby="filters-swipe-title"> <div className="dialog-panel"> <header className="dialog-header"> <h2 className="dialog-title" id="filters-swipe-title">Filters</h2> <p className="dialog-description">Narrow the list of deployments.</p> </header> <div className="dialog-body flex flex-col gap-md"> <label className="field">Branch <input className="input" defaultValue="main" /></label> <label className="check"> <input type="checkbox" className="checkbox" defaultChecked /> Production only </label> </div> <footer className="dialog-footer"> <button type="button" className="btn" {...{ commandfor: 'filters-swipe', command: 'close' }}> Reset </button> <button type="button" className="btn btn-primary" {...{ commandfor: 'filters-swipe', command: 'close' }}> Apply </button> </footer> </div> </dialog> </div> )}<script> import { attach } from '@master/ui/behaviors'</script><div {@attach attach}> <button type="button" class="btn" commandfor="filters-swipe" command="show-modal">Filters</button> <dialog id="filters-swipe" class="dialog dialog-drawer dialog-swipe" closedby="any" aria-labelledby="filters-swipe-title"> <div class="dialog-panel"> <header class="dialog-header"> <h2 class="dialog-title" id="filters-swipe-title">Filters</h2> <p class="dialog-description">Narrow the list of deployments.</p> </header> <div class="dialog-body flex flex-col gap-md"> <label class="field">Branch <input class="input" value="main"></label> <label class="check"> <input type="checkbox" class="checkbox" checked> Production only </label> </div> <footer class="dialog-footer"> <button type="button" class="btn" commandfor="filters-swipe" command="close">Reset</button> <button type="button" class="btn btn-primary" commandfor="filters-swipe" command="close"> Apply </button> </footer> </div> </dialog></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <div ref="root"> <button type="button" class="btn" commandfor="filters-swipe" command="show-modal"> Filters </button> <dialog id="filters-swipe" class="dialog dialog-drawer dialog-swipe" closedby="any" aria-labelledby="filters-swipe-title"> <div class="dialog-panel"> <header class="dialog-header"> <h2 class="dialog-title" id="filters-swipe-title">Filters</h2> <p class="dialog-description">Narrow the list of deployments.</p> </header> <div class="dialog-body flex flex-col gap-md"> <label class="field">Branch <input class="input" value="main"></label> <label class="check"> <input type="checkbox" class="checkbox" checked> Production only </label> </div> <footer class="dialog-footer"> <button type="button" class="btn" commandfor="filters-swipe" command="close"> Reset </button> <button type="button" class="btn btn-primary" commandfor="filters-swipe" command="close"> Apply </button> </footer> </div> </dialog> </div></template>スワイプの仕組みは次のとおりです。
- パネルはブラウザーが動かします。トラックはスナップポイントを持つスクロールコンテナーです。スナップポイントは、開いた状態で止まる位置と、手を離したパネルが端の外側で止まる位置です。端の外側には、ビューポートと同じ大きさのスクロール領域があります。指、トラックパッド、ホイールでスクロールするため、手の動きへの追従、はじいたときの慣性、止まる位置の選択はブラウザー自身が行います。トラックは逆向きのフレックスラインで、パネルはその末尾にあるため、スクリプトなしで開いた状態の位置から始まります。
- スクロールでできないことはビヘイビアが行います。パネルがどのような方法でトラックから出た場合でも、ダイアログを閉じます。
closedby="any"の動作も取り戻します。トラックはブラウザーが反応する背景幕を覆ってしまうため、パネルの横を押したときにビヘイビアがダイアログを閉じます。ドラッグでスクロールできないマウスでも、ハンドル、またはコントロールや本文以外の部分でパネルをつかめるようにし、はじいた方向の位置、または近いほうの位置で離せるようにします。精密なポインターがパネルをつかんでいる間、トラックはスナップしません。残っている背景幕の濃さを--dialog-scrimに書き込み、パネルが離れるにつれて背景幕を薄くします。 - ダイアログはダイアログのままです。 Esc、閉じるボタン、フォーカストラップ、トリガーへのフォーカスの復帰、スライドイン・スライドアウトは、通常のドロワーやシートと同じです。
- スクロールする本文は独自のスクロールを保ちます。
dialog-body内では、マウスのドラッグやホイール操作は、本文のスクロールやテキストの選択に使われます。タッチスクリーンでは、本文の先頭まで達したドラッグはそのままシートを動かします。
スワイプは近道です。閉じるボタンかダイアログを閉じるアクションを残し、Escも使えるようにしてください。
#デテント
スワイプできるシートにdialog-detentsを追加すると、シートは2つの高さで止まります。開いたときのビューポートの半分の高さと、全体の高さです。ドラッグやはじく操作で2つの高さの間を移動します。全体の高さから下にはじくと半分の高さで止まり、半分の高さから下にはじくと閉じます。ハンドルはアクセシブルな名前を持つ<button>にします。押す、Enter、Spaceでシートをもう一方の高さに移し、↑で全体の高さに広げ、↓で半分の高さに縮めます。ハンドルのaria-expandedは、シートが全体の高さにあるかどうかを示します。
デテント付きのシート
<button type="button" class="btn" commandfor="comments-sheet" command="show-modal">Comments</button><dialog id="comments-sheet" class="dialog dialog-sheet dialog-swipe dialog-detents" closedby="any" aria-labelledby="comments-sheet-title"> <div class="dialog-panel"> <button type="button" class="dialog-handle" aria-label="Sheet height"></button> <header class="dialog-header"> <h2 class="dialog-title" id="comments-sheet-title">Comments</h2> <p class="dialog-description">Five people reviewed this deployment.</p> </header> <div class="dialog-body flex flex-col gap-md"> <p class="m(0)">Ada: the build on main is green again.</p> <p class="m(0)">Grace: the preview for the pricing page loads in 1.2s.</p> <p class="m(0)">Linus: the cache headers on the fonts are right now.</p> <p class="m(0)">Margaret: the rollback plan is in the runbook.</p> <p class="m(0)">Alan: ship it after the 3pm check.</p> </div> <button type="button" class="btn btn-quiet btn-square btn-sm dialog-close" commandfor="comments-sheet" command="close" aria-label="Close"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 4L12 12" /><path d="M4 12L12 4" /> </svg> </button> </div></dialog><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import XIcon from '@master/icons-react/native/16/soft/x'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => attach(root.current!), []) return ( <div ref={root}> <button type="button" className="btn" {...{ commandfor: 'comments-sheet', command: 'show-modal' }}> Comments </button> <dialog id="comments-sheet" className="dialog dialog-sheet dialog-swipe dialog-detents" closedby="any" aria-labelledby="comments-sheet-title"> <div className="dialog-panel"> <button type="button" className="dialog-handle" aria-label="Sheet height"></button> <header className="dialog-header"> <h2 className="dialog-title" id="comments-sheet-title">Comments</h2> <p className="dialog-description">Five people reviewed this deployment.</p> </header> <div className="dialog-body flex flex-col gap-md"> <p className="m(0)">Ada: the build on main is green again.</p> <p className="m(0)">Grace: the preview for the pricing page loads in 1.2s.</p> <p className="m(0)">Linus: the cache headers on the fonts are right now.</p> <p className="m(0)">Margaret: the rollback plan is in the runbook.</p> <p className="m(0)">Alan: ship it after the 3pm check.</p> </div> <button type="button" className="btn btn-quiet btn-square btn-sm dialog-close" {...{ commandfor: 'comments-sheet', command: 'close' }} aria-label="Close"> <XIcon className="icon" /> </button> </div> </dialog> </div> )}<script> import { attach } from '@master/ui/behaviors' import XIcon from '@master/icons-svelte/native/16/soft/x'</script><div {@attach attach}> <button type="button" class="btn" commandfor="comments-sheet" command="show-modal"> Comments </button> <dialog id="comments-sheet" class="dialog dialog-sheet dialog-swipe dialog-detents" closedby="any" aria-labelledby="comments-sheet-title"> <div class="dialog-panel"> <button type="button" class="dialog-handle" aria-label="Sheet height"></button> <header class="dialog-header"> <h2 class="dialog-title" id="comments-sheet-title">Comments</h2> <p class="dialog-description">Five people reviewed this deployment.</p> </header> <div class="dialog-body flex flex-col gap-md"> <p class="m(0)">Ada: the build on main is green again.</p> <p class="m(0)">Grace: the preview for the pricing page loads in 1.2s.</p> <p class="m(0)">Linus: the cache headers on the fonts are right now.</p> <p class="m(0)">Margaret: the rollback plan is in the runbook.</p> <p class="m(0)">Alan: ship it after the 3pm check.</p> </div> <button type="button" class="btn btn-quiet btn-square btn-sm dialog-close" commandfor="comments-sheet" command="close" aria-label="Close"> <XIcon class="icon" /> </button> </div> </dialog></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import XIcon from '@master/icons-vue/native/16/soft/x'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <div ref="root"> <button type="button" class="btn" commandfor="comments-sheet" command="show-modal"> Comments </button> <dialog id="comments-sheet" class="dialog dialog-sheet dialog-swipe dialog-detents" closedby="any" aria-labelledby="comments-sheet-title"> <div class="dialog-panel"> <button type="button" class="dialog-handle" aria-label="Sheet height"></button> <header class="dialog-header"> <h2 class="dialog-title" id="comments-sheet-title">Comments</h2> <p class="dialog-description">Five people reviewed this deployment.</p> </header> <div class="dialog-body flex flex-col gap-md"> <p class="m(0)">Ada: the build on main is green again.</p> <p class="m(0)">Grace: the preview for the pricing page loads in 1.2s.</p> <p class="m(0)">Linus: the cache headers on the fonts are right now.</p> <p class="m(0)">Margaret: the rollback plan is in the runbook.</p> <p class="m(0)">Alan: ship it after the 3pm check.</p> </div> <button type="button" class="btn btn-quiet btn-square btn-sm dialog-close" commandfor="comments-sheet" command="close" aria-label="Close"> <XIcon class="icon" /> </button> </div> </dialog> </div></template>半分の高さのとき、シートの下半分はフッターも含めて画面の端の外で待機します。そのためデテントは、リスト、コメント、地図など、アクションが上部にある閲覧用のシートに向いています。高さがビューポートの半分に満たないシートは、シート全体が見える位置でのみ止まり、ハンドルもその状態を示します。
#機能がない場合
- スクリプトが無効な場合、端の外側の領域は停止位置になりません(
@media (scripting: enabled))。手を離したパネルは元の位置に戻り、Escと閉じるボタンでダイアログを閉じられます。スクリプトが動作する環境では必ずビヘイビアを適用してください。適用しないと、手を離したパネルが画面外で止まり、ページは操作できないままになります。 - ビヘイビアがない場合、背景幕はダイアログが閉じるまで薄くなりません。これはスクロール駆動アニメーションではありません。逆向きのスクロールコンテナーでは、ChromiumとWebKitでスクロールタイムラインとビュータイムラインの向きが逆になるためです。
scroll-initial-targetに対応したブラウザー(Chromium)では、デテント付きのシートはスクリプトの実行前から半分の高さで開きます。それ以外のブラウザーでは、ビヘイビアが動かすまで全体の高さで開きます。
スワイプは、ChromiumとWebKitでマウスとホイールを使って、またChromiumではタッチ操作でも検証しています。スクロールスナップ、逆向きのフレックスのスクロール、scrollendは、現行のすべてのブラウザーで使えます。
#アニメーション
ダイアログは、元の大きさの97%で0.5rem下にずれた状態から、280msかけてフェードインします。閉じるときは160msかけて消えます。開閉の両方をスタイルシートのCSSで定義します。@starting-styleで描画の初期状態を指定し、displayとoverlayをallow-discreteでトランジションさせることで、閉じるアニメーションが終わってからダイアログがトップレイヤーを離れます。動きを減らす設定では、フェードだけが残ります。
#アクセシビリティ
aria-labelledbyでダイアログのdialog-titleを参照し、ダイアログに名前を付けます。show-modalで開くと、フォーカスはダイアログ内に移り、閉じると開いたボタンに戻ります。最初にフォーカスを当てるフィールドにautofocusを指定します。削除などの破壊的な操作を確認する場合は、安全な選択肢に指定します。commandとcommandforは、現行のChrome、Edge、Firefox、Safariでサポートされています。古いブラウザーではクリックハンドラーからdialog.showModal()を呼び出します。スタイルシートはそのまま使えます。- スワイプだけを閉じる手段にしないでください。閉じるボタンか閉じるアクションを残します。Escでも引き続き閉じられます。デテント付きのシートでは、ハンドルは「シートの高さ」のような名前を持つボタンで、キー操作や押す操作でドラッグと同じように高さを変えます。デテントがない場合、ハンドルは支援技術から隠された溝です。操作領域は64×24pxで、タッチ画面では高さが44pxになります。
#React、Svelte、Vue
dialogコンポーネントは、アプリケーションの状態に応じてダイアログを開閉し、ブラウザーで実際に開閉されたことを通知します。開くための要素とダイアログ内の各部には、ページ側のマークアップをそのまま使います。すべてのダイアログにdrawerビヘイビアを適用するため、dialog-swipeとdialog-panelを持つドロワーやシートは、手を離すと閉じ、ほかの閉じ方と同じように通知されます。dialog-swipeのないダイアログでは、ビヘイビアは何もしません。npx master-ui add dialogでプロジェクトにコピーできます。構成と使い方はReact、Svelte、Vueを参照してください。
#クラス
| クラス | 説明 |
|---|---|
dialog | aria-labelledbyまたはaria-labelで名前を付けた dialog 要素に適用するオーバーレイシート。幅は28remで、ビューポートの端から1remの余白を確保します。 |
dialog-sm | 幅は 22rem で、1 文の確認メッセージに適しています。既定は 28rem です。dialog と併用します |
dialog-lg | 幅は 40rem です。既定は 28rem です。dialog と併用します |
dialog-drawer | ページを表示したまま作業できる、inline-end 側の幅 24rem のパネルです。ビューポートの端から 8px 内側に浮かび、配置される側の端からスライドインします。dialog と併用します |
dialog-drawer-start | dialog-drawer と併用すると、ナビゲーション用の幅 18rem のパネルが inline-start 側の端に配置されます。dialog と併用します |
dialog-sheet | 下端からせり上がるパネルです。下側の角は直角で、ホームインジケーターに重なりません。dialog と併用します |
dialog-swipe | dialog-drawer または dialog-sheet と併用します。ダイアログはビューポートと同じ大きさの透明なトラックになり、その中の dialog-panel が指、トラックパッド、ホイール、マウスに追従し、離すと閉じます。drawer ビヘイビアを適用します。dialog と併用します |
dialog-detents | dialog-sheet と dialog-swipe と併用します。シートは可能な限りの高さになり、ビューポートの半分が見える状態で開き、その位置か全高で止まります。dialog と併用します |
dialog-panel | dialog-swipe 内のドロワーまたはシート本体です。質感をまとい、ヘッダー、本文、フッター、閉じるボタンを収めます。 |
dialog-handle | つまみ部分です。シート上端の短い溝で、dialog-panel の先頭に置きます。dialog-detents を使うシートでは、動作を名前にしたボタンにします。ビヘイビアがボタンに合わせてシートを動かし、aria-expanded を設定します。それ以外では aria-hidden="true" を付けた div にします。 |
dialog-header | シート上部にタイトルと説明を配置する領域 |
dialog-title | タイトルです。ダイアログのaria-labelledbyでこのタイトルを参照します。 |
dialog-description | タイトルの下で、その意味を補足する控えめな一文 |
dialog-body | ヘッダーとフッターの間のコンテンツ。残りの高さを使い、長い場合はシート内でスクロール |
dialog-footer | 主要アクションを最後に並べます。ダイアログの幅が 22rem 未満では、各アクションを全幅で縦に並べ、主要アクションを先頭に置きます。 |
dialog-close | インライン方向の末尾側の上隅に控えめな正方形ボタンを配置。アクセシブルな名前が必要 |
#カスタムプロパティ
| プロパティ | 既定値 | 説明 |
|---|---|---|
--dialog-width | 28rem | 優先幅 |
--dialog-padding | 1.5rem | 各パーツの周囲のパディング |
--dialog-radius | 1.25rem | 角の半径 |
--dialog-scrim | dialog-swipe で、背景幕がどれだけ残っているかを示します。未設定時の 1(すべて)から、パネルが離れるにつれて 0 まで下がります。drawer ビヘイビアが書き込みます。 |