@@ -33,6 +33,7 @@ interface IRule<T, D = void> {
33
33
interface IArgs < T , D = void > {
34
34
rules : IRule < T , D > [ ] ;
35
35
description ( this : T , derivedData : D ) : React . ReactChild ;
36
+ hideDescriptionIfValid ?: boolean ;
36
37
deriveData ?( data : Data ) : Promise < D > ;
37
38
}
38
39
@@ -54,6 +55,8 @@ export interface IValidationResult {
54
55
* @param {Function } description
55
56
* Function that returns a string summary of the kind of value that will
56
57
* meet the validation rules. Shown at the top of the validation feedback.
58
+ * @param {Boolean } hideDescriptionIfValid
59
+ * If true, don't show the description if the validation passes validation.
57
60
* @param {Function } deriveData
58
61
* Optional function that returns a Promise to an object of generic type D.
59
62
* The result of this Promise is passed to rule methods `skip`, `test`, `valid`, and `invalid`.
@@ -71,7 +74,9 @@ export interface IValidationResult {
71
74
* A validation function that takes in the current input value and returns
72
75
* the overall validity and a feedback UI that can be rendered for more detail.
73
76
*/
74
- export default function withValidation < T = undefined , D = void > ( { description, deriveData, rules } : IArgs < T , D > ) {
77
+ export default function withValidation < T = undefined , D = void > ( {
78
+ description, hideDescriptionIfValid, deriveData, rules,
79
+ } : IArgs < T , D > ) {
75
80
return async function onValidate ( { value, focused, allowEmpty = true } : IFieldState ) : Promise < IValidationResult > {
76
81
if ( ! value && allowEmpty ) {
77
82
return {
@@ -156,7 +161,7 @@ export default function withValidation<T = undefined, D = void>({ description, d
156
161
}
157
162
158
163
let summary ;
159
- if ( description ) {
164
+ if ( description && ( details || ! hideDescriptionIfValid ) ) {
160
165
// We're setting `this` to whichever component holds the validation
161
166
// function. That allows rules to access the state of the component.
162
167
const content = description . call ( this , derivedData ) ;
0 commit comments