Skip to content

Commit 9b5067a

Browse files
author
xueyuan
committed
feat(ui/input): add select method
- Add select() method to select all text in input Closes #1912 docs(input): 移除输入组件文档中的键盘事件相关内容 refactor(input): 移除不必要的输入组件测试用例 refactor(input): 移除键盘事件处理器 refactor(input/example): 移除未使用的Snackbar导入 feat(input/docs): 添加en-US新的输入示例和选择全部功能 docs(input): 移除输入组件文档中的回车键事件示例 feat(input): add select method and clean up redundant code - Add select() method to Input component for programmatic text selection - Clean up redundant keyboard event handlers in examples and docs - Fix variable naming consistency in documentation - Remove unused handleEnter functions and value15 variables - Update type definitions to include select method docs(input/locale): 更新输入组件英文文档的术语描述
1 parent a935cea commit 9b5067a

7 files changed

Lines changed: 73 additions & 3 deletions

File tree

packages/varlet-ui/src/input/Input.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,11 @@ export default defineComponent({
368368
;(el.value as HTMLInputElement).blur()
369369
}
370370
371+
// expose
372+
function select() {
373+
;(el.value as HTMLInputElement).select()
374+
}
375+
371376
return {
372377
el,
373378
id,
@@ -397,6 +402,7 @@ export default defineComponent({
397402
reset,
398403
focus,
399404
blur,
405+
select,
400406
}
401407
},
402408
})

packages/varlet-ui/src/input/docs/en-US.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ const value11 = ref('')
2525
const value12 = ref('')
2626
const value13 = ref('')
2727
const value14 = ref('')
28+
const value15 = ref('')
29+
const inputRef = ref()
30+
31+
const selectAll = () => {
32+
inputRef.value?.select()
33+
}
2834
</script>
2935
3036
<template>
@@ -69,6 +75,14 @@ const value14 = ref('')
6975
<var-input placeholder="Textarea" textarea v-model="value10" />
7076
<var-input placeholder="Small Size" size="small" v-model="value11" />
7177
<var-input placeholder="Removes whitespace from both ends of this string" v-model.trim="value12" />
78+
<var-space>
79+
<var-input
80+
ref="inputRef"
81+
placeholder="Enter text and click the button to select all"
82+
v-model="value15"
83+
/>
84+
<var-button type="primary" @click="selectAll">Select All</var-button>
85+
</var-space>
7286
</var-space>
7387
</template>
7488
@@ -104,6 +118,12 @@ const value11 = ref('')
104118
const value12 = ref('')
105119
const value13 = ref('')
106120
const value14 = ref('')
121+
const value15 = ref('')
122+
const inputRef = ref()
123+
124+
const selectAll = () => {
125+
inputRef.value?.select()
126+
}
107127
</script>
108128
109129
<template>
@@ -154,6 +174,14 @@ const value14 = ref('')
154174
<var-input variant="outlined" placeholder="Textarea" textarea v-model="value10" />
155175
<var-input variant="outlined" placeholder="Small Size" size="small" v-model="value11" />
156176
<var-input variant="outlined" placeholder="Removes whitespace from both ends of this string" v-model.trim="value12" />
177+
<var-space>
178+
<var-input
179+
ref="inputRef"
180+
placeholder="Enter text and click the button to select all"
181+
v-model="value15"
182+
/>
183+
<var-button type="primary" @click="selectAll">Select All</var-button>
184+
</var-space>
157185
</var-space>
158186
</template>
159187
@@ -203,6 +231,7 @@ const value14 = ref('')
203231
| --- | --- | --- | --- |
204232
| `focus` | Focus | `-` | `-` |
205233
| `blur` | Blur | `-` | `-` |
234+
| `select` | Select all text in the input | `-` | `-` |
206235
| `validate` | Trigger validate | `-` | `valid: Promise<boolean>` |
207236
| `resetValidation` | Clear validate messages | `-` | `-` |
208237
| `reset` | Clear the value of the binding and validate messages | `-` | `-` |
@@ -218,6 +247,7 @@ const value14 = ref('')
218247
| `input` | Triggered on input | `value: string`, `event: Event` |
219248
| `change` | Triggered on change | `value: string`, `event: Event` |
220249
250+
221251
### Slots
222252
223253
| Name | Description | SlotProps |

