Skip to content

Commit 8f414cf

Browse files
Fix error and success states
Signed-off-by: Marco Ambrosini <marcoambrosini@icloud.com>
1 parent c8fef5b commit 8f414cf

2 files changed

Lines changed: 28 additions & 26 deletions

File tree

src/components/InputField/InputField.vue

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
:class="{
3939
'input-field__input--trailing-icon': showTrailingButton || hasTrailingIcon,
4040
'input-field__input--leading-icon': hasLeadingIcon,
41+
'input-field__input--success': success,
42+
'input-field__input--error': error,
4143
}"
4244
:value="value"
4345
v-on="$listeners"
@@ -49,9 +51,10 @@
4951
<slot />
5052
</div>
5153

52-
<!-- Success icon -->
53-
<div v-if="success" class="input-field__icon input-field__icon--trailing">
54-
<Check :size="18" />
54+
<!-- Success and error icons -->
55+
<div v-if="success || error" class="input-field__icon input-field__icon--trailing">
56+
<Check v-if="success" :size="18" />
57+
<AlertCircle v-else-if="error" :size="18" />
5558
</div>
5659

5760
<!-- trailing button -->
@@ -72,6 +75,7 @@
7275
<script>
7376
import Button from '../Button/index.js'
7477
import Check from 'vue-material-design-icons/Check'
78+
import AlertCircle from 'vue-material-design-icons/AlertCircleOutline'
7579
import GenRandomId from '../../utils/GenRandomId.js'
7680
7781
export default {
@@ -80,6 +84,7 @@ export default {
8084
components: {
8185
Button,
8286
Check,
87+
AlertCircle,
8388
},
8489
8590
props: {
@@ -193,18 +198,6 @@ export default {
193198
},
194199
195200
watch: {
196-
/**
197-
* Don't allow both trailing checkmark and clear button to be present
198-
* at the same time
199-
*/
200-
success() {
201-
this.validateTrailingIcon()
202-
},
203-
204-
canClear() {
205-
this.validateTrailingIcon()
206-
},
207-
208201
label() {
209202
this.validateLabel()
210203
},
@@ -223,12 +216,6 @@ export default {
223216
this.$emit('trailing-button-click', event)
224217
},
225218
226-
validateTrailingIcon() {
227-
if (this.canClear && this.success) {
228-
throw new Error('success and canClear props cannot be true at the same time')
229-
}
230-
},
231-
232219
validateLabel() {
233220
if (this.label && !this.labelOutside) {
234221
throw new Error('You need to add a label to the textField component. Either use the prop label or use an external one, as per the example in the documentation')
@@ -273,6 +260,14 @@ export default {
273260
cursor: text;
274261
}
275262
263+
&--success {
264+
border-color: var(--color-success) !important; //Override hover border color
265+
}
266+
267+
&--error {
268+
border-color: var(--color-error) !important; //Override hover border color
269+
}
270+
276271
&--leading-icon {
277272
padding-left: 28px;
278273
}

src/components/TextField/TextField.vue

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,34 @@ and `minlength`.
3131
<template>
3232
<div class="wrapper">
3333
<TextField :value.sync="text1"
34-
label="Type something here"
34+
label="Leading icon and trailing button"
3535
trailing-button-icon="close"
3636
:show-trailing-button="text1 !== ''"
3737
@trailing-button-click="clearText">
3838
<Magnify :size="16" />
3939
</TextField>
4040
<TextField :value.sync="text2"
41-
label="Type something here"
41+
label="Success state"
4242
:success="true"
4343
@trailing-button-click="clearText">
4444
</TextField>
4545
<TextField :value.sync="text3"
46-
label="Type something here"
46+
label="Error state"
47+
:error="true"
48+
@trailing-button-click="clearText">
49+
</TextField>
50+
<TextField :value.sync="text4"
51+
label="Internal label"
52+
placeholder="That can be used together with placeholder"
4753
:label-visible="true"
4854
trailing-button-icon="close"
49-
:show-trailing-button="text3 !== ''"
55+
:show-trailing-button="text4 !== ''"
5056
@trailing-button-click="clearText">
5157
<Lock :size="16" />
5258
</TextField>
5359
<div class="external-label">
5460
<label for="$refs.textField.id">External label</label>
55-
<TextField :value.sync="text4"
61+
<TextField :value.sync="text5"
5662
ref="textField"
5763
:label-outside= "true"
5864
@trailing-button-click="clearText" />
@@ -71,6 +77,7 @@ export default {
7177
text2: '',
7278
text3: '',
7379
text4: '',
80+
text5: '',
7481
}
7582
},
7683

0 commit comments

Comments
 (0)