導覽提示
操作導覽中的一個步驟,指向要說明的控制項。
本頁內容
導覽提示是操作導覽中的一個步驟,用一張小卡片指向控制項並說明其用途。它是彈出面板,因此瀏覽器會將它放在頂層,並把焦點移入其中。CSS 錨點定位會將卡片放在開啟它的元素旁,並以箭頭指向該元素。提示點是個不時向外擴散圓環的小圓點,用來標示頁面上的位置,也是開啟卡片的按鈕。操作導覽則透過 tour 行為依序開啟多則導覽提示。
導覽提示
<div class="toolbar" role="toolbar" aria-label="Deployments"> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Search"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="7" cy="7" r="4.5" /><path d="M10.182 10.182L14 14" /> </svg> </button> <span class="relative inline-flex"> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Filter"> <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.5365 3L11.4635 3A1 1 0 0 1 12.2548 4.6114L9.4587 8.2299A1 1 0 0 0 9.25 8.8413L9.25 11.323A1 1 0 0 1 8.6214 12.2514L7.875 12.55A0.8203 0.8203 0 0 1 6.75 11.7883L6.75 8.8413A1 1 0 0 0 6.5413 8.2299L3.7452 4.6114A1 1 0 0 1 4.5365 3Z" /> </svg> </button> <button type="button" class="coachmark-beacon absolute top(-3) right(-3)" popovertarget="tip-filter" aria-label="What is new in Filter"></button> <div id="tip-filter" popover class="coachmark coachmark-top" role="dialog" aria-labelledby="tip-filter-title"> <p class="coachmark-count">New</p> <h2 class="coachmark-title" id="tip-filter-title">Filter by author</h2> <p class="coachmark-text"> Narrow the deployments to the ones you shipped, or to anyone on the team. </p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm" popovertarget="tip-filter" popovertargetaction="hide" autofocus> Got it </button> </div> </div> </span> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Share"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="3.6667" cy="8" r="1.6667" /><circle cx="12" cy="3.3333" r="1.6667" /><circle cx="12" cy="12.6667" r="1.6667" /><path d="M5.12 7.1867L10.5467 4.1467" /><path d="M5.12 8.8133L10.5467 11.8533" /> </svg> </button></div>import SearchIcon from '@master/icons-react/native/16/soft/search'import FilterIcon from '@master/icons-react/native/16/soft/filter'import ShareIcon from '@master/icons-react/native/16/soft/share'<div className="toolbar" role="toolbar" aria-label="Deployments"> <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Search"> <SearchIcon className="icon" /> </button> <span className="relative inline-flex"> <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Filter"> <FilterIcon className="icon" /> </button> <button type="button" className="coachmark-beacon absolute top(-3) right(-3)" popoverTarget="tip-filter" aria-label="What is new in Filter"></button> <div id="tip-filter" popover="" className="coachmark coachmark-top" role="dialog" aria-labelledby="tip-filter-title"> <p className="coachmark-count">New</p> <h2 className="coachmark-title" id="tip-filter-title">Filter by author</h2> <p className="coachmark-text"> Narrow the deployments to the ones you shipped, or to anyone on the team. </p> <div className="coachmark-actions"> <button type="button" className="btn btn-sm" popoverTarget="tip-filter" popoverTargetAction="hide" autoFocus> Got it </button> </div> </div> </span> <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Share"> <ShareIcon className="icon" /> </button></div><script> import SearchIcon from '@master/icons-svelte/native/16/soft/search' import FilterIcon from '@master/icons-svelte/native/16/soft/filter' import ShareIcon from '@master/icons-svelte/native/16/soft/share'</script><div class="toolbar" role="toolbar" aria-label="Deployments"> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Search"> <SearchIcon class="icon" /> </button> <span class="relative inline-flex"> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Filter"> <FilterIcon class="icon" /> </button> <button type="button" class="coachmark-beacon absolute top(-3) right(-3)" popovertarget="tip-filter" aria-label="What is new in Filter"></button> <div id="tip-filter" popover class="coachmark coachmark-top" role="dialog" aria-labelledby="tip-filter-title"> <p class="coachmark-count">New</p> <h2 class="coachmark-title" id="tip-filter-title">Filter by author</h2> <p class="coachmark-text"> Narrow the deployments to the ones you shipped, or to anyone on the team. </p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm" popovertarget="tip-filter" popovertargetaction="hide" autofocus> Got it </button> </div> </div> </span> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Share"> <ShareIcon class="icon" /> </button></div><script setup>import SearchIcon from '@master/icons-vue/native/16/soft/search'import FilterIcon from '@master/icons-vue/native/16/soft/filter'import ShareIcon from '@master/icons-vue/native/16/soft/share'</script><template> <div class="toolbar" role="toolbar" aria-label="Deployments"> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Search"> <SearchIcon class="icon" /> </button> <span class="relative inline-flex"> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Filter"> <FilterIcon class="icon" /> </button> <button type="button" class="coachmark-beacon absolute top(-3) right(-3)" popovertarget="tip-filter" aria-label="What is new in Filter"></button> <div id="tip-filter" popover class="coachmark coachmark-top" role="dialog" aria-labelledby="tip-filter-title"> <p class="coachmark-count">New</p> <h2 class="coachmark-title" id="tip-filter-title">Filter by author</h2> <p class="coachmark-text"> Narrow the deployments to the ones you shipped, or to anyone on the team. </p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm" popovertarget="tip-filter" popovertargetaction="hide" autofocus> Got it </button> </div> </div> </span> <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Share"> <ShareIcon class="icon" /> </button> </div></template>卡片以平面樣式呈現 sheet-inverse 的反相配色,在月長石色底上用墨色,在黑曜石色底上用珍珠色,因此能與一般彈出面板及下方頁面區隔,箭頭也與卡片無縫相接。卡片上的預設按鈕清楚標示可執行的動作。低調樣式的按鈕沿用卡片的前景色,指標停留時則以該色的淡色調作為底色。
#結構
只有標題是必填項目。
| 類別 | 內容 |
|---|---|
coachmark-count | 以較低調的前景色顯示導覽進度,例如「第 2 步,共 4 步」,也可顯示「新功能」之類的字樣 |
coachmark-title | 步驟標題。為它設定 id,並用它標示導覽提示 |
coachmark-text | 用一兩句話說明控制項的用途 |
coachmark-actions | 卡片底部的小按鈕。有多個按鈕時,第一個(例如「略過」)靠起始端,其餘(例如「上一步」和「下一步」)靠結束端排列 |
操作按鈕與卡片邊緣相距 12px,讓小按鈕的圓角與卡片圓角相襯。卡片的圓角半徑等於按鈕的圓角半徑加上這段內距。
#位置
導覽提示預設在觸發元素正下方置中開啟,箭頭尖端距離該元素 6px。下方空間不足時,卡片會翻到上方。coachmark-top 優先使用上方空間,適合靠近畫面底部的控制項,或像第一個範例那樣把提示點放在控制項的上角。
箭頭會指向標記中緊接在導覽提示前面的元素,因此請把導覽提示放在提示點或所要說明的控制項之後;在操作導覽中,箭頭則指向導覽的聚光燈,聚光燈會覆蓋在該步驟的目標上。導覽提示開啟時,該元素會成為具名錨點,箭頭會對準其中央。即使檢視區邊緣把卡片推向一旁,箭頭也會維持對準,同時避開卡片的圓角。卡片翻轉時,箭頭會移到另一側。和操作導覽一樣,一次只會開啟一則導覽提示。
#提示點
coachmark-beacon 是按鈕上直徑 10px 的圓點,外框沿用所在表面的顏色,可點按範圍為 24px,在觸控螢幕上為 44px。它透過 popovertarget 開啟對應的導覽提示,並需要用 aria-label 說明會開啟什麼。提示點的位置由頁面決定。可在 relative 包裝元素內使用 absolute utility,將提示點放在控制項的上角,也可將兩者並排。
提示點以向外擴散的圓環吸引注意。指標停在提示點上、提示點取得焦點、對應的導覽提示開啟,或使用者偏好減少動態效果時,圓環會維持為靜止的光暈。使用者看過該步驟後,請移除提示點。
#操作導覽
操作導覽會依序開啟數則導覽提示,每則都以它所說明的控制項為錨點。將各步驟依進行順序放在 coachmark-tour 中,並為每個步驟設定 popover="manual",讓使用者點擊頁面(例如試用步驟所指的控制項)時不會結束導覽。步驟以 data-target 中的選擇器指定目標;沒有指定時,會指向標記中緊接在它前面的元素。步驟的按鈕以 value 表示其作用:next、back、skip,最後一個步驟則用 done。
其餘工作由 tour 行為處理。帶有 command="--start" 且以 commandfor 指向導覽的按鈕會開始導覽;行為會用 showPopover({ source }) 以目標為錨點開啟每個步驟,讓瀏覽器把卡片錨定在那裡並由 CSS 定位,再把焦點移入卡片中的「下一步」或「完成」。導覽中的 coachmark-spotlight 會先在目標上方開啟:無論步驟位在標記中的哪個位置,步驟的箭頭都會指向它。
操作導覽
<div class="coachmark-tour flex items-center gap-sm" id="deploys-tour"> <button type="button" class="btn btn-sm" commandfor="deploys-tour" command="--start"> Take the tour </button> <div class="toolbar" role="toolbar" aria-label="Deployments"> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-search" aria-label="Search"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="7" cy="7" r="4.5" /><path d="M10.182 10.182L14 14" /> </svg> </button> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-filter" aria-label="Filter"> <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.5365 3L11.4635 3A1 1 0 0 1 12.2548 4.6114L9.4587 8.2299A1 1 0 0 0 9.25 8.8413L9.25 11.323A1 1 0 0 1 8.6214 12.2514L7.875 12.55A0.8203 0.8203 0 0 1 6.75 11.7883L6.75 8.8413A1 1 0 0 0 6.5413 8.2299L3.7452 4.6114A1 1 0 0 1 4.5365 3Z" /> </svg> </button> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-share" aria-label="Share"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="3.6667" cy="8" r="1.6667" /><circle cx="12" cy="3.3333" r="1.6667" /><circle cx="12" cy="12.6667" r="1.6667" /><path d="M5.12 7.1867L10.5467 4.1467" /><path d="M5.12 8.8133L10.5467 11.8533" /> </svg> </button> </div> <div class="coachmark-spotlight" popover="manual"></div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-search-title" data-target="#deploys-search"> <p class="coachmark-count">1 of 3</p> <h2 class="coachmark-title" id="deploys-search-title">Search every deployment</h2> <p class="coachmark-text">Find one by its branch, its commit or the person who shipped it.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-filter-title" data-target="#deploys-filter"> <p class="coachmark-count">2 of 3</p> <h2 class="coachmark-title" id="deploys-filter-title">Filter the list</h2> <p class="coachmark-text">Keep only the deployments of one branch, one author or one status.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-share-title" data-target="#deploys-share"> <p class="coachmark-count">3 of 3</p> <h2 class="coachmark-title" id="deploys-share-title">Share a deployment</h2> <p class="coachmark-text">Copy a link to it, open for anyone on the team.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="done">Done</button> </div> </div></div><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import SearchIcon from '@master/icons-react/native/16/soft/search'import FilterIcon from '@master/icons-react/native/16/soft/filter'import ShareIcon from '@master/icons-react/native/16/soft/share'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => attach(root.current!), []) return ( <div ref={root} className="coachmark-tour flex items-center gap-sm" id="deploys-tour"> <button type="button" className="btn btn-sm" {...{ commandfor: 'deploys-tour', command: '--start' }}> Take the tour </button> <div className="toolbar" role="toolbar" aria-label="Deployments"> <button type="button" className="btn btn-quiet btn-sm btn-square" id="deploys-search" aria-label="Search"> <SearchIcon className="icon" /> </button> <button type="button" className="btn btn-quiet btn-sm btn-square" id="deploys-filter" aria-label="Filter"> <FilterIcon className="icon" /> </button> <button type="button" className="btn btn-quiet btn-sm btn-square" id="deploys-share" aria-label="Share"> <ShareIcon className="icon" /> </button> </div> <div className="coachmark-spotlight" popover="manual"></div> <div className="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-search-title" data-target="#deploys-search"> <p className="coachmark-count">1 of 3</p> <h2 className="coachmark-title" id="deploys-search-title">Search every deployment</h2> <p className="coachmark-text"> Find one by its branch, its commit or the person who shipped it. </p> <div className="coachmark-actions"> <button type="button" className="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" className="btn btn-sm" value="next">Next</button> </div> </div> <div className="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-filter-title" data-target="#deploys-filter"> <p className="coachmark-count">2 of 3</p> <h2 className="coachmark-title" id="deploys-filter-title">Filter the list</h2> <p className="coachmark-text"> Keep only the deployments of one branch, one author or one status. </p> <div className="coachmark-actions"> <button type="button" className="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" className="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" className="btn btn-sm" value="next">Next</button> </div> </div> <div className="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-share-title" data-target="#deploys-share"> <p className="coachmark-count">3 of 3</p> <h2 className="coachmark-title" id="deploys-share-title">Share a deployment</h2> <p className="coachmark-text">Copy a link to it, open for anyone on the team.</p> <div className="coachmark-actions"> <button type="button" className="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" className="btn btn-sm" value="done">Done</button> </div> </div> </div> )}<script> import { attach } from '@master/ui/behaviors' import SearchIcon from '@master/icons-svelte/native/16/soft/search' import FilterIcon from '@master/icons-svelte/native/16/soft/filter' import ShareIcon from '@master/icons-svelte/native/16/soft/share'</script><div class="coachmark-tour flex items-center gap-sm" id="deploys-tour" {@attach attach}> <button type="button" class="btn btn-sm" commandfor="deploys-tour" command="--start"> Take the tour </button> <div class="toolbar" role="toolbar" aria-label="Deployments"> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-search" aria-label="Search"> <SearchIcon class="icon" /> </button> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-filter" aria-label="Filter"> <FilterIcon class="icon" /> </button> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-share" aria-label="Share"> <ShareIcon class="icon" /> </button> </div> <div class="coachmark-spotlight" popover="manual"></div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-search-title" data-target="#deploys-search"> <p class="coachmark-count">1 of 3</p> <h2 class="coachmark-title" id="deploys-search-title">Search every deployment</h2> <p class="coachmark-text">Find one by its branch, its commit or the person who shipped it.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-filter-title" data-target="#deploys-filter"> <p class="coachmark-count">2 of 3</p> <h2 class="coachmark-title" id="deploys-filter-title">Filter the list</h2> <p class="coachmark-text">Keep only the deployments of one branch, one author or one status.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-share-title" data-target="#deploys-share"> <p class="coachmark-count">3 of 3</p> <h2 class="coachmark-title" id="deploys-share-title">Share a deployment</h2> <p class="coachmark-text">Copy a link to it, open for anyone on the team.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="done">Done</button> </div> </div></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import SearchIcon from '@master/icons-vue/native/16/soft/search'import FilterIcon from '@master/icons-vue/native/16/soft/filter'import ShareIcon from '@master/icons-vue/native/16/soft/share'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <div ref="root" class="coachmark-tour flex items-center gap-sm" id="deploys-tour"> <button type="button" class="btn btn-sm" commandfor="deploys-tour" command="--start"> Take the tour </button> <div class="toolbar" role="toolbar" aria-label="Deployments"> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-search" aria-label="Search"> <SearchIcon class="icon" /> </button> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-filter" aria-label="Filter"> <FilterIcon class="icon" /> </button> <button type="button" class="btn btn-quiet btn-sm btn-square" id="deploys-share" aria-label="Share"> <ShareIcon class="icon" /> </button> </div> <div class="coachmark-spotlight" popover="manual"></div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-search-title" data-target="#deploys-search"> <p class="coachmark-count">1 of 3</p> <h2 class="coachmark-title" id="deploys-search-title">Search every deployment</h2> <p class="coachmark-text">Find one by its branch, its commit or the person who shipped it.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-filter-title" data-target="#deploys-filter"> <p class="coachmark-count">2 of 3</p> <h2 class="coachmark-title" id="deploys-filter-title">Filter the list</h2> <p class="coachmark-text"> Keep only the deployments of one branch, one author or one status. </p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="deploys-share-title" data-target="#deploys-share"> <p class="coachmark-count">3 of 3</p> <h2 class="coachmark-title" id="deploys-share-title">Share a deployment</h2> <p class="coachmark-text">Copy a link to it, open for anyone on the team.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="done">Done</button> </div> </div> </div></template>導覽可以像這裡一樣包住它所說明的區域,也可以只包含步驟和聚光燈:步驟可以在文件中的任何位置找到目標。關閉時,步驟和聚光燈不占空間,因此導覽本身可以就是它所在的那一列。
由提示點開啟的單則導覽提示不需要這些。它使用 popover="auto":點擊外部或按下 Esc 時,瀏覽器會關閉它並將焦點移回提示點,全程無須腳本。
#等待中的步驟
步驟可以等待讀者,也可以等待它的目標。
- 操作。 帶有
data-advance的步驟會指定目標上的某個事件(例如click),觸發時導覽便繼續。不要給它「下一步」:它要求讀者親自操作,等頁面回應後導覽才會繼續。「略過」和 Esc 仍可離開。 - 稍後才出現的目標。 當步驟的目標不在頁面中或尚未算繪時,步驟會等待它,並在它出現後立即開啟,例如由按鈕顯示的欄位,或仍在載入的列。目標在三秒後(或依行為的
wait設定的時間)仍未出現時,該步驟會被跳過;越過最後一個步驟時,導覽即算完成。導覽不會停在一張什麼都沒指到的卡片上,而無法顯示的步驟所包含的內容,應該讓讀者不靠它也能找到。
等待中的步驟
<div class="coachmark-tour flex flex-col items-center gap-md" id="projects-tour"> <div class="flex items-center gap-sm"> <button type="button" class="btn btn-sm" commandfor="projects-tour" command="--start"> Take the tour </button> <button type="button" class="btn btn-sm btn-primary" id="projects-new">New project</button> </div> <input class="input w(240)" id="projects-name" placeholder="Project name" aria-label="Project name" hidden> <div class="coachmark-spotlight" popover="manual"></div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="projects-new-title" data-target="#projects-new" data-advance="click"> <p class="coachmark-count">1 of 2</p> <h2 class="coachmark-title" id="projects-new-title">Start a project</h2> <p class="coachmark-text">Press New project. The tour goes on once its form is open.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="projects-name-title" data-target="#projects-name"> <p class="coachmark-count">2 of 2</p> <h2 class="coachmark-title" id="projects-name-title">Name it</h2> <p class="coachmark-text"> Use the name your team already calls it by. You can change it later. </p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="done">Done</button> </div> </div></div><script>document.getElementById('projects-new').addEventListener('click', function () { setTimeout(function () { document.getElementById('projects-name').hidden = false }, 400)})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>#聚光燈
coachmark-spotlight-dim 會用對話框的遮罩讓步驟目標周圍的頁面變暗,並讓目標及其周圍 4px 保持明亮,圓角為控制項的圓角加上這段內距。遮罩是一圈與畫面同寬的陰影,由聚光燈繪製,錨點定位讓聚光燈維持在目標上方,因此頁面捲動時遮罩會跟著目標移動。導覽開始時遮罩淡入,結束時淡出;從一個步驟換到下一個步驟時,明亮的位置會直接移動。
遮罩只是視覺效果,並不會阻擋操作:底下的頁面仍會回應指標和按鍵,讀者可以試用步驟所指的控制項,導覽也不會妨礙他們做其他事。第一次導覽某個畫面、需要引導視線時使用它;只是介紹一個新控制項的提示則不要使用。
聚光燈
<div class="coachmark-tour flex flex-col items-center gap-md" id="release-tour"> <button type="button" class="btn btn-sm" commandfor="release-tour" command="--start"> Take the tour </button> <div class="card flex-row items-center gap-md p-md w(300)"> <div class="flex flex-col grow(1)"> <span class="text-sm fg-text-strong">atlas.dev</span> <span class="text-xs fg-text-muted" id="release-status">Ready, 2 minutes ago</span> </div> <button type="button" class="btn btn-sm btn-primary" id="release-deploy">Deploy</button> </div> <div class="coachmark-spotlight coachmark-spotlight-dim" popover="manual"></div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-status-title" data-target="#release-status"> <p class="coachmark-count">1 of 2</p> <h2 class="coachmark-title" id="release-status-title">See where it stands</h2> <p class="coachmark-text">Each project says whether its last build is ready and when it ran.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-deploy-title" data-target="#release-deploy"> <p class="coachmark-count">2 of 2</p> <h2 class="coachmark-title" id="release-deploy-title">Ship it</h2> <p class="coachmark-text">Deploy sends the ready build to production.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="done">Done</button> </div> </div></div><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} className="coachmark-tour flex flex-col items-center gap-md" id="release-tour"> <button type="button" className="btn btn-sm" {...{ commandfor: 'release-tour', command: '--start' }}> Take the tour </button> <div className="card flex-row items-center gap-md p-md w(300)"> <div className="flex flex-col grow(1)"> <span className="text-sm fg-text-strong">atlas.dev</span> <span className="text-xs fg-text-muted" id="release-status">Ready, 2 minutes ago</span> </div> <button type="button" className="btn btn-sm btn-primary" id="release-deploy">Deploy</button> </div> <div className="coachmark-spotlight coachmark-spotlight-dim" popover="manual"></div> <div className="coachmark" popover="manual" role="dialog" aria-labelledby="release-status-title" data-target="#release-status"> <p className="coachmark-count">1 of 2</p> <h2 className="coachmark-title" id="release-status-title">See where it stands</h2> <p className="coachmark-text"> Each project says whether its last build is ready and when it ran. </p> <div className="coachmark-actions"> <button type="button" className="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" className="btn btn-sm" value="next">Next</button> </div> </div> <div className="coachmark" popover="manual" role="dialog" aria-labelledby="release-deploy-title" data-target="#release-deploy"> <p className="coachmark-count">2 of 2</p> <h2 className="coachmark-title" id="release-deploy-title">Ship it</h2> <p className="coachmark-text">Deploy sends the ready build to production.</p> <div className="coachmark-actions"> <button type="button" className="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" className="btn btn-sm" value="done">Done</button> </div> </div> </div> )}<script> import { attach } from '@master/ui/behaviors'</script><div class="coachmark-tour flex flex-col items-center gap-md" id="release-tour" {@attach attach}> <button type="button" class="btn btn-sm" commandfor="release-tour" command="--start"> Take the tour </button> <div class="card flex-row items-center gap-md p-md w(300)"> <div class="flex flex-col grow(1)"> <span class="text-sm fg-text-strong">atlas.dev</span> <span class="text-xs fg-text-muted" id="release-status">Ready, 2 minutes ago</span> </div> <button type="button" class="btn btn-sm btn-primary" id="release-deploy">Deploy</button> </div> <div class="coachmark-spotlight coachmark-spotlight-dim" popover="manual"></div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-status-title" data-target="#release-status"> <p class="coachmark-count">1 of 2</p> <h2 class="coachmark-title" id="release-status-title">See where it stands</h2> <p class="coachmark-text">Each project says whether its last build is ready and when it ran.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-deploy-title" data-target="#release-deploy"> <p class="coachmark-count">2 of 2</p> <h2 class="coachmark-title" id="release-deploy-title">Ship it</h2> <p class="coachmark-text">Deploy sends the ready build to production.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="done">Done</button> </div> </div></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" class="coachmark-tour flex flex-col items-center gap-md" id="release-tour"> <button type="button" class="btn btn-sm" commandfor="release-tour" command="--start"> Take the tour </button> <div class="card flex-row items-center gap-md p-md w(300)"> <div class="flex flex-col grow(1)"> <span class="text-sm fg-text-strong">atlas.dev</span> <span class="text-xs fg-text-muted" id="release-status">Ready, 2 minutes ago</span> </div> <button type="button" class="btn btn-sm btn-primary" id="release-deploy">Deploy</button> </div> <div class="coachmark-spotlight coachmark-spotlight-dim" popover="manual"></div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-status-title" data-target="#release-status"> <p class="coachmark-count">1 of 2</p> <h2 class="coachmark-title" id="release-status-title">See where it stands</h2> <p class="coachmark-text"> Each project says whether its last build is ready and when it ran. </p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="skip">Skip</button> <button type="button" class="btn btn-sm" value="next">Next</button> </div> </div> <div class="coachmark" popover="manual" role="dialog" aria-labelledby="release-deploy-title" data-target="#release-deploy"> <p class="coachmark-count">2 of 2</p> <h2 class="coachmark-title" id="release-deploy-title">Ship it</h2> <p class="coachmark-text">Deploy sends the ready build to production.</p> <div class="coachmark-actions"> <button type="button" class="btn btn-sm btn-quiet" value="back">Back</button> <button type="button" class="btn btn-sm" value="done">Done</button> </div> </div> </div></template>在強制色彩模式下不會繪製陰影,改以系統醒目提示色的外框標示目標。
#行為
tour 接收根元素(帶有 coachmark-tour 類別的元素),並回傳可卸載行為的函式。從 @master/ui/behaviors 匯入的 attach() 會找出頁面上的每個導覽。
import { tour } from '@master/ui/behaviors/tour.js'const root = document.querySelector('#deploys-tour')const deploys = tour(root)deploys.value = 0 // starts the tour, as the button doesroot.addEventListener('end', (event) => { if (event.detail.completed) localStorage.setItem('deploys-tour', 'seen')})- 值是導覽目前所在步驟的索引,從 0 開始;導覽未執行時為
null。設定它可開啟某個步驟,設為null則結束導覽;這兩種做法都不會派送事件。 - 事件。 每當導覽移到另一個步驟,根元素都會派送可向上冒泡的
change事件,索引放在detail.value。讀者結束導覽時,會先派送值為null的change,再派送end;讀者走完最後一個步驟時,其detail.completed為 true,在那之前透過「略過」、Esc 或其他關閉步驟的方式離開時則為 false。 - 焦點會在每個步驟開啟時移入其中:移到帶有
autofocus的操作,否則移到「下一步」或「完成」,再否則移到步驟本身。導覽結束時,焦點會回到導覽開始時的位置,除非讀者之後已把焦點移到頁面中的其他地方。 - 選項。
target(step, index)會找出步驟的目標,適用於自行持有目標的頁面;wait是步驟等待目標的時間,單位為毫秒,預設為 3000。 - 觸發指令。 瀏覽器不支援
command和commandfor時,行為會自行監聽開始按鈕的點擊。
沒有行為時,導覽不會開始;步驟保持關閉,頁面少了它們依然完整。請從 end 事件記住讀者已看完導覽,之後不要再自動開始:改由讀者日後找得到的按鈕提供。
#鍵盤操作
| 按鍵 | 動作 |
|---|---|
| Enter, Space | 在提示點上:開啟或關閉對應的導覽提示。在導覽步驟上:依按鈕 value 執行下一步、上一步、略過或完成。導覽提示開啟時,內部設有 autofocus 的操作會取得焦點;沒有這類操作的步驟則由步驟本身取得焦點 |
| Tab | 在導覽提示的操作控制項之間移動焦點,離開時回到頁面上提示點之後的位置。步驟不會鎖住焦點,開啟期間頁面仍可正常使用 |
| Escape | 關閉以 popover="auto" 開啟的導覽提示,並將焦點移回提示點。在導覽中,若焦點位於步驟內:以略過的方式結束導覽,並將焦點移回導覽開始時的位置 |
#無障礙
- 為導覽提示設定
role="dialog",並透過aria-labelledby以其標題作為名稱。這是非模態對話框,使用者仍可操作周圍的頁面;在操作導覽中,聚光燈下的頁面也一樣。 - 在由提示點開啟的導覽提示的主要操作按鈕上加上
autofocus,讓卡片開啟時焦點移入其中,使用者便可按 Enter 繼續。操作導覽的步驟則由行為移入焦點。 - 每個步驟都應能退出,可透過「略過」或「完成」按鈕,也可按 Esc。單則導覽提示還可透過點擊外部關閉。
- 從讀者的操作開始導覽,例如按下按鈕,絕不要在頁面載入時開始:導覽是輔助說明,不應搶走讀者原本要處理的工作的焦點。
- 導覽中的所有資訊都應能從其他地方取得,讓略過導覽的使用者,或遇到步驟被跳過時,也不會錯過任何內容。
- 在標記中將導覽提示緊接在提示點之後,這樣無論卡片顯示在哪裡,Tab 鍵都會在提示點之後進入導覽提示。
#React、Svelte 和 Vue
tour 元件會依資料中的每個項目寫出一個步驟,各含標題、文字、計數和所需的操作按鈕,並接收和傳出開啟中步驟的索引,以 onEnd 回報導覽結束。步驟的目標可以是選擇器、元素、ref,或找出目標的函式。使用 npx master-ui add tour 將元件複製到專案中;元件的實作方式與用法請見 React、Svelte 和 Vue。
#瀏覽器支援
導覽提示使用 CSS 錨點定位。卡片的位置由 position-area 和 position-try-fallbacks 決定,箭頭和操作導覽的聚光燈則使用 anchor() 相對於卡片與所指向的元素定位。瀏覽器若不支援錨點定位,導覽提示仍可開關,會依瀏覽器的彈出面板預設位置在檢視區置中顯示,並省略箭頭;聚光燈不會讓任何區域變暗,因為它無法讓目標保持明亮。showPopover() 的 source 選項為導覽步驟指定錨點。未提供此選項時,步驟會在沒有錨點的情況下開啟。開始按鈕使用觸發指令,瀏覽器不支援時由行為代為處理。淡入與短距離滑動使用 @starting-style,缺少支援時卡片和遮罩會立即出現或消失。
卡片進場時會淡入並朝錨點滑動 4px,退場時則以較短的時間淡出。卡片維持原尺寸,因為套用其他彈出面板的縮放效果會把箭頭縮進卡片範圍內,使箭頭無法伸向所指的元素。
#類別
| 類別 | 說明 |
|---|---|
coachmark | 以前景色為底的卡片,套用在具有 popover 屬性和 role="dialog" 的元素上,並以卡片標題作為無障礙名稱。卡片必須具有 popover 屬性才能顯示。卡片寬 18rem,開啟時置中於觸發元素下方,下方空間不足時改到上方。箭頭指向標記中緊鄰卡片之前的元素,因此請將卡片緊接在提示圓點或它所說明的控制項之後。 |
coachmark-top | 優先顯示在觸發元素上方,適合靠近畫面底部的控制項,或位於控制項上方一角的提示圓點。搭配 coachmark 使用 |
coachmark-count | 標題上方的一小行文字,使用較淡的前景色,可顯示導覽進度(第 2 步,共 4 步),或「新功能」等字樣。 |
coachmark-title | 步驟的標題,也是引導提示的無障礙名稱。 |
coachmark-text | 用一到兩句話說明控制項的用途。 |
coachmark-actions | 卡片底部的一排小按鈕,與卡片邊緣相距 12px。有多個按鈕時,第一個放在起始側(略過),其餘放在結束側(上一步、下一步)。預設按鈕以實心前景色突顯動作,低調按鈕則沿用卡片的前景色。 |
coachmark-tour | 依進行順序包住導覽的各個步驟(每個步驟都是設有 popover="manual" 的導覽提示)及其聚光燈。導覽行為會掛在此元素上;請為它設定 id,供開始導覽的按鈕指向。此元素本身不繪製任何內容,箭頭所指目標的錨點名稱也只在此範圍內有效 |
coachmark-spotlight | 空的 popover,導覽會在每個步驟開啟之前,先將它開在該步驟的目標上方。它涵蓋目標及周圍 4px;無論步驟位於標記中的哪個位置,開啟中步驟的箭頭都會指向它。單獨使用時不繪製任何內容,並讓指標操作穿透 |
coachmark-spotlight-dim | 以對話框的遮罩調暗目標周圍的頁面,目標本身保持明亮。遮罩下方的頁面仍可使用。在強制色彩模式下,改以系統醒目提示色的外框標示目標搭配 coachmark-spotlight 使用 |
coachmark-beacon | 以前景色顯示的 10px 圓點,標出步驟的位置,並透過 popovertarget 開啟對應的引導提示。圓點會不時發出向外擴散的圓環。指標停在圓點上、圓點取得焦點、對應的引導提示已開啟,或使用者偏好減少動態效果時,圓環會維持為靜止的光暈。操作區大小為 24px,觸控螢幕上為 44px。位置由頁面指定,通常位於所標記控制項的上方一角。 |
#自訂屬性
| 屬性 | 預設值 | 說明 |
|---|---|---|
--coachmark-width | 18rem | 卡片寬度,上限為檢視區寬度減去 1rem |
--coachmark-inset | 12px | 操作控制項到卡片邊緣的內距。文字的內距再多 4px。卡片的圓角半徑為小型按鈕的圓角半徑加上這段內距 |
--coachmark-arrow | 7px | 箭頭尖端突出卡片的距離 |
--anchored-gap | calc(var(--coachmark-arrow) + 6px) | 卡片與觸發元素之間的間距。箭頭尖端距離該元素 6px |
--coachmark-beacon-size | .625rem | 提示圓點的直徑。設定於 coachmark-beacon |
--coachmark-spotlight-inset | 4px | 聚光燈超出目標各邊的距離設定於 coachmark-spotlight |
--coachmark-spotlight-radius | var(--radius-control) | 所照亮目標的圓角半徑。聚光燈的圓角為此值加上外擴距離設定於 coachmark-spotlight |