Skip to content

Commit 0f2dfc6

Browse files
Mikhail BashkirovDaniel Alarcon Amador
andcommitted
fix(input-datepicker): prevent button from submitting forms
Co-authored-by: Daniel Alarcon Amador <daniel.amador@ing.com>
1 parent f9824ae commit 0f2dfc6

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

packages/input-datepicker/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@lion/button": "^0.1.14",
4747
"@open-wc/demoing-storybook": "^0.2.0",
4848
"@open-wc/testing": "^0.11.1",
49-
"@polymer/iron-test-helpers": "^3.0.1"
49+
"@polymer/iron-test-helpers": "^3.0.1",
50+
"sinon": "^7.2.2"
5051
}
5152
}

packages/input-datepicker/src/LionInputDatepicker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ export class LionInputDatepicker extends LionInputDate {
274274
// (a.k.a. dropdowns) as well. Important: will be breaking for subclassers
275275
return html`
276276
<button
277+
type="button"
277278
@click="${this.__openCalendarOverlay}"
278279
id="${this.__invokerId}"
279280
aria-haspopup="dialog"

packages/input-datepicker/test/lion-input-datepicker.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect, fixture, aTimeout, defineCE } from '@open-wc/testing';
2+
import sinon from 'sinon';
23
import { localizeTearDown } from '@lion/localize/test-helpers.js';
34
import { html, LitElement } from '@lion/core';
45
import {
@@ -422,4 +423,20 @@ describe('<lion-input-datepicker>', () => {
422423
it.skip('can configure the overlay presentation based on media query switch', async () => {});
423424
});
424425
});
426+
427+
describe('regression tests', async () => {
428+
it('does not submit a form when datepicker is opened', async () => {
429+
const submitSpy = sinon.spy();
430+
const form = await fixture(html`
431+
<form @submit="${submitSpy}">
432+
<lion-input-datepicker></lion-input-datepicker>
433+
</form>
434+
`);
435+
const el = form.children[0];
436+
await el.updateComplete;
437+
const elObj = new DatepickerInputObject(el);
438+
await elObj.openCalendar();
439+
expect(submitSpy.callCount).to.equal(0);
440+
});
441+
});
425442
});

0 commit comments

Comments
 (0)