packages/varlet-ui/src/input/docs/zh-CN.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<script setup>
1111
import { ref } from 'vue'
1212
import { z } from 'zod'
13+
import { Snackbar } from '@varlet/ui'
1314
1415
const value = ref('')
1516
const value2 = ref('')
@@ -25,6 +26,12 @@ const value11 = ref('')
2526
const value12 = ref('')
2627
const value13 = ref('')
2728
const value14 = ref('')
29+
const value15 = ref('')
30+
const inputRef = ref()
31+
32+
const selectAll = () => {
33+
inputRef.value?.select()
34+
}
2835
</script>
2936
3037
<template>
@@ -69,6 +76,14 @@ const value14 = ref('')
6976
<var-input placeholder="文本域" textarea v-model="value10" />
7077
<var-input placeholder="小尺寸" size="small" v-model="value11" />
7178
<var-input placeholder="移除空白字符" v-model.trim="value12" />
79+
<var-space>
80+
<var-input
81+
ref="inputRef"
82+
placeholder="输入文本后点击按钮全选"
83+
v-model="value15"
84+
/>
85+
<var-button type="primary" @click="selectAll">全选</var-button>
86+
</var-space>
7287
</var-space>
7388
</template>
7489
@@ -203,6 +218,7 @@ const value14 = ref('')
203218
| --- | --- | --- | --- |
204219
| `focus` | 聚焦 | `-` | `-` |
205220
| `blur` | 失焦 | `-` | `-` |
221+
| `select` | 选中输入框中的所有文本 | `-` | `-` |
206222
| `validate` | 触发校验 | `-` | `valid: Promise<boolean>` |
207223
| `resetValidation` | 清空校验信息 | `-` | `-` |
208224
| `reset` | 清空绑定的值和校验信息 | `-` | `-` |
@@ -218,6 +234,7 @@ const value14 = ref('')
218234
| `input` | 输入时触发 | `value: string`, `event: Event` |
219235
| `change` | 更新时触发 | `value: string`, `event: Event` |
220236
237+
221238
### 插槽
222239
223240
| 插槽名 | 说明 | 参数 |

packages/varlet-ui/src/input/example/index.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const standardValue11 = ref('')
1818
const standardValue12 = ref('')
1919
const standardValue13 = ref('')
2020
const standardValue14 = ref('')
21+
const standardValue15 = ref('')
2122
2223
const outlinedValue = ref('')
2324
const outlinedValue2 = ref('')
@@ -34,6 +35,12 @@ const outlinedValue12 = ref('')
3435
const outlinedValue13 = ref('')
3536
const outlinedValue14 = ref('')
3637
38+
const inputRef = ref()
39+
40+
const selectAll = () => {
41+
inputRef.value?.select()
42+
}
43+
3744
watchLang(use)
3845
onThemeChange()
3946
</script>
@@ -78,6 +85,10 @@ onThemeChange()
7885
<var-input v-model="standardValue10" :placeholder="t('textarea')" textarea />
7986
<var-input v-model="standardValue11" :placeholder="t('smallSize')" size="small" />
8087
<var-input v-model.trim="standardValue12" :placeholder="t('trim')" />
88+
<var-space>
89+
<var-input ref="inputRef" v-model="standardValue15" :placeholder="t('selectAll')" />
90+
<var-button type="primary" @click="selectAll">{{ t('selectAllButton') }}</var-button>
91+
</var-space>
8192
</var-space>
8293
8394
<app-type style="margin-top: 10vmin">{{ t('outlined') }}</app-type>

packages/varlet-ui/src/input/example/locale/en-US.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ export default {
99
trim: 'Removes whitespace from both ends of this string',
1010
readonly: 'Readonly',
1111
clearable: 'Clearable',
12-
clearIconSlot: 'Use the clear icon slot',
12+
clearIconSlot: 'Custom Clear Icon',
1313
displayIcon: 'Display Icon',
14-
customIconSize: 'Custom Icon Size',
14+
customIconSize: 'Use the clear icon slot',
1515
validate: 'Validate',
1616
validateWithZod: 'Validate With Zod',
1717
placeholder: 'Please enter text',
1818
numberPlaceholder: 'Please enter number',
1919
maxMessage: 'Text length must be greater than 6',
20-
clearableText: 'Clearable Text',
20+
clearableText: 'Clearable text',
21+
selectAll: 'Type text and click button to select all',
22+
selectAllButton: 'Select All',
2123
}

packages/varlet-ui/src/input/example/locale/zh-CN.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ export default {
1818
numberPlaceholder: '请输入数字',
1919
maxMessage: '文本长度必须大于6',
2020
clearableText: '可清除文本',
21+
selectAll: '输入文本后点击按钮 全选',
22+
selectAllButton: '全选',
2123
}

packages/varlet-ui/types/input.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ export class Input extends VarComponent {
6868

6969
blur(): void
7070

71+
select(): void
72+
7173
validate(): Promise<boolean>
7274

7375
resetValidation(): void

0 commit comments

Comments
 (0)