Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/views/credential-dialog.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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');
});
});
});