fix(components): [input] the cursor error when click show-password (#19003)

closed #18387, #18831
This commit is contained in:
qiang 2024-11-24 20:02:02 +08:00 committed by GitHub
parent 349a2e9c16
commit 6c6e4c67e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 6 deletions

View File

@ -551,6 +551,30 @@ describe('Input.vue', () => {
expect(d !== d0).toBeTruthy()
})
test('show / hide password', async () => {
const password = ref('123456')
const wrapper = mount(() => (
<Input type="password" modelValue={password.value} show-password />
))
const icon = wrapper.find('.el-input__icon.el-input__password')
const input = wrapper.find('input')
expect(input.element.value).toBe('123456')
expect(input.element.selectionStart).toBe(6)
expect(input.element.selectionEnd).toBe(6)
await icon.trigger('click')
expect(input.element.value).toBe('123456')
expect(input.element.selectionStart).toBe(6)
expect(input.element.selectionEnd).toBe(6)
await input.element.setSelectionRange(1, 4)
await icon.trigger('click')
expect(input.element.selectionStart).toBe(1)
expect(input.element.selectionEnd).toBe(4)
})
describe('form item accessibility integration', () => {
test('automatic id attachment', async () => {
const wrapper = mount(() => (

View File

@ -428,15 +428,13 @@ const {
} = useComposition({ emit, afterComposition: handleInput })
const handlePasswordVisible = () => {
recordCursor()
passwordVisible.value = !passwordVisible.value
focus()
// The native input needs a little time to regain focus
setTimeout(setCursor)
}
const focus = async () => {
// see: https://github.com/ElemeFE/element/issues/18573
await nextTick()
_ref.value?.focus()
}
const focus = () => _ref.value?.focus()
const blur = () => _ref.value?.blur()