Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

Commit f02161b

Browse files
Merge pull request #923 from wyvl/techcnial/INT-14666-add-type-props-to-enable-password-input
Add type props to enable password input
2 parents dc9edb1 + 36cbc90 commit f02161b

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

src/domain/Inputs/TextInput/TextInput.examples.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,15 @@ initialState = { value: 'I have a custom width 500px' };
133133
/>
134134
```
135135

136+
#### Password Input
137+
138+
```jsx
139+
initialState = { textValue: '1234567890' };
140+
141+
<TextInput
142+
type='password'
143+
value={state.textValue}
144+
onChange={(value) => {setState({textValue: value})}}
145+
/>
146+
```
147+

src/domain/Inputs/TextInput/TextInput.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,17 @@ describe('<TextInput />', () => {
153153

154154
expect(wrapper).toMatchSnapshot()
155155
})
156+
157+
it(`should render an password input`, () => {
158+
const wrapper = shallow(
159+
<TextInput
160+
type='password'
161+
value='test'
162+
name='test'
163+
onChange={dummyFunction}
164+
/>
165+
)
166+
167+
expect(wrapper).toMatchSnapshot()
168+
})
156169
})

src/domain/Inputs/TextInput/TextInput.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ interface ITextInputProps {
2424
onChange?: (value: string) => void
2525
/** Value of the input */
2626
value?: string | number
27+
/** Type of the input */
28+
type?: 'text' | 'password'
2729
/** If true, sets input to disabled state */
2830
isDisabled?: boolean
2931
/** Icon to display in the input box */
@@ -130,14 +132,15 @@ class TextInput extends React.PureComponent<ITextInputProps> {
130132
width,
131133
componentContext,
132134
margins,
135+
type,
133136
'aria-label': label
134137
} = this.props
135138

136139
return (
137140
<StyledTextInput
138141
id={id || name}
139142
name={name}
140-
type='text'
143+
type={type ? type : 'text'}
141144
value={value}
142145
onChange={this.handleChange}
143146
onKeyDown={handleKeyDown}

src/domain/Inputs/TextInput/__snapshots__/TextInput.test.tsx.snap

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ exports[`<TextInput /> should render an invalid text input 1`] = `
5353
/>
5454
`;
5555

56+
exports[`<TextInput /> should render an password input 1`] = `
57+
<styled.input
58+
className="input "
59+
data-component-type="text_input"
60+
id="test"
61+
name="test"
62+
onChange={[Function]}
63+
onFocus={[Function]}
64+
type="password"
65+
value="test"
66+
/>
67+
`;
68+
5669
exports[`<TextInput /> should render an text input 1`] = `
5770
<styled.input
5871
className="input "

0 commit comments

Comments
 (0)