Skip to content

Commit

Permalink
Autofill shadow dom follow up (#184)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
GioSensation authored Jan 30, 2024
1 parent 90c0e45 commit 340bca2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
58 changes: 36 additions & 22 deletions autofill/autoprompt/2-form-in-modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,55 @@
</ul>
</nav>

<p id="demo"></p>
<p id="demo"><button type="button" id="open-modal">Click here to open dialog</button></p>

<p id="random-text">Some random text to use as "something outside the dialog element". Clicking here should close the dialog (if open).</p>

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

<div class="dialog">
<p><button type="button">Click here to login</button></p>
</div>
<script>
const initialButton = document.querySelector('button');
initialButton.addEventListener('click', () => {
const formEl = `<form id="click-form" novalidate action="3-multistep-form.html">
<h3>Sign in form dia</h3>
<div class="dialog" hidden></div>
</div>

<script type="module">
const initialButton = document.querySelector('button');
const dialogEl = document.querySelector('.dialog');
initialButton.addEventListener('click', () => {
const formEl = `<form id="login" novalidate action="3-multistep-form.html">
<h3>Sign in form</h3>
<fieldset>
<label for="email">Email</label>
<input id="email" type="email">
<label for="password">Password</label>
<input id="password" type="password">
<button type="submit">Sign in</button>
<button type="submit">Log in</button>
</fieldset>
</form>`
initialButton.outerHTML = formEl;
const clickForm = document.getElementById('click-form');
const button = clickForm?.querySelector('button');
</form>`;
dialogEl.innerHTML = formEl;
dialogEl.removeAttribute('hidden');
window.addEventListener('keydown', (e) => {
if (e.key === 'Escape') { dialogEl.setAttribute('hidden', ''); }
});
window.addEventListener('pointerdown', (e) => {
if (!dialogEl.contains(e.target)) { dialogEl.setAttribute('hidden', ''); }
});

const loginForm = document.getElementById('login');
const button = loginForm?.querySelector('button');
const handler = (e) => {
e.preventDefault();
e.stopImmediatePropagation();
window.location.href = '3-multistep-form.html';
e.preventDefault();
e.stopImmediatePropagation();
// window.location.href = '3-multistep-form.html';
if (loginForm.checkValidity()) {
setTimeout(() => {
dialogEl.innerHTML = '<h1>Submitted!</h1>';
}, 100);
}
};
button?.addEventListener('click', handler, true);
clickForm?.addEventListener('submit', handler, true);
});
</script>
</div>

loginForm?.addEventListener('submit', handler, true);
});
</script>
</body>

</html>
4 changes: 2 additions & 2 deletions autofill/shadow-dom.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<p id="demo"></p>

<div class="">
<p>Form in shadow DOM created after click.</p>
<p>Form in nested shadow DOM created after click.</p>

<div class="dialog">
<shadow-component></shadow-component>
Expand All @@ -41,7 +41,7 @@
// Create a div element inside the shadow root
const div = document.createElement('div');
const initialButton = document.createElement('button');
initialButton.textContent = 'Click here to login';
initialButton.textContent = 'Click here to sign up';
initialButton.type = 'button';
div.appendChild(initialButton);
shadowRoot.appendChild(div);
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "privacy-test-pages",
"name": "@duckduckgo/privacy-test-pages",
"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.",
"main": "server.js",
"engines": {
Expand Down

0 comments on commit 340bca2

Please sign in to comment.