File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed
packages/blueprint-component-mapper/src Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -22,12 +22,13 @@ export const FormGroupInternal = ({
22
22
} ) => {
23
23
const { required } = useContext ( BlueprintContext ) ;
24
24
25
- const { error, touched } = meta ;
25
+ const { error, touched, warning } = meta ;
26
26
const showError = ( validateOnMount || touched ) && error ;
27
+ const showWarning = ( validateOnMount || touched ) && warning ;
27
28
28
- const text = showError ? error : helperText || description ;
29
+ const text = showError || showWarning || helperText || description ;
29
30
30
- const intent = showError && error && { intent : Intent . DANGER } ;
31
+ const intent = ( showError && { intent : Intent . DANGER } ) || ( showWarning && { intent : Intent . WARNING } ) ;
31
32
const labelInfo = ! hideLabel && isRequired && { labelInfo : required } ;
32
33
33
34
return (
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import { mount } from 'enzyme' ;
3
+ import { act } from 'react-dom/test-utils' ;
3
4
4
5
import FormRenderer , { componentTypes } from '@data-driven-forms/react-form-renderer' ;
5
6
import FormTemplate from '../files/form-template' ;
@@ -107,6 +108,29 @@ describe('formFields generated tests', () => {
107
108
expect ( wrapper . find ( '.bp3-intent-danger' ) . length ) . toBeGreaterThanOrEqual ( 1 ) ;
108
109
} ) ;
109
110
111
+ it ( 'renders with warning' , async ( ) => {
112
+ const errorField = {
113
+ ...field ,
114
+ validate : [ { type : validatorTypes . REQUIRED , warning : true } ] ,
115
+ useWarnings : true ,
116
+ validateOnMount : true
117
+ } ;
118
+ let wrapper ;
119
+
120
+ await act ( async ( ) => {
121
+ wrapper = mount ( < RendererWrapper schema = { { fields : [ errorField ] } } /> ) ;
122
+ } ) ;
123
+ wrapper . update ( ) ;
124
+
125
+ expect (
126
+ wrapper
127
+ . find ( '.bp3-form-helper-text' )
128
+ . last ( )
129
+ . text ( )
130
+ ) . toEqual ( errorText ) ;
131
+ expect ( wrapper . find ( '.bp3-intent-warning' ) . length ) . toBeGreaterThanOrEqual ( 1 ) ;
132
+ } ) ;
133
+
110
134
it ( 'renders with helperText' , ( ) => {
111
135
const helpertextField = {
112
136
...field ,
You can’t perform that action at this time.
0 commit comments