Skip to content

Commit

Permalink
Add paste event to AddressInput to intercept request links
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed May 29, 2020
1 parent 4ae0e0a commit 5cf3fcb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/components/AddressInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ export default class AddressInput extends Vue {
}
private _onPaste(e: ClipboardEvent) {
// Stop paste event from affecting other inputs that may get focussed as a result of the emitted 'paste' event
e.stopPropagation();
const clipboardData = e.clipboardData;
const pastedData = clipboardData ? clipboardData.getData('text/plain') : '';
this.$emit('paste', pastedData);
inputFormatOnPaste(e, this.$refs.textarea, AddressInput._parse, AddressInput._format, this._afterChange);
}
Expand Down
6 changes: 5 additions & 1 deletion src/stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,12 @@ storiesOf('Components', module)
lastValidAddress: null,
};
},
methods: {
input: action('input'),
paste: action('paste'),
},
template: `<div>
<AddressInput v-model="address" @address="lastValidAddress = $event" />
<AddressInput v-model="address" @input="input" @address="lastValidAddress = $event" @paste="paste" />
<div>Current address: {{ address }}</div>
<div>valid?: {{ address === lastValidAddress }}</div>
</div>`,
Expand Down

0 comments on commit 5cf3fcb

Please sign in to comment.