Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit a70b713

Browse files
author
Tilde Ann Thurium
authored
Merge pull request #1808 from ericcornelissen/papercut/show-credentials
Add button to show/hide password in credentials dialog
2 parents 9fe9fcb + dfccca2 commit a70b713

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

lib/views/credential-dialog.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ export default class CredentialDialog extends React.Component {
2323

2424
constructor(props, context) {
2525
super(props, context);
26-
autobind(this, 'confirm', 'cancel', 'onUsernameChange', 'onPasswordChange', 'onRememberChange', 'focusFirstInput');
26+
autobind(this, 'confirm', 'cancel', 'onUsernameChange', 'onPasswordChange', 'onRememberChange',
27+
'focusFirstInput', 'toggleShowPassword');
2728

2829
this.state = {
2930
username: '',
3031
password: '',
3132
remember: false,
33+
showPassword: false,
3234
};
3335
}
3436

@@ -61,13 +63,16 @@ export default class CredentialDialog extends React.Component {
6163
<label className="github-DialogLabel">
6264
Password:
6365
<input
64-
type="password"
66+
type={this.state.showPassword ? 'text' : 'password'}
6567
ref={e => (this.passwordInput = e)}
6668
className="input-text github-CredentialDialog-Password"
6769
value={this.state.password}
6870
onChange={this.onPasswordChange}
6971
tabIndex="2"
7072
/>
73+
<button className="github-DialogLabelButton" onClick={this.toggleShowPassword}>
74+
{this.state.showPassword ? 'Hide' : 'Show'}
75+
</button>
7176
</label>
7277
</main>
7378
<footer className="github-DialogButtons">
@@ -122,4 +127,8 @@ export default class CredentialDialog extends React.Component {
122127
focusFirstInput() {
123128
(this.usernameInput || this.passwordInput).focus();
124129
}
130+
131+
toggleShowPassword() {
132+
this.setState({showPassword: !this.state.showPassword});
133+
}
125134
}

styles/dialog.less

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,22 @@
1919
&Label {
2020
flex: 1;
2121
margin: @github-dialog-spacing;
22+
position: relative;
2223
line-height: 2;
24+
25+
&Button {
26+
position: absolute;
27+
background: transparent;
28+
right: .3em;
29+
bottom: 0;
30+
border: none;
31+
color: @text-color-subtle;
32+
cursor: pointer;
33+
34+
&:hover {
35+
color: @text-color-highlight;
36+
}
37+
}
2338
}
2439

2540
&Buttons {

test/views/credential-dialog.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,24 @@ describe('CredentialDialog', function() {
8585
assert.isFalse(wrapper.find('.github-CredentialDialog-remember').exists());
8686
});
8787
});
88+
89+
describe('show password', function() {
90+
it('sets the passwords input type to "text" on the first click', function() {
91+
wrapper = mount(app);
92+
93+
wrapper.find('.github-DialogLabelButton').simulate('click');
94+
95+
const passwordInput = wrapper.find('.github-CredentialDialog-Password');
96+
assert.equal(passwordInput.prop('type'), 'text');
97+
});
98+
99+
it('sets the passwords input type back to "password" on the second click', function() {
100+
wrapper = mount(app);
101+
102+
wrapper.find('.github-DialogLabelButton').simulate('click').simulate('click');
103+
104+
const passwordInput = wrapper.find('.github-CredentialDialog-Password');
105+
assert.equal(passwordInput.prop('type'), 'password');
106+
});
107+
});
88108
});

0 commit comments

Comments
 (0)