Skip to content

Commit 2c6139d

Browse files
authored
fix(ui5-input): number input doesn't lose value (#2130)
1 parent 306572f commit 2c6139d

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

packages/main/src/Input.js

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
isDown,
1111
isSpace,
1212
isEnter,
13+
isBackSpace,
1314
} from "@ui5/webcomponents-base/dist/Keys.js";
1415
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
1516
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
@@ -676,6 +677,11 @@ class Input extends UI5Element {
676677
async _handleInput(event) {
677678
const inputDomRef = await this.getInputDOMRef();
678679

680+
if (this.value && this.type === InputType.Number && !isBackSpace(event) && !inputDomRef.value) {
681+
// For input with type="Number", if the delimiter is entered second time, the inner input is firing event with empty value
682+
return;
683+
}
684+
679685
if (event.target === inputDomRef) {
680686
// stop the native event, as the semantic "input" would be fired.
681687
event.stopImmediatePropagation();

packages/main/test/pages/Input.html

+2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ <h3> Input required</h3>
144144
<h3> Input type 'Number'</h3>
145145
<ui5-input id="input-number" type="Number" placeholder="Numbers are allowed only ..."></ui5-input>
146146

147+
<ui5-input id="input-number2" type="Number" placeholder="Numbers are allowed only ..."></ui5-input>
148+
147149
<h3> Input type 'Password'</h3>
148150
<ui5-input id="input-password" type="Password" placeholder="Typing in private ..."></ui5-input>
149151

packages/main/test/specs/Input.spec.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ describe("Input general interaction", () => {
154154
assert.equal(suggestionsScrollable, true, "The suggestions popup is scrolalble");
155155

156156
// close suggestions
157-
input.keys("Enter");
157+
input.keys("Enter");
158158
});
159159

160160
it("handles suggestions", () => {
@@ -293,7 +293,19 @@ describe("Input general interaction", () => {
293293
const firstListItem = respPopover.$("ui5-list").$("ui5-li-suggestion-item");
294294

295295
assert.ok(respPopover.isDisplayedInViewport(), "The popover is visible");
296-
assert.ok(firstListItem.getHTML().indexOf(EXPTECTED_TEXT) !== -1, "The suggestions is highlighted.")
296+
assert.ok(firstListItem.getHTML().indexOf(EXPTECTED_TEXT) !== -1, "The suggestions is highlighted.");
297+
});
298+
299+
it("Doesn't remove value on number type input even if locale specific delimiter/multiple delimiters", () => {
300+
const input = browser.$("#input-number2");
301+
302+
input.click();
303+
input.keys("1.22.33");
304+
input.keys("Tab");
305+
306+
browser.pause(500);
307+
308+
assert.strictEqual(parseFloat(input.getProperty("value")), 1.22, "Value is not lost");
297309
});
298310

299311
it("fires suggestion-item-preview", () => {
@@ -308,7 +320,7 @@ describe("Input general interaction", () => {
308320
inputItemPreview.keys("c");
309321

310322
inputItemPreview.keys("ArrowDown");
311-
323+
312324
// assert
313325
const staticAreaItemClassName = browser.getStaticAreaItemClassName("#inputPreview2");
314326
const inputPopover = browser.$(`.${staticAreaItemClassName}`).shadow$("ui5-responsive-popover");
@@ -326,4 +338,4 @@ describe("Input general interaction", () => {
326338
assert.notOk(inputPopover.isDisplayedInViewport(), "The inpuit popover is closed as it lost the focus.");
327339
assert.ok(helpPopover.isDisplayedInViewport(), "The help popover remains open as the focus is within.");
328340
});
329-
});
341+
});

0 commit comments

Comments
 (0)