Skip to content

Commit b2201bc

Browse files
champi-devapertureless
authored andcommitted
feat: ✨ Allow the usage of built-in input to be optional (#19)
Added the prop strengthMeterOnly to toggle the visibily of the input that's already inside the PasswordStrengthMeter component. This will allow users to use their own input element. For this to work both the user's input element and the password component must bound v-model to the same variable.
1 parent 02c9403 commit b2201bc

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Interactive password strength meter based on [zxcvbn](https://github.com/dropbox
9191
| strengthMeterClass | String | Password__strength-meter | strength-meter class |
9292
| strengthMeterFillClass | String | Password__strength-meter--fill | strength-meter class for individual data fills |
9393
| showStrengthMeter | Boolean | true | Hide the Strength Meter if you want to implement your own |
94+
| strengthMeterOnly | Boolean | false | Hides the built-in input if you want to implement your own |
9495

9596
## Events
9697

src/components/PasswordStrengthMeter.vue

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
<template>
22
<div class="Password">
3-
<div class="Password__group">
3+
<div
4+
v-if="!strengthMeterOnly"
5+
class="Password__group"
6+
>
47
<input
58
:type="inputType"
69
:ref="referanceValue"
7-
v-bind:value="value"
8-
v-on:input="emitValue($event.target.value)"
910
:class="[defaultClass, disabled ? disabledClass : '']"
1011
:name="name"
1112
:id="id"
1213
:placeholder="placeholder"
1314
:required="required"
1415
:disabled="disabled"
16+
v-bind:value="value"
17+
@input="evt => emitValue(evt.target.value)"
1518
>
1619
<div class="Password__icons">
1720
<div
@@ -157,6 +160,16 @@
157160
type: Boolean,
158161
default: true
159162
},
163+
/**
164+
* Prop to toggle the
165+
* input element if
166+
* User wants to implement
167+
* their own input element
168+
*/
169+
strengthMeterOnly: {
170+
type: Boolean,
171+
default: false
172+
},
160173
/**
161174
* CSS Class for the Input field
162175
* @type {String}
@@ -222,14 +235,6 @@
222235
},
223236
224237
methods: {
225-
/**
226-
* Emit passowrd value to parent component
227-
* @param {String} value password typed in
228-
*/
229-
emitValue (value) {
230-
this.password = value
231-
this.$emit('input', value)
232-
},
233238
togglePassword () {
234239
if (this.$data._showPassword) {
235240
this.$emit('hide')
@@ -238,6 +243,10 @@
238243
this.$emit('show')
239244
this.$data._showPassword = true
240245
}
246+
},
247+
emitValue (value) {
248+
this.$emit('input', value)
249+
this.password = value
241250
}
242251
},
243252
@@ -290,6 +299,11 @@
290299
},
291300
292301
watch: {
302+
value (newValue) {
303+
if (this.strengthMeterOnly) {
304+
this.emitValue(newValue)
305+
}
306+
},
293307
passwordStrength (score) {
294308
this.$emit('score', score)
295309
this.$emit('feedback', zxcvbn(this.password).feedback)

0 commit comments

Comments
 (0)