Skip to content

Commit 68aec36

Browse files
committed
fix(input): press enter submit form to mimic native input
1 parent 0a582f3 commit 68aec36

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

packages/core/src/components/input/input.tsx

+15-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
Watch,
1212
h,
1313
} from '@stencil/core';
14+
import { ENTER } from 'key-definitions';
1415
import type { AutoCapitalize, EnterKeyHint, FormAssociatedInterface, KeyboardType, Size } from 'src/interface';
1516
import { componentConfig, config } from '#config';
1617
import { type Attributes, hostContext, inheritAriaAttributes, inheritAttributes } from '#utils/helpers';
@@ -404,6 +405,12 @@ export class Input implements ComponentInterface, FormAssociatedInterface {
404405
}, this.debounce || 0);
405406
};
406407

408+
private onKeyUp = (ev: KeyboardEvent): void => {
409+
if (ev.key === ENTER.key) {
410+
this.internals.form?.requestSubmit();
411+
}
412+
};
413+
407414
private onCompositionStart = () => {
408415
this.isComposing = true;
409416
};
@@ -456,17 +463,17 @@ export class Input implements ComponentInterface, FormAssociatedInterface {
456463
>
457464
<slot name="start" />
458465
<input
459-
autoCapitalize={this.autoCapitalize}
460-
autoComplete={this.autoComplete}
461-
autoFocus={this.autoFocus}
466+
autocapitalize={this.autoCapitalize}
467+
autocomplete={this.autoComplete}
468+
autofocus={this.autoFocus}
462469
disabled={this.disabled}
463-
enterKeyHint={this.enterkeyhint}
470+
enterkeyhint={this.enterkeyhint}
464471
id={inputId}
465-
inputMode={this.keyboard}
472+
inputmode={this.keyboard}
466473
max={this.max}
467-
maxLength={this.maxLength}
474+
maxlength={this.maxLength}
468475
min={this.min}
469-
minLength={this.minLength}
476+
minlength={this.minLength}
470477
multiple={this.multiple}
471478
name={this.name}
472479
onBlur={this.onBlur}
@@ -475,6 +482,7 @@ export class Input implements ComponentInterface, FormAssociatedInterface {
475482
onCompositionstart={this.onCompositionStart}
476483
onFocus={this.onFocus}
477484
onInput={this.onInput}
485+
onKeyUp={this.onKeyUp}
478486
part={`native ${this.type}`}
479487
pattern={this.pattern}
480488
placeholder={this.placeholder || ''}

packages/core/src/components/input/tests/form/index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141
<h2>Input - form</h2>
4242
<div>
4343
<form>
44-
<pop-input type="text" name="custom" error-text="test error">input label</pop-input>
44+
<pop-input type="text" value="test" name="custom" error-text="test error">input label</pop-input>
4545
<pop-input type="text" value="default" name="custom-value" error-text="test error">input label</pop-input>
46-
<pop-input type="text" name="custom-value" auto-complete="name">input label</pop-input>
47-
<input type="text" name="native">
46+
<pop-input type="text" name="custom-autocomplete" auto-complete="email">input label</pop-input>
47+
<input type="number" name="native">
4848
<pop-button type="submit" color="primary">submit</pop-button>
4949
<pop-button type="reset" color="ghost">reset</pop-button>
5050
</form>

0 commit comments

Comments
 (0)