Skip to content

Commit 57adfe7

Browse files
frozenheliumtnagorra
authored andcommitted
Improve input error behaviour
1 parent 3c70c24 commit 57adfe7

9 files changed

Lines changed: 33 additions & 11 deletions

File tree

components/Input/ColorInput/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const propTypes = {
5050

5151
disabled: PropTypes.bool,
5252
readOnly: PropTypes.bool,
53+
persistantHintAndError: PropTypes.bool,
5354
};
5455

5556
const defaultProps = {
@@ -61,6 +62,7 @@ const defaultProps = {
6162
showHintAndError: true,
6263
disabled: false,
6364
readOnly: false,
65+
persistantHintAndError: true,
6466
};
6567

6668
class ColorInput extends React.PureComponent {
@@ -136,6 +138,7 @@ class ColorInput extends React.PureComponent {
136138
hint,
137139
disabled,
138140
readOnly,
141+
persistantHintAndError,
139142
} = this.props;
140143

141144
const { showColorPicker } = this.state;
@@ -179,6 +182,7 @@ class ColorInput extends React.PureComponent {
179182
show={showHintAndError}
180183
hint={hint}
181184
error={error}
185+
persistant={persistantHintAndError}
182186
/>
183187
{
184188
showColorPicker && (

components/Input/HintAndError/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ const propTypes = {
88
show: PropTypes.bool,
99
error: PropTypes.string,
1010
hint: PropTypes.string,
11+
persistant: PropTypes.bool,
1112
};
1213

1314
const defaultProps = {
1415
show: true,
1516
error: undefined,
1617
hint: undefined,
18+
persistant: false,
1719
};
1820

1921
const emptyText = '-';
@@ -28,9 +30,10 @@ export default class InputHintAndError extends React.PureComponent {
2830
show,
2931
error,
3032
hint,
33+
persistant,
3134
} = this.props;
3235

33-
if (!show) {
36+
if (!show || (!persistant && !error)) {
3437
return null;
3538
}
3639

components/Input/HintAndError/styles.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
.input-hint-and-error {
32
overflow: hidden;
43
text-overflow: ellipsis;

components/Input/NonFieldErrors/styles.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
.non-field-errors {
32
display: flex;
43
text-align: center;
@@ -9,7 +8,8 @@
98
padding: var(--spacing-small);
109

1110
&.empty {
12-
color: transparent;
11+
display: none;
12+
// color: transparent;
1313
user-select: none;
1414
}
1515

components/Input/SegmentInput/Option/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export default class SegmentOption extends React.PureComponent {
7474
checked,
7575
label,
7676
name,
77+
renderer: Renderer,
78+
data,
7779
} = this.props;
7880

7981
const classNames = this.getClassName();
@@ -92,7 +94,7 @@ export default class SegmentOption extends React.PureComponent {
9294
value={id}
9395
name={name}
9496
/>
95-
{label}
97+
{ Renderer ? <Renderer data={data} /> : label}
9698
</label>
9799
);
98100
}

components/Input/SegmentInput/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ class SegmentInput extends React.PureComponent {
141141
error: this.props.error,
142142
readOnly: this.props.readOnly,
143143
disabled: this.props.disabled,
144+
renderer: this.props.renderer,
145+
className: this.props.itemClassName,
146+
data,
144147
});
145148

146149
render() {

components/Input/SelectInput/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const propTypes = {
6060
optionLabelSelector: PropTypes.func,
6161

6262
renderEmpty: PropTypes.func,
63+
persistantHintAndError: PropTypes.bool,
6364
};
6465

6566
const defaultProps = {
@@ -82,6 +83,7 @@ const defaultProps = {
8283
showLabel: true,
8384
title: undefined,
8485
value: undefined,
86+
persistantHintAndError: true,
8587
};
8688

8789
class SelectInput extends React.PureComponent {
@@ -292,6 +294,7 @@ class SelectInput extends React.PureComponent {
292294
autoFocus,
293295
hideClearButton,
294296
className: classNameFromProps,
297+
persistantHintAndError,
295298
options,
296299
} = this.props;
297300

@@ -415,12 +418,12 @@ class SelectInput extends React.PureComponent {
415418
/>
416419
</div>
417420
</div>
418-
{ showHintAndError && (
419-
<HintAndError
420-
error={error}
421-
hint={hint}
422-
/>
423-
)}
421+
<HintAndError
422+
show={showHintAndError}
423+
error={error}
424+
hint={hint}
425+
persistant={persistantHintAndError}
426+
/>
424427
<Options
425428
className={optionsClassName}
426429
labelSelector={labelSelector}

components/Input/TextArea/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const propTypes = {
6363
resize: PropTypes.string,
6464

6565
selectOnFocus: PropTypes.bool,
66+
persistantHintAndError: PropTypes.bool,
6667
};
6768

6869
const defaultProps = {
@@ -80,6 +81,7 @@ const defaultProps = {
8081
showHintAndError: true,
8182
value: '',
8283
selectOnFocus: false,
84+
persistantHintAndError: true,
8385
};
8486

8587
export class NormalTextArea extends React.PureComponent {
@@ -188,6 +190,7 @@ export class NormalTextArea extends React.PureComponent {
188190
showHintAndError,
189191
disabled,
190192
resize,
193+
persistantHintAndError,
191194
...otherProps
192195
} = this.props;
193196

@@ -216,6 +219,7 @@ export class NormalTextArea extends React.PureComponent {
216219
show={showHintAndError}
217220
hint={hint}
218221
error={error}
222+
persistant={persistantHintAndError}
219223
/>
220224
</div>
221225
);

components/Input/TextInput/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const propTypes = {
2929
]),
3030
selectOnFocus: PropTypes.bool,
3131
title: PropTypes.string,
32+
persistantHintAndError: PropTypes.bool,
3233
};
3334

3435
const defaultProps = {
@@ -46,6 +47,7 @@ const defaultProps = {
4647
value: '',
4748
selectOnFocus: false,
4849
title: undefined,
50+
persistantHintAndError: true,
4951
};
5052

5153
class TextInput extends React.PureComponent {
@@ -138,6 +140,7 @@ class TextInput extends React.PureComponent {
138140
showHintAndError,
139141
disabled,
140142
title,
143+
persistantHintAndError,
141144
...otherProps
142145
} = this.props;
143146

@@ -170,6 +173,7 @@ class TextInput extends React.PureComponent {
170173
show={showHintAndError}
171174
hint={hint}
172175
error={error}
176+
persistant={persistantHintAndError}
173177
/>
174178
</div>
175179
);

0 commit comments

Comments
 (0)