Skip to content

Commit

Permalink
Fix dead key
Browse files Browse the repository at this point in the history
  • Loading branch information
claudivanfilho committed Sep 24, 2020
1 parent 7946c02 commit 8cbfc54
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# v1.0.21
# v1.0.22

- Fix dead key

## v1.0.21

- Fix dead key

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "v-slim-mask",
"version": "1.0.21",
"version": "1.0.22",
"description": "A input mask directtive compatible with Vue 3",
"main": "dist/index.js",
"scripts": {
Expand Down
20 changes: 15 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const MASK_TOKEN_PATTERN: IMASK_TOKEN_PATTERN = {
S: /[a-z]|[A-Z]/,
A: /[0-9]|[a-z]|[A-Z]/,
C: /[^ ]/,
X: /.*/
X: /.*/,
}
export type MASK_TOKEN = keyof typeof MASK_TOKEN_PATTERN
interface InputEvent extends Event {
Expand Down Expand Up @@ -67,7 +67,7 @@ export function getCustomMaskDirective(
}
}
)
}
},
}
}

Expand All @@ -77,7 +77,7 @@ class InputMaskDOMManiputalion {
private maskService: MaskLogic
private lastValue = ''
constructor(
mapTokens = MASK_TOKEN_PATTERN,
private mapTokens = MASK_TOKEN_PATTERN,
private inputElement: HTMLInputElement,
private mask: string,
private shouldUnmask: boolean,
Expand Down Expand Up @@ -132,13 +132,23 @@ class InputMaskDOMManiputalion {
onInput = (event: any) => {
const target: HTMLInputElement | null = event.target as HTMLInputElement
const value = target.value
const start = target.selectionStart || 0
const isComposition = event.inputType === 'insertCompositionText'
let finalValue = this.remask(value, event.inputType === 'insertFromPaste')
if (event.inputType === 'deleteContentBackward') {
if (finalValue === this.lastValue) {
finalValue = this.popValue(finalValue)
}
}
if (!(event.inputType === 'insertCompositionText' && !this.isMobile())) {
const pattern = this.mapTokens[this.mask[start - 1]]
if (
finalValue !== value &&
isComposition &&
pattern &&
!value[start - 1].match(pattern)
) {
this.refreshInput(finalValue)
} else if (!(isComposition && !this.isMobile())) {
this.refreshInput(finalValue)
}
this.formatAndEmit(finalValue)
Expand All @@ -149,7 +159,7 @@ class InputMaskDOMManiputalion {
initListeners() {
this.inputElement.oninput = this.onInput
this.inputElement.onclick = this.onClick
this.inputElement.onkeyup = e => {
this.inputElement.onkeyup = (e) => {
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
this.onClick(e)
}
Expand Down

0 comments on commit 8cbfc54

Please sign in to comment.