Skip to content

Commit

Permalink
Trigger submit on form section Enter key press (aws-amplify#5467)
Browse files Browse the repository at this point in the history
* Trigger submit on form section Enter key press

* Add base unit test
  • Loading branch information
jordanranz authored Apr 20, 2020
1 parent 7cab470 commit 307628f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ describe('amplify-form-section spec:', () => {
it('should render `Submit` for the button text', () => {
expect(formSection.submitButtonText).toEqual('Submit');
});

it('`handleKeyDown` should be defined', () => {
expect(formSection.handleKeyDown).toBeDefined();
})

});
describe('Render logic ->', () => {
it('should render a form section with a submit button text of `Go`', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Prop, h, FunctionalComponent } from '@stencil/core';
import { Component, Prop, h, FunctionalComponent, Listen } from '@stencil/core';

@Component({
tag: 'amplify-form-section',
Expand All @@ -19,6 +19,13 @@ export class AmplifyFormSection {
/** Secondary footer component or text */
@Prop() secondaryFooterContent: string | FunctionalComponent | null = null;

@Listen('keydown')
handleKeyDown(ev: KeyboardEvent) {
if (ev.key === 'Enter') {
this.handleSubmit(ev);
}
}

render() {
return (
<form onSubmit={this.handleSubmit}>
Expand Down

0 comments on commit 307628f

Please sign in to comment.