forked from learningequality/kolibri-design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ktextbox.vue
94 lines (68 loc) · 2.66 KB
/
ktextbox.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<template>
<DocsPageTemplate apiDocs>
<DocsPageSection title="Overview" anchor="#overview">
For detailed design guidance, refer to the page on <DocsInternalLink href="/textfields" text="text fields" />.
</DocsPageSection>
<DocsPageSection title="Usage" anchor="#usage">
<h3>Input with label</h3>
<KTextbox label="Input with label" />
<DocsShowCode language="html">
<KTextbox label="Input with label" />
</DocsShowCode>
<p>This text box includes a visible label, providing clear guidance and context to the user about the expected input.</p>
<h3>Valid and invalid input</h3>
<KTextbox
v-model="numericInput"
label="Numbers only"
:invalid="!isNumeric(numericInput)"
invalidText="Please enter a valid number."
/>
<DocsShowCode language="html">
<KTextbox
v-model="numericInput"
label="Numbers only"
:invalid="!isNumeric(numericInput)"
invalidText="Please enter a valid number."
/>
</DocsShowCode>
<p>This text box only accepts numeric input. If any non-numeric character is entered, it will be considered invalid.</p>
<h3>Disabled input</h3>
<KTextbox label="Disabled input" disabled />
<DocsShowCode language="html">
<KTextbox label="Disabled input" disabled />
</DocsShowCode>
<p>This text box is disabled. It cannot be edited or focused, so it will be skipped during keyboard navigation.</p>
<h3>Number input</h3>
<KTextbox label="Number input" type="number" :min="0" :max="100" />
<DocsShowCode language="html">
<KTextbox label="Number Input" type="number" :min="0" :max="100" />
</DocsShowCode>
<p>
This is a numeric input field where users can input values within the range of 0 to 100.
</p>
<p>
<strong>Note:</strong> The KTextbox does not automatically validate the min and max values, however, it is recommended to use them for accessibility purposes while using the invalid and invalidText props to handle validation as needed.
</p>
<h3>Text area</h3>
<KTextbox label="Text area" :textArea="true" />
<DocsShowCode language="html">
<KTextbox label="Text area" :textArea="true" />
</DocsShowCode>
<p>This is a multi-line text input area, suitable for longer text entries.</p>
</DocsPageSection>
</DocsPageTemplate>
</template>
<script>
export default {
data() {
return {
numericInput: '',
};
},
methods: {
isNumeric(value) {
return !isNaN(parseFloat(value)) && isFinite(value);
},
},
};
</script>