Last active
May 30, 2019 15:10
-
-
Save tsmd/ced9fcd31245caed9bc078c491368a26 to your computer and use it in GitHub Desktop.
Cool textarea
This file contains hidden or 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
| @charset "UTF-8"; | |
| .Textarea { | |
| @at-root { | |
| & { | |
| position: relative; | |
| color: inherit; | |
| font-size: rem(16px); | |
| line-height: 1.8; | |
| } | |
| .Textarea__dummy { | |
| display: none; | |
| overflow: hidden; | |
| visibility: hidden; | |
| min-height: rem(120px); | |
| padding: rem(4px) rem(14px); | |
| white-space: pre-wrap; | |
| word-wrap: break-word; | |
| overflow-wrap: break-word; | |
| border: 1px solid; | |
| } | |
| .Textarea__textarea { | |
| display: block; | |
| width: 100%; | |
| height: rem(120px); | |
| padding: rem(4px) rem(14px); | |
| border: 1px solid $color-gray30; | |
| border-radius: 4px; | |
| font: inherit; | |
| line-height: inherit; | |
| resize: vertical; | |
| } | |
| &.-flex { | |
| .Textarea__dummy { | |
| display: block; | |
| } | |
| .Textarea__textarea { | |
| position: absolute; | |
| top: 0; | |
| right: 0; | |
| left: 0; | |
| //height: auto; | |
| height: 100%; | |
| overflow: hidden; | |
| resize: none; | |
| } | |
| } | |
| // ------------------------------------------------------ | |
| // States | |
| // | |
| .Textarea__textarea:invalid { | |
| outline: 0; // ブラウザ規定の invalid スタイルを打ち消し | |
| box-shadow: none; // ブラウザ規定の invalid スタイルを打ち消し | |
| .-invalid & { | |
| border: 1px solid $color-alert; | |
| } | |
| } | |
| &.-invalid { | |
| .Textarea__textarea { | |
| border: 1px solid $color-alert; | |
| } | |
| } | |
| .Textarea__textarea:disabled { | |
| color: $color-gray40; | |
| border: 0; | |
| background-color: $color-gray10; | |
| } | |
| .Textarea__textarea:focus { | |
| background-color: #fff; | |
| box-shadow: 0 0 0 4px $color-primary-10; | |
| outline: 0; | |
| } | |
| } | |
| } |
This file contains hidden or 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
| import { Controller } from 'stimulus' | |
| /** | |
| * 内容物に応じて大きさが変わる Textarea | |
| */ | |
| export default class extends Controller { | |
| static get targets() { | |
| return ['dummy'] | |
| } | |
| update(e) { | |
| this.dummyTarget.textContent = e.target.value + '\u200b' | |
| } | |
| } |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html lang="ja"> | |
| <title>TextInput</title> | |
| <div class="Textarea"> | |
| <textarea class="Textarea__textarea"></textarea> | |
| </div> | |
| <div class="Textarea -flex" data-controller="flex-textarea"> | |
| <div class="Textarea__dummy" aria-hidden="true" data-target="flex-textarea.dummy"></div> | |
| <textarea class="Textarea__textarea" data-action="input->flex-textarea#update"></textarea> | |
| </div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment