Skip to content

Commit 9c82fc9

Browse files
authored
Merge pull request #768 from BY00565233/SURF-2065
feat(hx-text-control): add help and error text
2 parents ee9c9a7 + 2546604 commit 9c82fc9

File tree

3 files changed

+110
-4
lines changed

3 files changed

+110
-4
lines changed

docs/components/text-input/index.html

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,42 @@ <h2 id="basic-text-input">Basic Text Input</h2>
9191
</p>
9292
</hx-checkbox-control>
9393
</fieldset>
94+
95+
<fieldset>
96+
<legend class="beta-hxFieldName">Optional Text</legend>
97+
<hx-checkbox-control>
98+
<input
99+
id="chkHasHelpText"
100+
type="checkbox"
101+
v-model="helpTextToDisplay"
102+
/>
103+
<label for="chkHasHelpText">
104+
<hx-checkbox></hx-checkbox>
105+
Help Text
106+
</label>
107+
</hx-checkbox-control>
108+
<hx-checkbox-control>
109+
<input
110+
id="chkHasError"
111+
type="checkbox"
112+
v-model="errorTextToDisplay"
113+
/>
114+
<label for="chkHasError">
115+
<hx-checkbox></hx-checkbox>
116+
Error Text
117+
</label>
118+
</hx-checkbox-control>
119+
120+
<hx-text-control>
121+
<label> Help Text</label>
122+
<input type="text" v-model="helpText" :disabled="!helpTextToDisplay">
123+
</hx-text-control>
124+
125+
<hx-text-control>
126+
<label> Error Text</label>
127+
<input type="text" v-model="errorText" :disabled="!errorTextToDisplay">
128+
</hx-text-control>
129+
</fieldset>
94130
</form>
95131
</header>
96132

@@ -108,6 +144,14 @@ <h2 id="basic-text-input">Basic Text Input</h2>
108144
>
109145
{% raw %}{{label}}{% endraw %}
110146
</label>
147+
<p class="hxHelpText" :hidden="!helpTextToDisplay">
148+
{% raw %}{{helpText}} {% endraw %}
149+
</p>
150+
<p class="hxErrorText" :hidden="!errorTextToDisplay">
151+
<hx-error>
152+
{% raw %}{{errorText}} {% endraw %}
153+
</hx-error>
154+
</p>
111155
</hx-text-control>
112156
</div>
113157

docs/components/text-input/text-input-demo.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ if (document.getElementById('vue-textInputDemo')) {
99
isDisabled: false,
1010
isRequired: false,
1111
label: 'Username',
12+
errorTextToDisplay: false,
13+
helpTextToDisplay: false,
14+
helpText: 'Please enter username.',
15+
errorText: 'Username should not be empty',
1216
},
1317
computed: {
1418
attrDisabled: function () {
@@ -32,6 +36,12 @@ if (document.getElementById('vue-textInputDemo')) {
3236

3337
return (classNames === '' ? '' : `class="${classNames}"`);
3438
},
39+
isHelpTextHidden: function () {
40+
return (this.helpTextToDisplay ? '' : 'hidden');
41+
},
42+
isErrorTextHidden: function () {
43+
return (this.errorTextToDisplay ? '' : 'hidden');
44+
},
3545
snippet: function () {
3646
return Util.snippet(`
3747
<hx-text-control>
@@ -47,6 +57,14 @@ if (document.getElementById('vue-textInputDemo')) {
4757
>
4858
${this.label}
4959
</label>
60+
<p class="hxHelpText" ${this.isHelpTextHidden}>
61+
${this.helpText}
62+
</p>
63+
<p class="hxErrorText" ${this.isErrorTextHidden}>
64+
<hx-error>
65+
${this.errorText}
66+
</hx-error>
67+
</p>
5068
</hx-text-control>
5169
`);
5270
},

src/scss/components/text-input/_index.scss

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
/// +----------+---------+----------+
99
/// | [prefix] | control | [suffix] | auto
1010
/// +----------+---------+----------+
11+
/// | help | help | help | auto
12+
/// +----------+---------+----------+
13+
/// | error | error | error | auto
14+
/// +----------+---------+----------+
1115
///
12-
/// * column will collapse if content not present
16+
/// column will collapse if content not present
1317

1418
hx-text-control {
1519
$ctrl-columns: auto 1fr auto;
16-
$ctrl-rows: auto auto;
20+
$ctrl-rows: auto auto auto auto;
1721
$ctrl-row-align: center;
1822

1923
-ms-grid-columns: $ctrl-columns;
@@ -23,7 +27,9 @@ hx-text-control {
2327
display: grid;
2428
grid-template-areas:
2529
"label label label"
26-
"prefix control suffix";
30+
"prefix control suffix"
31+
"help help help"
32+
"error error error";
2733
grid-template-columns: $ctrl-columns;
2834
grid-template-rows: $ctrl-rows;
2935

@@ -36,7 +42,8 @@ hx-text-control {
3642
> label,
3743
> input[type="text"],
3844
> .hxPrefix,
39-
> .hxSuffix {
45+
> .hxSuffix,
46+
> p {
4047
display: block;
4148
}
4249

@@ -83,6 +90,31 @@ hx-text-control {
8390
justify-self: $justify;
8491
margin-left: 0.25rem;
8592
}
93+
94+
> p,
95+
p.hxHelpText {
96+
$justify: start;
97+
98+
-ms-grid-column-align: $justify;
99+
-ms-grid-column-span: 3;
100+
-ms-grid-column: 1;
101+
-ms-grid-row: 3;
102+
-ms-grid-row-align: $ctrl-row-align; // because IE
103+
grid-area: help;
104+
justify-self: $justify;
105+
}
106+
107+
> p.hxErrorText {
108+
$justify: start;
109+
110+
-ms-grid-column-align: $justify;
111+
-ms-grid-column-span: 3;
112+
-ms-grid-column: 1;
113+
-ms-grid-row: 4;
114+
-ms-grid-row-align: $ctrl-row-align; // because IE
115+
grid-area: error;
116+
justify-self: $justify;
117+
}
86118
}
87119

88120
// ----- PRISTINE ----------
@@ -98,6 +130,18 @@ hx-text-control {
98130
@include hxTextControl($focused: true);
99131
}
100132
}
133+
134+
> p,
135+
p.hxHelpText {
136+
@include hxHelpText(); // default styles
137+
}
138+
139+
> p.hxErrorText {
140+
color: $red-900;
141+
font-size: 0.75rem;
142+
margin-top: 0;
143+
width: 100%; // for IE11
144+
}
101145
}
102146

103147
// ----- INVALID ----------

0 commit comments

Comments
 (0)