File tree Expand file tree Collapse file tree 5 files changed +72
-12
lines changed Expand file tree Collapse file tree 5 files changed +72
-12
lines changed Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import { render } from '@testing-library/react'
3
+
4
+ import { InputGroup } from './InputGroup'
5
+
6
+ describe ( 'InputGroup component' , ( ) => {
7
+ it ( 'renders without errors' , ( ) => {
8
+ const { queryByTestId } = render ( < InputGroup > My Input Group</ InputGroup > )
9
+ expect ( queryByTestId ( 'inputGroup' ) ) . toBeInTheDocument ( )
10
+ expect ( queryByTestId ( 'inputGroup' ) ) . toHaveClass ( 'usa-input-group' )
11
+ } )
12
+
13
+ it ( 'renders its children' , ( ) => {
14
+ const { queryByText } = render ( < InputGroup > My Input Group</ InputGroup > )
15
+ expect ( queryByText ( 'My Input Group' ) ) . toBeInTheDocument ( )
16
+ } )
17
+
18
+ it ( 'adds the error class when error is true' , ( ) => {
19
+ const { queryByTestId } = render (
20
+ < InputGroup error > My Input Group</ InputGroup >
21
+ )
22
+ expect ( queryByTestId ( 'inputGroup' ) ) . toHaveClass ( 'usa-input-group--error' )
23
+ } )
24
+
25
+ it ( 'adds the provided className' , ( ) => {
26
+ const { queryByTestId } = render (
27
+ < InputGroup className = "my-class" > My Input Group</ InputGroup >
28
+ )
29
+ expect ( queryByTestId ( 'inputGroup' ) ) . toHaveClass ( 'my-class' )
30
+ } )
31
+ } )
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import classnames from 'classnames'
3
+
4
+ export interface InputGroupProps {
5
+ children : React . ReactNode
6
+ className ?: string
7
+ error ?: boolean
8
+ }
9
+
10
+ export const InputGroup = ( {
11
+ children,
12
+ className,
13
+ error,
14
+ } : InputGroupProps ) : React . ReactElement => {
15
+ const classes = classnames (
16
+ 'usa-input-group' ,
17
+ { 'usa-input-group--error' : error } ,
18
+ className
19
+ )
20
+
21
+ return (
22
+ < div data-testid = "inputGroup" className = { classes } >
23
+ { children }
24
+ </ div >
25
+ )
26
+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import React from 'react'
2
2
import { InputPrefix } from './InputPrefix'
3
3
import { Icon } from '../../Icon/Icons'
4
4
import { TextInput } from '../TextInput/TextInput'
5
+ import { InputGroup } from '../InputGroup/InputGroup'
5
6
import { FormGroup } from '../FormGroup/FormGroup'
6
7
7
8
export default {
@@ -22,29 +23,29 @@ Source: https://designsystem.digital.gov/components/input-prefix-suffix/
22
23
23
24
export const InputWithTextInputPrefix = ( ) : React . ReactElement => (
24
25
< FormGroup >
25
- < div className = "usa-input-group" >
26
+ < InputGroup >
26
27
< InputPrefix > cvc</ InputPrefix >
27
28
< TextInput id = "cvc" name = "cvc" type = "text" />
28
- </ div >
29
+ </ InputGroup >
29
30
</ FormGroup >
30
31
)
31
32
32
33
export const InputWithTextInputPrefixError = ( ) : React . ReactElement => (
33
34
< FormGroup >
34
- < div className = "usa-input-group usa-input-group-- error" >
35
+ < InputGroup error >
35
36
< InputPrefix > cvc</ InputPrefix >
36
37
< TextInput id = "cvc" name = "cvc" type = "text" validationStatus = "error" />
37
- </ div >
38
+ </ InputGroup >
38
39
</ FormGroup >
39
40
)
40
41
41
42
export const InputWithIconInputPrefix = ( ) : React . ReactElement => (
42
43
< FormGroup >
43
- < div className = "usa-input-group" >
44
+ < InputGroup >
44
45
< InputPrefix >
45
46
< Icon . CreditCard />
46
47
</ InputPrefix >
47
48
< TextInput id = "card" name = "card" type = "text" />
48
- </ div >
49
+ </ InputGroup >
49
50
</ FormGroup >
50
51
)
Original file line number Diff line number Diff line change 1
1
import React from 'react'
2
2
import { InputSuffix } from './InputSuffix'
3
+ import { InputGroup } from '../InputGroup/InputGroup'
3
4
import { FormGroup } from '../FormGroup/FormGroup'
4
5
import { TextInput } from '../TextInput/TextInput'
5
6
import { Icon } from '../../Icon/Icons'
@@ -22,18 +23,18 @@ Source: https://designsystem.digital.gov/components/input-prefix-suffix/
22
23
23
24
export const InputWithIconInputSuffix = ( ) : React . ReactElement => (
24
25
< FormGroup >
25
- < div className = "usa-input-group" >
26
+ < InputGroup >
26
27
< TextInput id = "search" name = "search" type = "search" />
27
28
< InputSuffix >
28
29
< Icon . Search />
29
30
</ InputSuffix >
30
- </ div >
31
+ </ InputGroup >
31
32
</ FormGroup >
32
33
)
33
34
34
35
export const InputWithIconInputSuffixError = ( ) : React . ReactElement => (
35
36
< FormGroup >
36
- < div className = "usa-input-group usa-input-group-- error" >
37
+ < InputGroup error >
37
38
< TextInput
38
39
id = "search"
39
40
name = "search"
@@ -43,15 +44,15 @@ export const InputWithIconInputSuffixError = (): React.ReactElement => (
43
44
< InputSuffix >
44
45
< Icon . Search />
45
46
</ InputSuffix >
46
- </ div >
47
+ </ InputGroup >
47
48
</ FormGroup >
48
49
)
49
50
50
51
export const InputWithTextInputSuffix = ( ) : React . ReactElement => (
51
52
< FormGroup >
52
- < div className = "usa-input-group usa-input-group--sm" >
53
+ < InputGroup >
53
54
< TextInput id = "weight" name = "weight" type = "text" />
54
55
< InputSuffix > lbs.</ InputSuffix >
55
- </ div >
56
+ </ InputGroup >
56
57
</ FormGroup >
57
58
)
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ export { FileInput } from './components/forms/FileInput/FileInput'
59
59
export type { FileInputRef } from './components/forms/FileInput/FileInput'
60
60
export { Form } from './components/forms/Form/Form'
61
61
export { FormGroup } from './components/forms/FormGroup/FormGroup'
62
+ export { InputGroup } from './components/forms/InputGroup/InputGroup'
62
63
export { InputPrefix } from './components/forms/InputPrefix/InputPrefix'
63
64
export { InputSuffix } from './components/forms/InputSuffix/InputSuffix'
64
65
export { Label } from './components/forms/Label/Label'
You can’t perform that action at this time.
0 commit comments