Skip to content

Commit

Permalink
fix(ui5-input): number input doesn't lose value (#2130)
Browse files Browse the repository at this point in the history
  • Loading branch information
fifoosid committed Sep 2, 2020
1 parent 306572f commit 2c6139d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions packages/main/src/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
isDown,
isSpace,
isEnter,
isBackSpace,
} from "@ui5/webcomponents-base/dist/Keys.js";
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
Expand Down Expand Up @@ -676,6 +677,11 @@ class Input extends UI5Element {
async _handleInput(event) {
const inputDomRef = await this.getInputDOMRef();

if (this.value && this.type === InputType.Number && !isBackSpace(event) && !inputDomRef.value) {
// For input with type="Number", if the delimiter is entered second time, the inner input is firing event with empty value
return;
}

if (event.target === inputDomRef) {
// stop the native event, as the semantic "input" would be fired.
event.stopImmediatePropagation();
Expand Down
2 changes: 2 additions & 0 deletions packages/main/test/pages/Input.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ <h3> Input required</h3>
<h3> Input type 'Number'</h3>
<ui5-input id="input-number" type="Number" placeholder="Numbers are allowed only ..."></ui5-input>

<ui5-input id="input-number2" type="Number" placeholder="Numbers are allowed only ..."></ui5-input>

<h3> Input type 'Password'</h3>
<ui5-input id="input-password" type="Password" placeholder="Typing in private ..."></ui5-input>

Expand Down
20 changes: 16 additions & 4 deletions packages/main/test/specs/Input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe("Input general interaction", () => {
assert.equal(suggestionsScrollable, true, "The suggestions popup is scrolalble");

// close suggestions
input.keys("Enter");
input.keys("Enter");
});

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

assert.ok(respPopover.isDisplayedInViewport(), "The popover is visible");
assert.ok(firstListItem.getHTML().indexOf(EXPTECTED_TEXT) !== -1, "The suggestions is highlighted.")
assert.ok(firstListItem.getHTML().indexOf(EXPTECTED_TEXT) !== -1, "The suggestions is highlighted.");
});

it("Doesn't remove value on number type input even if locale specific delimiter/multiple delimiters", () => {
const input = browser.$("#input-number2");

input.click();
input.keys("1.22.33");
input.keys("Tab");

browser.pause(500);

assert.strictEqual(parseFloat(input.getProperty("value")), 1.22, "Value is not lost");
});

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

inputItemPreview.keys("ArrowDown");

// assert
const staticAreaItemClassName = browser.getStaticAreaItemClassName("#inputPreview2");
const inputPopover = browser.$(`.${staticAreaItemClassName}`).shadow$("ui5-responsive-popover");
Expand All @@ -326,4 +338,4 @@ describe("Input general interaction", () => {
assert.notOk(inputPopover.isDisplayedInViewport(), "The inpuit popover is closed as it lost the focus.");
assert.ok(helpPopover.isDisplayedInViewport(), "The help popover remains open as the focus is within.");
});
});
});

0 comments on commit 2c6139d

Please sign in to comment.