Skip to content

Commit

Permalink
Fix form types (estevanmaito#31)
Browse files Browse the repository at this point in the history
* fix(input): fix input type

* fix(forms): fix prop extension to allow usage of element attributes eg. name

Extend the correct HTML element to get all the available attributes, for example, `name`

fix estevanmaito#30

Co-authored-by: Samuel Carnell
  • Loading branch information
estevanmaito authored Feb 6, 2021
1 parent 258f4ae commit 971ace0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useContext } from 'react'
import classNames from 'classnames'
import { ThemeContext } from './context/ThemeContext'

interface Props extends React.HTMLAttributes<HTMLInputElement> {
interface Props extends React.ComponentPropsWithRef<'input'> {
/**
* Defines the color of the input
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useContext } from 'react'
import classNames from 'classnames'
import { ThemeContext } from './context/ThemeContext'

interface Props extends React.SelectHTMLAttributes<HTMLSelectElement> {
interface Props extends React.ComponentPropsWithRef<'select'> {
/**
* Defines the color of the select
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useContext } from 'react'
import classNames from 'classnames'
import { ThemeContext } from './context/ThemeContext'

interface Props extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
interface Props extends React.ComponentPropsWithRef<'textarea'> {
/**
* Defines the color of the textarea
*/
Expand Down
6 changes: 6 additions & 0 deletions src/__tests__/Input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,10 @@ describe('Input', () => {
expected
)
})

it('should contain name attribute', () => {
const wrapper = mount(<Input name="test-name" />)

expect(wrapper.find('input[name="test-name"]').getDOMNode().getAttribute('name')).toBeDefined()
})
})
10 changes: 10 additions & 0 deletions src/__tests__/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,14 @@ describe('Select', () => {

expect(wrapper.find('select').children()).toHaveLength(expected)
})

it('should contain name attribute', () => {
const wrapper = mount(
<Select name="test-name">
<option value="lorem">Lorem</option>
</Select>
)

expect(wrapper.find('select[name="test-name"]').getDOMNode().getAttribute('name')).toBeDefined()
})
})
8 changes: 8 additions & 0 deletions src/__tests__/Textarea.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ describe('Textarea', () => {

expect(wrapper.find('textarea').getDOMNode().getAttribute('class')).toContain(expected)
})

it('should contain name attribute', () => {
const wrapper = mount(<Textarea name="test-name" />)

expect(wrapper.find('textarea[name="test-name"]').getDOMNode().getAttribute('name')).toBe(
'test-name'
)
})
})

0 comments on commit 971ace0

Please sign in to comment.