Skip to content

Commit 53eed0a

Browse files
authored
feat(web): builtinTagTransformMap add input for x-input (#1907)
<!-- Thank you for submitting a pull request! We appreciate the time and effort you have invested in making these changes. Please ensure that you provide enough information to allow others to review your pull request. Upon submission, your pull request will be automatically assigned with reviewers. If you want to learn more about contributing to this project, please visit: https://github.com/lynx-family/lynx-stack/blob/main/CONTRIBUTING.md. --> <!-- The AI summary below will be auto-generated - feel free to replace it with your own. --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Added support for input element transformation to the x-input component. * **Tests** * Added test coverage for input element binding behavior. * **Chores** * Updated patch versions for core packages. <!-- end of auto-generated comment: release notes by coderabbit.ai --> ## Checklist <!--- Check and mark with an "x" --> - [ ] Tests updated (or not required). - [ ] Documentation updated (or not required). - [ ] Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).
1 parent b736b6e commit 53eed0a

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

.changeset/seven-coats-appear.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@lynx-js/web-core-server": patch
3+
"@lynx-js/web-core": patch
4+
"@lynx-js/web-explorer": patch
5+
---
6+
7+
feat: builtinTagTransformMap add `'input': 'x-input'`

packages/web-platform/web-core-server/src/createLynxView.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const builtinTagTransformMap = {
8181
'image': 'x-image',
8282
'list': 'x-list',
8383
'svg': 'x-svg',
84+
'input': 'x-input',
8485
};
8586

8687
// @ts-expect-error

packages/web-platform/web-core/src/apis/LynxView.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ export class LynxView extends HTMLElement {
420420
'image': 'x-image',
421421
'list': 'x-list',
422422
'svg': 'x-svg',
423+
'input': 'x-input',
423424
...this.overrideLynxTagToHTMLTagMap,
424425
};
425426
if (!this.shadowRoot) {

packages/web-platform/web-tests/tests/react.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,6 +3003,16 @@ test.describe('reactlynx3 tests', () => {
30033003
const result = await page.locator('.result').first().innerText();
30043004
expect(result).toBe('foobar-6-6');
30053005
});
3006+
// input/bindinput test-case start for <input>
3007+
test('basic-element-input-bindinput', async ({ page }, { title }) => {
3008+
await goto(page, title);
3009+
await page.locator('input').press('Enter');
3010+
await wait(200);
3011+
await page.locator('input').fill('foobar');
3012+
await wait(200);
3013+
const result = await page.locator('.result').first().innerText();
3014+
expect(result).toBe('foobar-6-6');
3015+
});
30063016
// input/bindinput test-case end
30073017
test(
30083018
'basic-element-x-input-getValue',
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2023 The Lynx Authors. All rights reserved.
2+
// Licensed under the Apache License Version 2.0 that can be found in the
3+
// LICENSE file in the root directory of this source tree.
4+
import { root, useState } from '@lynx-js/react';
5+
6+
function App() {
7+
const value = 'bindinput';
8+
const [result, setResult] = useState();
9+
10+
const onInput = ({ detail }) => {
11+
if (typeof detail !== 'object') {
12+
throw new Error(
13+
`detail type not match. expect object, got ${typeof detail}`,
14+
);
15+
}
16+
17+
const { value, cursor, textLength, selectionStart, selectionEnd } = detail;
18+
19+
if (value.length !== textLength) {
20+
throw new Error(
21+
`input length not match. expect ${textLength}, got ${value.length}`,
22+
);
23+
}
24+
25+
setResult(`${value}-${selectionStart}-${selectionStart}`);
26+
};
27+
28+
return (
29+
<view>
30+
<input
31+
bindinput={onInput}
32+
value={value}
33+
style='border: 1px solid;width: 300px;height:40px'
34+
/>
35+
<view class='result'>
36+
<text>{result}</text>
37+
</view>
38+
</view>
39+
);
40+
}
41+
42+
root.render(<App></App>);

0 commit comments

Comments
 (0)