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

Add button to show/hide password in credentials dialog #1808

Merged
merged 3 commits into from Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/views/credential-dialog.js
Expand Up @@ -23,12 +23,14 @@ export default class CredentialDialog extends React.Component {

constructor(props, context) {
super(props, context);
autobind(this, 'confirm', 'cancel', 'onUsernameChange', 'onPasswordChange', 'onRememberChange', 'focusFirstInput');
autobind(this, 'confirm', 'cancel', 'onUsernameChange', 'onPasswordChange', 'onRememberChange',
'focusFirstInput', 'toggleShowPassword');

this.state = {
username: '',
password: '',
remember: false,
showPassword: false,
};
}

Expand Down Expand Up @@ -61,13 +63,16 @@ export default class CredentialDialog extends React.Component {
<label className="github-DialogLabel">
Password:
<input
type="password"
type={this.state.showPassword ? 'text' : 'password'}
ref={e => (this.passwordInput = e)}
className="input-text github-CredentialDialog-Password"
value={this.state.password}
onChange={this.onPasswordChange}
tabIndex="2"
/>
<button className="github-DialogLabelButton" onClick={this.toggleShowPassword}>
{this.state.showPassword ? 'Hide' : 'Show'}
</button>
</label>
</main>
<footer className="github-DialogButtons">
Expand Down Expand Up @@ -122,4 +127,8 @@ export default class CredentialDialog extends React.Component {
focusFirstInput() {
(this.usernameInput || this.passwordInput).focus();
}

toggleShowPassword() {
this.setState({showPassword: !this.state.showPassword});
}
}
15 changes: 15 additions & 0 deletions styles/dialog.less
Expand Up @@ -19,7 +19,22 @@
&Label {
flex: 1;
margin: @github-dialog-spacing;
position: relative;
line-height: 2;

&Button {
position: absolute;
background: transparent;
right: .3em;
bottom: 0;
border: none;
color: @text-color-subtle;
cursor: pointer;

&:hover {
color: @text-color-highlight;
}
}
}

&Buttons {
Expand Down
20 changes: 20 additions & 0 deletions test/views/credential-dialog.test.js
Expand Up @@ -85,4 +85,24 @@ describe('CredentialDialog', function() {
assert.isFalse(wrapper.find('.github-CredentialDialog-remember').exists());
});
});

describe('show password', function() {
it('sets the passwords input type to "text" on the first click', function() {
wrapper = mount(app);

wrapper.find('.github-DialogLabelButton').simulate('click');

const passwordInput = wrapper.find('.github-CredentialDialog-Password');
assert.equal(passwordInput.prop('type'), 'text');
});

it('sets the passwords input type back to "password" on the second click', function() {
wrapper = mount(app);

wrapper.find('.github-DialogLabelButton').simulate('click').simulate('click');

const passwordInput = wrapper.find('.github-CredentialDialog-Password');
assert.equal(passwordInput.prop('type'), 'password');
});
});
});