Skip to content

Commit 94818e4

Browse files
author
Joren Broekema
committed
fix(button): change redispatch click logic so form submit fires properly
1 parent 1ef9535 commit 94818e4

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

packages/button/src/LionButton.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,11 @@ export class LionButton extends DisabledWithTabIndexMixin(SlotMixin(LitElement))
176176
}
177177

178178
/**
179-
* Prevent normal click and redispatch click on the native button unless already redispatched.
179+
* Prevent normal click and redispatch submit on the native button unless already redispatched.
180180
*/
181-
__clickDelegationHandler(e) {
182-
if (!e.__isRedispatchedOnNativeButton) {
183-
e.stopImmediatePropagation();
184-
this._redispatchClickEvent(e);
181+
__clickDelegationHandler() {
182+
if (this.type === 'submit' && this._nativeButtonNode.form) {
183+
this._nativeButtonNode.form.submit();
185184
}
186185
}
187186

packages/button/stories/index.stories.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ storiesOf('Buttons|Button', module)
3535
.add(
3636
'Within a form',
3737
() => html`
38-
<lion-form id="form"
38+
<lion-form id="form" @submit=${() => console.log('form submitted')}
3939
><form>
4040
<lion-input name="foo" label="Foo" .modelValue=${'bar'}></lion-input>
41+
<lion-input name="foo2" label="Foo2" .modelValue=${'bar'}></lion-input>
4142
<lion-button
4243
type="submit"
4344
@click=${() => console.log(document.querySelector('#form').serializeGroup())}
@@ -46,4 +47,16 @@ storiesOf('Buttons|Button', module)
4647
</form></lion-form
4748
>
4849
`,
49-
);
50+
)
51+
.add('Within another form', () => {
52+
const submitForm = () => console.log('hey');
53+
return html`
54+
<form id="form" @submit=${submitForm}>
55+
<h3>Details</h3>
56+
<input name="input1" />
57+
<input name="input2" />
58+
<input name="input3" />
59+
<lion-button>Submit</lion-button>
60+
</form>
61+
`;
62+
});

0 commit comments

Comments
 (0)