-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(trigger('focus')) added natural to jsdom behavior (#1777)
* Fix for trigger('focus') Added test case and the fix for wrapper trigger * Extended types notation and jsdoc * Added type check and fallback for focus processing
- Loading branch information
Showing
3 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
test/resources/components/component-with-multiple-inputs.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<template> | ||
<div> | ||
<input | ||
v-for="index of 5" | ||
@focus="onFocus(index)" | ||
:id="index" | ||
:data-test-position="index" | ||
:ref="refNameByIndex(index)" | ||
:key="index" | ||
type="text" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'component-with-multiple-inputs', | ||
data: () => ({ activeInputIndex: null }), | ||
computed: { | ||
inputRefAtIndex() { | ||
return index => this.$refs[this.refNameByIndex(index)] | ||
} | ||
}, | ||
methods: { | ||
refNameByIndex(index) { | ||
return `input${index}` | ||
}, | ||
returnToLastSelectedInput() { | ||
return this.focusInput(this.inputRefAtIndex(this.activeInputIndex)) | ||
}, | ||
onFocus(index) { | ||
const isOdd = Boolean(index % 2) | ||
if (isOdd) { | ||
return this.returnToLastSelectedInput() | ||
} | ||
this.activeInputIndex = index | ||
}, | ||
focusInput(inputRef) { | ||
if (!inputRef) { | ||
return | ||
} | ||
const [input] = inputRef | ||
input.focus() | ||
} | ||
}, | ||
mounted() { | ||
this.focusInput(this.focusInput(this.inputRefAtIndex(2))) | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters