Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
feat(textfield): add id prop to text field
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmeyer committed Dec 18, 2020
1 parent 81d9b3d commit dd0ce21
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/components/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import Form from 'react-bootstrap/Form'
import { getControlSize } from '../../helpers/controlSize'

interface Props {
/** A unique identifier for the componentchrome
*
*/
id?: string
/** Determines whether the TextField should be disabled or not. By default, it is false. */
disabled?: boolean
/** Determines whether the TextField should be rendered as invalid or not. By default, it is false. */
Expand Down Expand Up @@ -39,6 +43,7 @@ interface Props {
*/
const TextField = (props: Props) => {
const {
id,
disabled,
isValid,
isInvalid,
Expand All @@ -56,6 +61,7 @@ const TextField = (props: Props) => {
return (
<Form.Group>
<Form.Control
id={id}
as="textarea"
disabled={disabled}
isInvalid={isInvalid}
Expand Down
6 changes: 5 additions & 1 deletion test/textfield.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ describe('TextField', () => {
it('renders a TextField with attributes', () => {
const name = 'example_field'
const value = 'this is teh text field text'
const id = 'someId'
const rows = 5
const wrapper = mount(<TextField name={name} value={value} onChange={onChange} rows={rows} />)
const wrapper = mount(
<TextField id={id} name={name} value={value} onChange={onChange} rows={rows} />,
)

expect(wrapper.find(HTMLTextAreaElement).prop('id')).toEqual(id)
expect(wrapper.find(HTMLTextAreaElement)).toHaveLength(1)
expect(
wrapper.find(HTMLTextAreaElement).filterWhere((item) => item.prop('name') === name),
Expand Down

0 comments on commit dd0ce21

Please sign in to comment.