Skip to content

Commit

Permalink
add conditional classes when input is complete and also for each input
Browse files Browse the repository at this point in the history
  • Loading branch information
ejirocodes committed Apr 25, 2022
1 parent dd54d66 commit 018c04b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions dev/serve.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default defineComponent({
<vue3-otp-input
ref="otpInput0"
input-classes="otp-input"
:conditionalClass="['one', 'two', 'three', 'four']"
separator="-"
inputType="number"
:num-inputs="4"
Expand All @@ -49,6 +50,9 @@ export default defineComponent({
border: 1px solid rgba(0, 0, 0, 0.3);
text-align: center;
}
.otp-input.is-complete {
background-color: #e4e4e4;
}
.otp-input.error {
border: 1px solid red !important;
}
Expand Down
5 changes: 4 additions & 1 deletion src/single-otp-input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
maxlength="1"
pattern="[0-9]"
v-model="model"
:class="inputClasses"
:class="[inputClasses, conditionalClass, { 'is-complete': model }]"
@input="handleOnChange"
@keydown="handleOnKeyDown"
@paste="handleOnPaste"
Expand Down Expand Up @@ -45,6 +45,9 @@ export default defineComponent({
inputClasses: {
type: String,
},
conditionalClass: {
type: String,
},
shouldAutoFocus: {
type: Boolean,
},
Expand Down
5 changes: 5 additions & 0 deletions src/vue3-otp-input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export default /* #__PURE__ */ defineComponent({
inputClasses: {
type: String,
},
conditionalClass: {
type: Array,
},
inputType: {
type: String,
validator: (value: string) =>
Expand Down Expand Up @@ -188,6 +191,7 @@ export default /* #__PURE__ */ defineComponent({
:separator="separator"
:input-type="inputType"
:input-classes="inputClasses"
:conditionalClass="conditionalClass[i]"
:is-last-child="i === numInputs - 1"
:should-auto-focus="shouldAutoFocus"
:placeholder="placeholder[i]"
Expand All @@ -199,6 +203,7 @@ export default /* #__PURE__ */ defineComponent({
@on-blur="handleOnBlur"
/>
</div>
{{ otp }}
</template>

<style scoped></style>

0 comments on commit 018c04b

Please sign in to comment.