Skip to content

Commit 340bca2

Browse files
authored
Autofill shadow dom follow up (#184)
* Stupid minor text changes Signed-off-by: Emanuele Feliziani <[email protected]> * Update the form in modal Signed-off-by: Emanuele Feliziani <[email protected]> * Update package name Signed-off-by: Emanuele Feliziani <[email protected]> --------- Signed-off-by: Emanuele Feliziani <[email protected]>
1 parent 90c0e45 commit 340bca2

File tree

4 files changed

+41
-26
lines changed

4 files changed

+41
-26
lines changed

autofill/autoprompt/2-form-in-modal.html

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,55 @@
2020
</ul>
2121
</nav>
2222

23-
<p id="demo"></p>
23+
<p id="demo"><button type="button" id="open-modal">Click here to open dialog</button></p>
24+
25+
<p id="random-text">Some random text to use as "something outside the dialog element". Clicking here should close the dialog (if open).</p>
2426

2527
<div class="">
2628
<p>Form created in modal after click (<b>should not prompt automatically</b>).</p>
2729

28-
<div class="dialog">
29-
<p><button type="button">Click here to login</button></p>
30-
</div>
31-
<script>
32-
const initialButton = document.querySelector('button');
33-
initialButton.addEventListener('click', () => {
34-
const formEl = `<form id="click-form" novalidate action="3-multistep-form.html">
35-
<h3>Sign in form dia</h3>
30+
<div class="dialog" hidden></div>
31+
</div>
32+
33+
<script type="module">
34+
const initialButton = document.querySelector('button');
35+
const dialogEl = document.querySelector('.dialog');
36+
initialButton.addEventListener('click', () => {
37+
const formEl = `<form id="login" novalidate action="3-multistep-form.html">
38+
<h3>Sign in form</h3>
3639
<fieldset>
3740
<label for="email">Email</label>
3841
<input id="email" type="email">
3942
<label for="password">Password</label>
4043
<input id="password" type="password">
41-
<button type="submit">Sign in</button>
44+
<button type="submit">Log in</button>
4245
</fieldset>
43-
</form>`
44-
initialButton.outerHTML = formEl;
45-
const clickForm = document.getElementById('click-form');
46-
const button = clickForm?.querySelector('button');
46+
</form>`;
47+
dialogEl.innerHTML = formEl;
48+
dialogEl.removeAttribute('hidden');
49+
window.addEventListener('keydown', (e) => {
50+
if (e.key === 'Escape') { dialogEl.setAttribute('hidden', ''); }
51+
});
52+
window.addEventListener('pointerdown', (e) => {
53+
if (!dialogEl.contains(e.target)) { dialogEl.setAttribute('hidden', ''); }
54+
});
55+
56+
const loginForm = document.getElementById('login');
57+
const button = loginForm?.querySelector('button');
4758
const handler = (e) => {
48-
e.preventDefault();
49-
e.stopImmediatePropagation();
50-
window.location.href = '3-multistep-form.html';
59+
e.preventDefault();
60+
e.stopImmediatePropagation();
61+
// window.location.href = '3-multistep-form.html';
62+
if (loginForm.checkValidity()) {
63+
setTimeout(() => {
64+
dialogEl.innerHTML = '<h1>Submitted!</h1>';
65+
}, 100);
66+
}
5167
};
5268
button?.addEventListener('click', handler, true);
53-
clickForm?.addEventListener('submit', handler, true);
54-
});
55-
</script>
56-
</div>
57-
69+
loginForm?.addEventListener('submit', handler, true);
70+
});
71+
</script>
5872
</body>
5973

6074
</html>

autofill/shadow-dom.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<p id="demo"></p>
1515

1616
<div class="">
17-
<p>Form in shadow DOM created after click.</p>
17+
<p>Form in nested shadow DOM created after click.</p>
1818

1919
<div class="dialog">
2020
<shadow-component></shadow-component>
@@ -41,7 +41,7 @@
4141
// Create a div element inside the shadow root
4242
const div = document.createElement('div');
4343
const initialButton = document.createElement('button');
44-
initialButton.textContent = 'Click here to login';
44+
initialButton.textContent = 'Click here to sign up';
4545
initialButton.type = 'button';
4646
div.appendChild(initialButton);
4747
shadowRoot.appendChild(div);

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "privacy-test-pages",
2+
"name": "@duckduckgo/privacy-test-pages",
33
"description": "This project contains a collection of pages that are meant to be used for testing various privacy and security features of browsers and browser extensions.",
44
"main": "server.js",
55
"engines": {

0 commit comments

Comments
 (0)