-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdialog-example.html
More file actions
54 lines (46 loc) · 1.82 KB
/
dialog-example.html
File metadata and controls
54 lines (46 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dialog example</title>
<style>
#login-dialog::backdrop {
background: rgb(0 0 0 / 32%);
}
</style>
</head>
<body>
<button>Just</button>
<a id="login-anchor" href="#login">Login</a>
<button>button</button>
<h1>모달? <dialog> 요소가 답!</h1>
<p>모달 대화 상자에 <dialog> 요소를 사용하면 개발 효율과 접근성 품질 문제를 한 번에 해결해 준다.</p>
<ul>
<li>첫째, 내장되어 있는 ::backdrop 요소 사용 가능.</li>
<li>둘째, 접근성 있는 키보드 문맥 형성.</li>
<li>셋째, ESC 키 자동 맵핑.</li>
</ul>
<p>키보드 문맥을 자세히 설명하면; 모달이 열렸을 때 모달 안으로 초점을 옮겨주고, 모달이 열려있는 동안 모달 안에 초점을 가두고, 모달을 닫을 때 모달 이전 요소로 초점을 돌려 놓는다.</p>
<dialog id="login-dialog">
<h2>Login</h2>
<fieldset>
<input type="text" aria-label="ID" placeholder="abc@xyz.com">
<input type="password" aria-label="Password" placeholder="********">
<button>Login</button>
</fieldset>
<button id="close-btn">Close</button>
</dialog>
<script>
const loginAnchor = document.getElementById('login-anchor');
const loginDialog = document.getElementById('login-dialog');
const closeBtn = document.getElementById('close-btn');
loginAnchor.addEventListener('click', () => {
loginDialog.showModal();
});
closeBtn.addEventListener('click', () => {
loginDialog.close();
});
</script>
</body>
</html>