-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: InputGroup component #2383
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
151200d
Add InputGroup component
jcbcapps dd0567f
Add test
jcbcapps aeda663
Update to use InputGroup
jcbcapps 2ae0c7a
Add FormGroup back as a wrapper
jcbcapps 013410a
Export InputGroup component
jcbcapps 61e9535
Add tests to verify classNames are applied
jcbcapps 604ac27
Check that default class is applied
jcbcapps 560796f
Merge branch 'main' into 1692-jc-input-group-component
jcbcapps 3f7c6cb
Merge branch 'main' into 1692-jc-input-group-component
jcbcapps File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react' | ||
import { render } from '@testing-library/react' | ||
|
||
import { InputGroup } from './InputGroup' | ||
|
||
describe('InputGroup component', () => { | ||
it('renders without errors', () => { | ||
const { queryByTestId } = render(<InputGroup>My Input Group</InputGroup>) | ||
expect(queryByTestId('inputGroup')).toBeInTheDocument() | ||
}) | ||
|
||
it('renders its children', () => { | ||
const { queryByText } = render(<InputGroup>My Input Group</InputGroup>) | ||
expect(queryByText('My Input Group')).toBeInTheDocument() | ||
}) | ||
|
||
it('adds the error class when error is true', () => { | ||
const { queryByTestId } = render( | ||
<InputGroup error>My Input Group</InputGroup> | ||
) | ||
expect(queryByTestId('inputGroup')).toHaveClass('usa-input-group--error') | ||
}) | ||
|
||
it('adds the provided className', () => { | ||
const { queryByTestId } = render( | ||
<InputGroup className="my-class">My Input Group</InputGroup> | ||
) | ||
expect(queryByTestId('inputGroup')).toHaveClass('my-class') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react' | ||
import classnames from 'classnames' | ||
|
||
export interface InputGroupProps { | ||
children: React.ReactNode | ||
className?: string | ||
error?: boolean | ||
} | ||
|
||
export const InputGroup = ({ | ||
children, | ||
className, | ||
error, | ||
}: InputGroupProps): React.ReactElement => { | ||
const classes = classnames( | ||
'usa-input-group', | ||
{ 'usa-input-group--error': error }, | ||
className | ||
) | ||
|
||
return ( | ||
<div data-testid="inputGroup" className={classes}> | ||
{children} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a test for checking that the right className is applied?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also one with the error state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I was just thinking the tests could probably be more thorough. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcbcapps sorry, I shoulda been more clear. Can you add a test that verifies that the component has the default class name applied? (
usa-input-group
)It can go in the
renders without errors
test, imo, since it's jsut verifying that the component built with the right uswds class