Skip to content

Commit f3edec2

Browse files
authored
feat(input): add help/descriptor text (#516)
## Feature * feat(input): add help/descriptor text ## Chore * chore: increment version
1 parent afc0d29 commit f3edec2

File tree

6 files changed

+132
-4
lines changed

6 files changed

+132
-4
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@karnama/vueish",
3-
"version": "0.18.0",
3+
"version": "0.19.0",
44
"files": [
55
"dist",
66
"types"

src/assets/styles/main.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,13 @@
4242
color: theme('colors.red.500') !important;
4343
}
4444
}
45+
46+
.ui-error-text {
47+
@extend .text-color-error;
48+
@apply text-sm mt-1;
49+
}
50+
51+
.ui-help-text {
52+
@extend .text-color-muted;
53+
@apply text-gray-400 text-sm mt-1;
54+
}

src/components/input/Demo.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,27 @@
175175
type="number"
176176
placeholder="Placeholder text."
177177
label="Placeholder" />
178+
179+
<UIInput v-model="helpProp"
180+
:error="error"
181+
:small="small"
182+
:loading="loading"
183+
name="ui-text15"
184+
class="mt-10"
185+
help="Descriptive message..."
186+
label="Help (prop)" />
187+
188+
<UIInput v-model="helpSlot"
189+
:error="error"
190+
:small="small"
191+
:loading="loading"
192+
name="ui-text15"
193+
class="mt-10"
194+
label="Help (slot)">
195+
<template #help>
196+
<span class="underline ui-help-text">Descriptive message...</span>
197+
</template>
198+
</UIInput>
178199
</div>
179200
</template>
180201

@@ -200,6 +221,8 @@ export default defineComponent({
200221
const suffixProp = ref('100');
201222
const suffixSlot = ref('Feather-weight');
202223
const placeholder = ref<number|null>(null);
224+
const helpProp = ref('I\'m an input!');
225+
const helpSlot = ref('I\'m an input!');
203226
const large = ref(false);
204227
const small = ref(false);
205228
const error = ref('');
@@ -224,6 +247,8 @@ export default defineComponent({
224247
suffixProp,
225248
suffixSlot,
226249
placeholder,
250+
helpProp,
251+
helpSlot,
227252
large,
228253
error,
229254
loading,

src/components/input/UIInput.test.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,83 @@ describe('UIInput', () => {
320320
expect(wrapper.lastEventValue()).toBeUndefined();
321321
});
322322
});
323+
324+
it('should display the error text when passed as a slot', () => {
325+
const error = 'error';
326+
const errorContainer = `<span id="error">${error}</span>`;
327+
328+
const wrapper = mount(UIInput, {
329+
props: {
330+
modelValue: '',
331+
name: 'input'
332+
},
333+
slots: {
334+
error: errorContainer
335+
}
336+
});
337+
338+
expect(wrapper.get('#error').text()).toBe(error);
339+
});
340+
341+
it('should display the error text when passed as a prop', () => {
342+
const error = 'error';
343+
344+
const wrapper = mount(UIInput, {
345+
props: {
346+
modelValue: '',
347+
name: 'input',
348+
error
349+
}
350+
});
351+
352+
expect(wrapper.get('.ui-error-text').text()).toBe(error);
353+
});
354+
355+
it('should display the help text when passed as a slot', () => {
356+
const help = 'help';
357+
const helpContainer = `<span id="help">${help}</span>`;
358+
359+
const wrapper = mount(UIInput, {
360+
props: {
361+
modelValue: '',
362+
name: 'input'
363+
},
364+
slots: {
365+
help: helpContainer
366+
}
367+
});
368+
369+
expect(wrapper.get('#help').text()).toBe(help);
370+
});
371+
372+
it('should display the help text when passed as a prop', () => {
373+
const help = 'help';
374+
375+
const wrapper = mount(UIInput, {
376+
props: {
377+
modelValue: '',
378+
name: 'input',
379+
help
380+
}
381+
});
382+
383+
expect(wrapper.get('.ui-help-text').text()).toBe(help);
384+
});
385+
386+
it('should display the only error text when both help and error are passed as prop', () => {
387+
const help = 'help';
388+
const error = 'error';
389+
390+
const wrapper = mount(UIInput, {
391+
props: {
392+
modelValue: '',
393+
name: 'input',
394+
help,
395+
error
396+
}
397+
});
398+
399+
expect(wrapper.find('.ui-help-text').exists()).toBe(false);
400+
expect(wrapper.get('.ui-error-text').text()).toBe(error);
401+
});
323402
});

src/components/input/UIInput.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,16 @@
119119

120120
<UIExpandTransition>
121121
<slot v-if="error || $slots.error" name="error">
122-
<p class="text-color-error text-sm">
122+
<p class="ui-error-text">
123123
{{ error }}
124124
</p>
125125
</slot>
126+
127+
<slot v-else-if="(help || $slots.help)" name="help">
128+
<p class="ui-help-text">
129+
{{ help }}
130+
</p>
131+
</slot>
126132
</UIExpandTransition>
127133
</div>
128134
</template>
@@ -226,6 +232,14 @@ export default defineComponent({
226232
type: [Number, String]
227233
},
228234
235+
236+
/**
237+
* Help message to show below the input.
238+
*/
239+
help: {
240+
type: String
241+
},
242+
229243
large,
230244
small,
231245
prefix,

0 commit comments

Comments
 (0)