Skip to content

Commit d0842b5

Browse files
st-slothFeng
authored andcommitted
InputNumber: add select method (ElemeFE#13286)
* Input: add test for `select` method * InputNumber: add `select` method
1 parent 93ebe61 commit d0842b5

File tree

6 files changed

+65
-0
lines changed

6 files changed

+65
-0
lines changed

examples/docs/en-US/input-number.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,5 @@ Use attribute `size` to set additional sizes with `medium`, `small` or `mini`.
205205
| Method | Description | Parameters |
206206
|------|--------|-------|
207207
| focus | focus the Input component | - |
208+
| select | select the text in input element ||
209+

examples/docs/es/input-number.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,5 @@ Utilice el atributo `size` para establecer tamaños adicionales con `medium`, `s
206206
| Método | Descripción | Parámetro |
207207
| ------ | ------------------------------------ | --------- |
208208
| focus | coloca el foco en el elemento actual | - |
209+
| select | selecciona el texto del input | - |
210+

examples/docs/zh-CN/input-number.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,4 @@
202202
| 方法名 | 说明 | 参数 |
203203
| ---- | ---- | ---- |
204204
| focus | 使 input 获取焦点 | - |
205+
| select | 选中 input 中的文字 ||

packages/input-number/src/input-number.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@
233233
if (!isNaN(newVal) || value === '') {
234234
this.setCurrentValue(newVal);
235235
}
236+
},
237+
select() {
238+
this.$refs.input.select();
236239
}
237240
},
238241
mounted() {

test/unit/specs/input-number.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,4 +396,35 @@ describe('InputNumber', () => {
396396
done();
397397
});
398398
});
399+
400+
describe('InputNumber Methods', () => {
401+
it('method:select', done => {
402+
const testContent = '123';
403+
404+
vm = createVue({
405+
template: `
406+
<el-input-number
407+
ref="inputNumComp"
408+
:value="${testContent}"
409+
/>
410+
`
411+
}, true);
412+
413+
expect(vm.$refs.inputNumComp.$refs.input.$refs.input.selectionStart)
414+
.to.equal(testContent.length);
415+
expect(vm.$refs.inputNumComp.$refs.input.$refs.input.selectionEnd)
416+
.to.equal(testContent.length);
417+
418+
vm.$refs.inputNumComp.select();
419+
420+
vm.$nextTick(_ => {
421+
expect(vm.$refs.inputNumComp.$refs.input.$refs.input.selectionStart)
422+
.to.equal(0);
423+
expect(vm.$refs.inputNumComp.$refs.input.$refs.input.selectionEnd)
424+
.to.equal(testContent.length);
425+
426+
done();
427+
});
428+
});
429+
});
399430
});

test/unit/specs/input.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,30 @@ describe('Input', () => {
300300
});
301301
});
302302
});
303+
304+
describe('Input Methods', () => {
305+
it('method:select', done => {
306+
const testContent = 'test';
307+
308+
vm = createVue({
309+
template: `
310+
<el-input
311+
ref="inputComp"
312+
value="${testContent}"
313+
/>
314+
`
315+
}, true);
316+
317+
expect(vm.$refs.inputComp.$refs.input.selectionStart).to.equal(testContent.length);
318+
expect(vm.$refs.inputComp.$refs.input.selectionEnd).to.equal(testContent.length);
319+
320+
vm.$refs.inputComp.select();
321+
322+
vm.$nextTick(_ => {
323+
expect(vm.$refs.inputComp.$refs.input.selectionStart).to.equal(0);
324+
expect(vm.$refs.inputComp.$refs.input.selectionEnd).to.equal(testContent.length);
325+
done();
326+
});
327+
});
328+
});
303329
});

0 commit comments

Comments
 (0)