提交 badc3da2 编写于 作者: taohebin@dcloud.io's avatar taohebin@dcloud.io

update: 补充input、textarea的示例和测试例

上级 cb332a62
......@@ -248,6 +248,17 @@
</view>
</view>
<view>
<view class="uni-title" style="flex-direction: row;align-items: center;">
<text class="uni-title-text">设置adjust-position</text>
<switch style="margin-left: 10px;" @change="changeAdjustPosition" :checked="adjustPosition"></switch>
</view>
<view class="input-wrapper">
<input class="uni-input" :adjust-position="adjustPosition"/>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
......@@ -282,7 +293,8 @@
holdKeyboard: false,
keyboardHeight: 0,
focusedForKeyboardHeightChangeTest: false,
demoValue: '123'
demoValue: '123',
adjustPosition: false
}
},
methods: {
......@@ -359,6 +371,10 @@
changeHoldKeyboard(event : UniSwitchChangeEvent) {
const checked = event.detail.value;
this.holdKeyboard = checked
},
changeAdjustPosition(event : UniSwitchChangeEvent){
const checked = event.detail.value;
this.adjustPosition = checked
}
}
}
......
......@@ -81,4 +81,21 @@ describe('component-native-textarea', () => {
expect(await textarea2.value()).toBe("123")
})
}
it("maxlength", async () => {
const input = await page.$('#textarea-instance-maxlength');
let str = "";
for(let i = 0;i < 200;i++){
str += `${i}`
}
await page.setData({
textareaMaxLengthValue: str
})
let length = (await input.value()).length
expect(length).toBe(10)
await page.setData({
textareaMaxLengthValue: ""
})
})
});
<script>
import { ItemType } from '@/components/enum-data/enum-data'
export default {
import { ItemType } from '@/components/enum-data/enum-data'
export default {
data() {
return {
adjust_position_boolean: false,
......@@ -10,16 +10,20 @@ export default {
confirm_hold_boolean: false,
focus_boolean: true,
auto_focus_boolean: false,
default_value:"1\n2\n3\n4\n5\n6",
maxlength:-1,
inputmode_enum: [{"value":1,"name":"text"},{"value":2,"name":"decimal"},{"value":3,"name":"numeric"},{"value":4,"name":"tel"},{"value":5,"name":"search"},{"value":6,"name":"email"},{"value":7,"name":"url"},{"value":0,"name":"none"}] as ItemType[],
confirm_type_list: [{"value":0,"name":"return"},{"value":1,"name":"done"},{"value":2,"name":"send"},{"value":3,"name":"search"},{"value":4,"name":"next"},{"value":5,"name":"go"}] as ItemType[],
default_value: "1\n2\n3\n4\n5\n6",
inputmode_enum: [{ "value": 1, "name": "text" }, { "value": 2, "name": "decimal" }, { "value": 3, "name": "numeric" }, { "value": 4, "name": "tel" }, { "value": 5, "name": "search" }, { "value": 6, "name": "email" }, { "value": 7, "name": "url" }, { "value": 0, "name": "none" }] as ItemType[],
confirm_type_list: [{ "value": 0, "name": "return" }, { "value": 1, "name": "done" }, { "value": 2, "name": "send" }, { "value": 3, "name": "search" }, { "value": 4, "name": "next" }, { "value": 5, "name": "go" }] as ItemType[],
cursor_color: "#3393E2",
cursor: 0,
inputmode_enum_current: 0,
confirm_type_current: 0,
placeholder_value: "请输入",
defaultModel:'123'
defaultModel: '123',
textareaMaxLengthValue: "",
selectionStart: -1,
selectionEnd: -1,
hold_keyboard: false,
adjust_position: false
}
},
......@@ -44,11 +48,27 @@ export default {
change_confirm_hold_boolean(checked : boolean) { this.confirm_hold_boolean = checked },
change_focus_boolean(checked : boolean) { this.focus_boolean = checked },
change_auto_focus_boolean(checked : boolean) { this.auto_focus_boolean = checked },
change_cursor_color_boolean(checked : boolean) { if(checked){ this.cursor_color = "transparent"} else {this.cursor_color = "#3393E2"}},
change_cursor_color_boolean(checked : boolean) { if (checked) { this.cursor_color = "transparent" } else { this.cursor_color = "#3393E2" } },
radio_change_inputmode_enum(checked : number) { this.inputmode_enum_current = checked },
radio_change_confirm_type(checked : number) { this.confirm_type_current = checked }
radio_change_confirm_type(checked : number) { this.confirm_type_current = checked },
setSelection: function (selectionStart : number, selectionEnd : number) {
uni.getElementById("textarea-instance-2")?.focus()
this.selectionStart = selectionStart;
this.selectionEnd = selectionEnd;
},
onSelectionBlurChange() {
this.selectionEnd = 0;
},
changeHoldKeyboard(event : UniSwitchChangeEvent) {
const checked = event.detail.value;
this.hold_keyboard = checked;
},
changeAdjustPosition(event : UniSwitchChangeEvent) {
const checked = event.detail.value;
this.adjust_position = checked;
}
}
}
}
</script>
<template>
......@@ -56,115 +76,122 @@ export default {
<scroll-view style="flex: 1">
<!-- #endif -->
<view class="main">
<textarea
:value="default_value"
class="uni-textarea"
:auto-focus="true"
:focus="focus_boolean"
:confirm-hold="confirm_hold_boolean"
:auto-height="auto_height_boolean"
:fixed="fixed_boolean"
:show-confirm-bar="show_confirm_bar_boolean"
:adjust-position="adjust_position_boolean"
:cursor-color="cursor_color"
:cursor="cursor"
:placeholder="placeholder_value"
<textarea :value="default_value" class="uni-textarea" :auto-focus="true" :focus="focus_boolean"
:confirm-hold="confirm_hold_boolean" :auto-height="auto_height_boolean" :fixed="fixed_boolean"
:show-confirm-bar="show_confirm_bar_boolean" :adjust-position="adjust_position_boolean"
:cursor-color="cursor_color" :cursor="cursor" :placeholder="placeholder_value"
:inputmode="inputmode_enum[inputmode_enum_current].name"
:confirm-type="confirm_type_list[confirm_type_current].name"
:maxlength="maxlength"
@click="textarea_click"
@touchstart="textarea_touchstart"
@touchmove="textarea_touchmove"
@touchcancel="textarea_touchcancel"
@touchend="textarea_touchend"
@tap="textarea_tap"
@longpress="textarea_longpress"
@confirm="textarea_confirm"
@input="textarea_input"
@linechange="textarea_linechange"
@blur="textarea_blur"
@keyboardheightchange="textarea_keyboardheightchange"
@focus="textarea_focus"
style="padding: 10px; border: 1px solid #666;height: 200px"
/>
:confirm-type="confirm_type_list[confirm_type_current].name" @click="textarea_click"
@touchstart="textarea_touchstart" @touchmove="textarea_touchmove" @touchcancel="textarea_touchcancel"
@touchend="textarea_touchend" @tap="textarea_tap" @longpress="textarea_longpress" @confirm="textarea_confirm"
@input="textarea_input" @linechange="textarea_linechange" @blur="textarea_blur"
@keyboardheightchange="textarea_keyboardheightchange" @focus="textarea_focus"
style="padding: 10px; border: 1px solid #666;height: 200px" />
</view>
<view class="content">
<boolean-data
:defaultValue="false"
title="键盘弹起时,是否自动上推页面(限非 Web 平台)"
@change="change_adjust_position_boolean"
></boolean-data>
<boolean-data
:defaultValue="false"
title="是否自动增高,设置auto-height时,style.height不生效"
@change="change_auto_height_boolean"
></boolean-data>
<boolean-data
:defaultValue="focus_boolean"
title="获取焦点"
@change="change_focus_boolean"
></boolean-data>
<boolean-data
:defaultValue="true"
title="首次自动获取焦点"
@change="change_auto_focus_boolean"
></boolean-data>
<boolean-data
:defaultValue="false"
title="改变光标颜色为透明"
@change="change_cursor_color_boolean"
></boolean-data>
<enum-data
:items="confirm_type_list"
title="confirm-type,设置键盘右下角按钮。(Android仅支持return)"
@change="radio_change_confirm_type"
></enum-data>
<boolean-data
:defaultValue="false"
title="点击软键盘右下角按钮时是否保持键盘不收起(confirm-type为return时必然不收起)"
@change="change_confirm_hold_boolean"
></boolean-data>
<enum-data
:items="inputmode_enum"
title="input-mode,控制软键盘类型。(仅限 Web 平台符合条件的高版本浏览器或webview)。"
@change="radio_change_inputmode_enum"
></enum-data>
<boolean-data
:defaultValue="false"
title="是否显示键盘上方带有“完成”按钮那一栏(仅限小程序平台)"
@change="change_show_confirm_bar_boolean"
></boolean-data>
<boolean-data
:defaultValue="false"
title="如果 textarea 是在一个 position:fixed 的区域,需要显示指定属性 fixed 为 true(仅限小程序平台)"
@change="change_fixed_boolean"
></boolean-data>
<view style="flex-direction:row;justify-content:center;">
<textarea id="textarea-height-exception" style="flex:1;border: 1 solid #666;margin: 10px" placeholder="底部textarea测试键盘遮挡"/>
<boolean-data :defaultValue="false" title="键盘弹起时,是否自动上推页面(限非 Web 平台)"
@change="change_adjust_position_boolean"></boolean-data>
<boolean-data :defaultValue="false" title="是否自动增高,设置auto-height时,style.height不生效"
@change="change_auto_height_boolean"></boolean-data>
<boolean-data :defaultValue="focus_boolean" title="获取焦点" @change="change_focus_boolean"></boolean-data>
<boolean-data :defaultValue="true" title="首次自动获取焦点" @change="change_auto_focus_boolean"></boolean-data>
<boolean-data :defaultValue="false" title="改变光标颜色为透明" @change="change_cursor_color_boolean"></boolean-data>
<enum-data :items="confirm_type_list" title="confirm-type,设置键盘右下角按钮。(Android仅支持return)"
@change="radio_change_confirm_type"></enum-data>
<boolean-data :defaultValue="false" title="点击软键盘右下角按钮时是否保持键盘不收起(confirm-type为return时必然不收起)"
@change="change_confirm_hold_boolean"></boolean-data>
<enum-data :items="inputmode_enum" title="input-mode,控制软键盘类型。(仅限 Web 平台符合条件的高版本浏览器或webview)。"
@change="radio_change_inputmode_enum"></enum-data>
<boolean-data :defaultValue="false" title="是否显示键盘上方带有“完成”按钮那一栏(仅限小程序平台)"
@change="change_show_confirm_bar_boolean"></boolean-data>
<boolean-data :defaultValue="false" title="如果 textarea 是在一个 position:fixed 的区域,需要显示指定属性 fixed 为 true(仅限小程序平台)"
@change="change_fixed_boolean"></boolean-data>
<view class="title-wrap">
<view>maxlength 输入最大长度为10</view>
</view>
<view class="textarea-wrap">
<textarea id="textarea-instance-maxlength" class="textarea-instance" :value="textareaMaxLengthValue"
:maxlength="10" />
</view>
<view class="title-wrap">
<view>cursor-spacing、placeholder-class、placeholder-style例子</view>
</view>
<view class="textarea-wrap">
<textarea id="textarea-height-exception" class="textarea-instance" placeholder="底部textarea测试键盘遮挡"
placeholder-class="placeholder" placeholder-style="background-color:red" :cursor-spacing="300" />
</view>
<view class="title-wrap">
<view>同时存在 v-model 和 value</view>
<view class="main">
<textarea class="list-item both-set-textarea" v-model='defaultModel' value='456'></textarea>
</view>
<view class="textarea-wrap">
<textarea class="textarea-instance" v-model='defaultModel' value='456'></textarea>
</view>
<view class="title-wrap">
<view @click="setSelection(2, 5)">设置输入框聚焦时光标的起始位置和结束位置(点击生效)</view>
</view>
<view class="textarea-wrap">
<textarea id="textarea-instance-2" class="textarea-instance" value="Hello UniApp X Textarea TestCase"
:selection-start="selectionStart" :selection-end="selectionEnd" @blur="onSelectionBlurChange" />
</view>
<view class="title-wrap">
<view>设置hold-keyboard</view>
<switch style="margin-left: 10px;" @change="changeHoldKeyboard" :checked="hold_keyboard"></switch>
</view>
<view class="textarea-wrap">
<textarea class="textarea-instance" :hold-keyboard="hold_keyboard" />
</view>
<view class="title-wrap">
<view>设置adjust-position</view>
<switch style="margin-left: 10px;" @change="changeAdjustPosition" :checked="adjust_position"></switch>
</view>
<view class="textarea-wrap">
<textarea class="textarea-instance" :adjust-position="adjust_position" />
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<style>
.main {
.main {
min-height: 100px;
padding: 5px 0;
border-bottom: 1px solid rgba(0, 0, 0, 0.06);
flex-direction: row;
justify-content: center;
}
}
.main .list-item {
.main .list-item {
width: 100%;
height: 100px;
border: 1px solid #666;
}
}
.textarea-wrap {
flex-direction: row;
justify-content: center;
}
.title-wrap {
flex-direction: row;
align-items: center;
margin-left: 10px;
}
.textarea-instance {
flex: 1;
border: 1 solid #666;
margin: 10px;
}
.placeholder {
background-color: yellow;
}
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册