Skip to content

Commit d479a32

Browse files
fix: reset login overlay fields and disabled state on close (#12274) (#12281)
Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
1 parent fcbb66b commit d479a32

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

packages/login/src/vaadin-login-overlay-mixin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const LoginOverlayMixin = (superClass) =>
8686
}
8787

8888
if (props.has('opened')) {
89-
this._openedChanged(this.opened);
89+
this._openedChanged(this.opened, props.get('opened'));
9090
}
9191
}
9292

packages/login/test/login-overlay.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,57 @@ describe('title slot', () => {
304304
});
305305
});
306306

307+
describe('reset on close', () => {
308+
let login, vaadinLoginUsername, vaadinLoginPassword;
309+
310+
beforeEach(async () => {
311+
login = fixtureSync('<vaadin-login-overlay opened></vaadin-login-overlay>');
312+
await nextRender();
313+
({ vaadinLoginUsername, vaadinLoginPassword } = fillUsernameAndPassword(login));
314+
});
315+
316+
it('should clear the username and password fields when closing the overlay', async () => {
317+
login.opened = false;
318+
await nextUpdate(login);
319+
320+
expect(vaadinLoginUsername.value).to.equal('');
321+
expect(vaadinLoginPassword.value).to.equal('');
322+
});
323+
324+
it('should enable the submit button when closing the overlay after submit', async () => {
325+
const submit = login.querySelector('vaadin-button[slot="submit"]');
326+
submit.click();
327+
await nextRender();
328+
expect(submit.disabled).to.be.true;
329+
330+
login.opened = false;
331+
await nextRender();
332+
expect(submit.disabled).to.be.false;
333+
});
334+
335+
it('should not clear the username and password fields when opening the overlay', async () => {
336+
login.opened = false;
337+
await nextUpdate(login);
338+
339+
fillUsernameAndPassword(login);
340+
login.opened = true;
341+
await nextUpdate(login);
342+
343+
expect(vaadinLoginUsername.value).to.equal('username');
344+
expect(vaadinLoginPassword.value).to.equal('password');
345+
});
346+
});
347+
348+
describe('initially closed', () => {
349+
it('should not enable the submit button when disabled is set before attaching', async () => {
350+
const login = fixtureSync('<vaadin-login-overlay disabled></vaadin-login-overlay>');
351+
await nextRender();
352+
353+
expect(login.disabled).to.be.true;
354+
expect(login.querySelector('vaadin-button[slot="submit"]').disabled).to.be.true;
355+
});
356+
});
357+
307358
describe('detach and re-attach', () => {
308359
let login;
309360

0 commit comments

Comments
 (0)