-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(html): Add example of
is
global attribute (#2234)
- Loading branch information
1 parent
49e2095
commit ad63bb9
Showing
4 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
live-examples/html-examples/global-attributes/attribute-is.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<p>Please describe why would you like to work for us:</p> | ||
|
||
<div class="length-textarea-container"> | ||
<textarea is="length-left-textarea" maxLength="150">I would like to work for you because…</textarea> | ||
</div> |
19 changes: 19 additions & 0 deletions
19
live-examples/html-examples/global-attributes/css/attribute-is.css
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,19 @@ | ||
textarea { | ||
width: 100%; | ||
height: 100%; | ||
resize: none; | ||
} | ||
|
||
.length-textarea-container { | ||
position: relative; | ||
width: 100%; | ||
height: 10em; | ||
} | ||
|
||
.length-textarea-container::after { | ||
content: 'Characters left: ' attr(length-left); | ||
position: absolute; | ||
bottom: 5px; | ||
right: 5px; | ||
color: grey; | ||
} |
18 changes: 18 additions & 0 deletions
18
live-examples/html-examples/global-attributes/js/attribute-is.js
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,18 @@ | ||
class LengthLeftTextarea extends HTMLTextAreaElement { | ||
constructor() { | ||
super(); | ||
|
||
const updateLengthAttribute = (newContent) => { | ||
const length = newContent ? newContent.length : 0; | ||
const lengthLeft = this.maxLength - length; | ||
this.parentNode.setAttribute('length-left', lengthLeft); | ||
}; | ||
|
||
updateLengthAttribute(this.value); | ||
this.addEventListener('input', (e) => { | ||
updateLengthAttribute(e.target.value); | ||
}); | ||
} | ||
} | ||
|
||
customElements.define('length-left-textarea', LengthLeftTextarea, { extends: 'textarea' }); |
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