当我从中运行代码时......
var updateButton = document.getElementById('updateDetails');
var favDialog = document.getElementById('favDialog');
var outputBox = document.querySelector('output');
var selectEl = document.querySelector('select');
var confirmBtn = document.getElementById('confirmBtn');
// "Update details" button opens the <dialog> modally
updateButton.addEventListener('click', function onOpen() {
if (typeof favDialog.showModal === "function") {
favDialog.showModal();
} else {
alert("The <dialog> API is not supported by this browser");
}
});
// "Favorite animal" input sets the value of the submit button
selectEl.addEventListener('change', function onSelect(e) {
confirmBtn.value = selectEl.value;
});
// "Confirm" button of form triggers "close" on dialog because of [method="dialog"]
favDialog.addEventListener('close', function onClose() {
outputBox.value = favDialog.returnValue + " button clicked - " + (new Date()).toString();
});
<!-- Simple pop-up dialog box containing a form -->
<dialog id="favDialog">
<form method="dialog">
<p><label>Favorite animal:
<select>
<option></option>
<option>Brine shrimp</option>
<option>Red panda</option>
<option>Spider monkey</option>
</select>
</label></p>
<menu>
<button value="cancel">Cancel</button>
<button id="confirmBtn" value="default">Confirm</button>
</menu>
</form>
</dialog>
<menu>
<button id="updateDetails">Update details</button>
</menu>
<output aria-live="polite"></output>
...我发现当对话框打开时,焦点并不像ARIA 模式示例描述的那样完全“陷入”。他们说当用户按下 Tab 键时:
当焦点位于对话框中最后一个可聚焦元素上时,将焦点移动到对话框中第一个可聚焦元素。
然而,对话框元素的 MDN 示例允许用户“跳出”模式并进入浏览器框架。就我而言,使用 Chrome,在确认按钮按下选项卡后,将聚焦于“查看站点信息”按钮,然后聚焦于文档区域之外的地址栏。
这里发生了什么。MDN 的示例不完整吗?为了<dialog>
在生产中使用该元素,Web 开发人员是否需要编写额外的 JS 代码来真正聚焦陷阱?或者从可访问性的角度来看,允许模式部分捕获焦点(如示例中所示)是否“可接受”,其中选项卡上的按键可以暂时转义到浏览器 UI 元素。
森栏
DIEA
相关分类