Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/whole-teeth-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@lynx-js/web-elements": patch
---

fix: the `input` event of x-input with number type should have raw value

For `type:=number` x-input with typed value "2."

Before this commit: the value is "2"

After this commit the value is "2."
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ export class InputBaseAttributes
| 'email'
| 'url' = 'text';
let inputType: 'text' | 'number' | 'password' = 'text';
/**
* For number / digit type, if the user is typing "2.", the raw value is expected to remain "2." rather than being altered.
*/
if (attributeValue === 'digit') {
inputMode = 'numeric';
inputType = 'number';
} else if (attributeValue === 'number') {
inputMode = 'decimal';
inputType = 'number';
} else if (attributeValue === 'email') {
inputMode = 'email';
} else if (attributeValue === 'tel') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ export class XInputEvents
{ passive: true },
);
} else {
input.addEventListener(
input.removeEventListener(
Comment thread
PupilTong marked this conversation as resolved.
'input',
this.#teleportInput as (ev: Event) => void,
{ passive: true },
);
input.removeEventListener(
'compositionend',
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions packages/web-platform/web-tests/tests/web-elements.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2408,6 +2408,27 @@ test.describe('web-elements test suite', () => {
},
);

test(
'event-input-number-dot',
async ({ page }, { titlePath }) => {
const title = getTitle(titlePath);
await gotoWebComponentPage(page, title);
const confirmValue = await page
.locator('#target')
.evaluateHandle((target) => {
let detail = { value: undefined };
target.addEventListener('input', (e) => {
detail.value = (e as any).detail.value;
});
return detail;
});
await page.mouse.click(100, 25);
await page.keyboard.type('2.');
await wait(200);
expect((await confirmValue.jsonValue()).value).toBe('2.');
},
);

test(
'method-addText',
async ({ page }, { titlePath, title: simpleTitle }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<!-- Copyright 2024 The Lynx Authors. All rights reserved.
Licensed under the Apache License Version 2.0 that can be found in the
LICENSE file in the root directory of this source tree. -->
<html>
<head>
<meta charset="utf-8">
<title>web playground</title>
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="default" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<meta content="portrait" name="screen-orientation">
<meta
content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"
name="viewport"
>
<meta content="portrait" name="x5-orientation" />

<link
href="/node_modules/@lynx-js/web-elements/index.css"
rel="stylesheet"
/>
<link
href="/web-elements.css"
rel="stylesheet"
/>

<style>
@import url("../../common.css");
</style>
</head>

<body>
<script src="/web-elements.js" defer></script>
<x-view class="page">
<x-input
id="target"
style="height:50px; width:200px;border-width: 1px;"
type="number"
></x-input>
</x-view>
</body>
</html>