Skip to content

Commit 674bd6c

Browse files
committed
make type attribute optional
by setting it internally
1 parent b99c927 commit 674bd6c

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

demo.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
<br>
1717

1818
<label for="password_confirm">Confirm Password</label>
19-
<input autocomplete="none" data-1p-ignore type="password" name="password_confirm" id="password_confirm" is="x-password" value="hidden" confirm-target="password">
19+
<input autocomplete="none" data-1p-ignore name="password_confirm" id="password_confirm" is="x-password" value="hidden" confirm-target="password">
2020

2121
<br>
2222

2323
<label for="password_confirm">Visible Password</label>
24-
<input autocomplete="none" data-1p-ignore type="password" name="visibile_password" id="visibile_password" is="x-password" value="not hidden" visible>
24+
<input autocomplete="none" data-1p-ignore name="visibile_password" id="visibile_password" is="x-password" value="not hidden" visible>
2525

2626
<br>
2727

readme.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# &lt;x-password&gt;
2-
31
A password input natively enhanced via a Custom Element (Web Component).
42

53
It adds the ability to toggle visibility and validation to confirm it matches the value of another field
@@ -11,7 +9,7 @@ It adds the ability to toggle visibility and validation to confirm it matches th
119
## Usage
1210

1311
```html
14-
<script src="" type="module"></script>
12+
<script src="https://tobz-nz.github.io/x-password/x-password.js" type="module"></script>
1513

1614
<form onsubmit="return false">
1715
<label for="password">Password</label>
@@ -20,7 +18,7 @@ It adds the ability to toggle visibility and validation to confirm it matches th
2018
<br>
2119

2220
<label for="password_confirm">Confirm Password</label>
23-
<input type="password" name="password_confirm" id="password_confirm" is="x-password" confirm-target="password">
21+
<input is="x-password" name="password_confirm" id="password_confirm" confirm-target="password">
2422

2523
<br>
2624

x-password.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
customElements.define('x-password', class extends HTMLInputElement {
22
static get observedAttributes() {
3-
return ["visible"]
3+
return ['visible']
44
}
55

66
constructor() {
@@ -18,6 +18,10 @@ customElements.define('x-password', class extends HTMLInputElement {
1818
}
1919

2020
connectedCallback() {
21+
if (!this.getAttribute('type')) {
22+
this.setAttribute('type', 'password')
23+
}
24+
2125
if (this.hasAttribute('confirm-target')) {
2226
const confirmTarget = document.getElementById(this.getAttribute('confirm-target'))
2327

0 commit comments

Comments
 (0)