-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Autofill shadow dom test page (#183)
* Easier navigation between autofill pages Signed-off-by: Emanuele Feliziani <feliziani.emanuele@gmail.com> * Add autofill shadow dom test page Signed-off-by: Emanuele Feliziani <feliziani.emanuele@gmail.com> * Use a nested shadow tree Signed-off-by: Emanuele Feliziani <feliziani.emanuele@gmail.com> --------- Signed-off-by: Emanuele Feliziani <feliziani.emanuele@gmail.com>
- Loading branch information
1 parent
f56ef13
commit 90c0e45
Showing
15 changed files
with
123 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<title>Autofill: form in a nested shadow DOM</title> | ||
<link rel="stylesheet" href="../style.css" /> | ||
</head> | ||
|
||
<body> | ||
<p><a href="../../index.html#autofill">[Home]</a></p> | ||
|
||
<p id="demo"></p> | ||
|
||
<div class=""> | ||
<p>Form in shadow DOM created after click.</p> | ||
|
||
<div class="dialog"> | ||
<shadow-component></shadow-component> | ||
</div> | ||
<script> | ||
class ShadowComponent extends HTMLElement { | ||
constructor () { | ||
super(); | ||
|
||
// Create a shadow root | ||
const shadowRoot = this.attachShadow({ mode: 'open' }); | ||
|
||
// Apply some styles to the shadow DOM | ||
shadowRoot.innerHTML += ` | ||
<style> | ||
div { | ||
padding: 20px; | ||
background-color: #f0f0f0; | ||
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2); | ||
} | ||
</style> | ||
`; | ||
|
||
// 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.type = 'button'; | ||
div.appendChild(initialButton); | ||
shadowRoot.appendChild(div); | ||
|
||
initialButton.addEventListener('click', () => { | ||
initialButton.outerHTML = '<custom-form></custom-form>'; | ||
}); | ||
} | ||
} | ||
|
||
// Define the custom element "shadow-component" | ||
customElements.define('shadow-component', ShadowComponent); | ||
|
||
class Form extends HTMLElement { | ||
constructor () { | ||
super(); | ||
|
||
// Create a shadow root | ||
const shadowRoot = this.attachShadow({ mode: 'open' }); | ||
|
||
// Append the form to the shadow root | ||
this.shadowRoot.innerHTML = ` | ||
<form id="click-form" novalidate action="./shadow-dom.html"> | ||
<h3>Sign up form</h3> | ||
<fieldset> | ||
<label for="email">Email</label> | ||
<input id="email" type="email"> | ||
<label for="password">Password</label> | ||
<input id="password" type="password" autocomplete="new-password"> | ||
<button type="submit">Sign up</button> | ||
</fieldset> | ||
</form> | ||
`; | ||
const clickForm = shadowRoot.getElementById('click-form'); | ||
const button = clickForm?.querySelector('button'); | ||
const handler = (e) => { | ||
e.preventDefault(); | ||
e.stopImmediatePropagation(); | ||
alert('Success'); | ||
}; | ||
button?.addEventListener('click', handler, true); | ||
clickForm?.addEventListener('submit', handler, true); | ||
} | ||
} | ||
|
||
// Define the custom element | ||
customElements.define('custom-form', Form); | ||
</script> | ||
</div> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters